Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

createMessage.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const CreateMsgRouter = {
  2. template: `
  3. <div class="content">
  4. <div class="column pull-right-sm is-four-fifths-desktop">
  5. <div id="mobile" class="om-card card">
  6. <h4>Neue Nachricht erstellen</h4>
  7. <!--<b-field>
  8. <b-input placeholder="User" id="user"></b-input>
  9. </b-field>-->
  10. <label class="label">{{ userName }}</label>
  11. <b-field>
  12. <b-input placeholder="Betreff" id="subject"></b-input>
  13. </b-field>
  14. <b-field label="Tags">
  15. <b-taginput
  16. id="tag"
  17. v-model="selected"
  18. :data="filteredDataArray"
  19. autocomplete
  20. allow-new:false
  21. icon="label"
  22. placeholder="#"
  23. @input="saveTagsToArray">
  24. </b-taginput>
  25. </b-field>
  26. <b-field>
  27. <b-input placeholder="Nachricht" id="message" type="textarea"></b-input>
  28. </b-field>
  29. <b-button @click="$router.go(-1)">ABBRECHEN</b-button>
  30. <b-button type="is-primary" @click="createMsg">SENDEN</b-button>
  31. </div>
  32. </div>
  33. </div>`,
  34. data: function () {
  35. return {
  36. auth: auth,
  37. isDisabled: false,
  38. selected: [],
  39. searchtext : "",
  40. taglist: data,
  41. };
  42. },
  43. computed:{
  44. filteredDataArray: function() {
  45. return this.taglist.filter((option) => {
  46. return option
  47. .toString()
  48. .toLowerCase()
  49. .indexOf(this.searchtext.toLowerCase()) >= 0
  50. })
  51. },
  52. userName: function() {
  53. return 'User: '+auth.name;
  54. }
  55. },
  56. methods: {
  57. saveTagsToArray: function() {
  58. tagArray = this.selected;
  59. console.info(tagArray);
  60. },
  61. createMsg: function () {
  62. var _subject = $("#subject").val();
  63. var _message = $("#message").val();
  64. var tmpArr = [];
  65. tagArray.forEach(function(tag) {
  66. console.info(tag);
  67. tmpArr.push(tag.replace(/#/g, ''));
  68. });
  69. tagArray = tmpArr;
  70. var _tag = tagArray;
  71. var _user = auth.name.split(' ');
  72. if (_user.length < 2) {
  73. _user = _user[0];
  74. } else {
  75. _user = _user[1] + ', ' + _user[0];
  76. }
  77. //console.log("Message Created: " + _tag + " " + _message + " " + _user);
  78. $.ajax({
  79. url: "api/msg",
  80. data: {
  81. subject: _subject,
  82. message: _message,
  83. user: _user,
  84. tag: _tag
  85. },
  86. method: "POST"
  87. }).done(have_result).fail(have_error);
  88. function have_result(res) {
  89. //console.log(res);
  90. router.push('/home')
  91. }
  92. function have_error(err) {
  93. console.log("error: " + err.responseText);
  94. console.log(err);
  95. }
  96. },
  97. getFilteredTags(text) {
  98. this.taglist = data.filter((option) => {
  99. return option
  100. .toString()
  101. .toLowerCase()
  102. .indexOf(text.toLowerCase()) >= 0
  103. })
  104. },
  105. list_tags: function () {
  106. $.ajax({url: "api/tag/ids",method: "GET"})
  107. .done(jd => {
  108. // NICHT SO wg. Vue: _messagelist = jd;
  109. console.log("DATA: "+data);
  110. if(data == ""){
  111. _taglist.splice(0, _taglist.length);
  112. _taglist.push.apply(_taglist, jd);
  113. console.log("tag: jd: " + jd);
  114. for (var e in jd) {
  115. if (!_tags[jd[e]]) {
  116. get_insert_tag(jd[e]);
  117. }
  118. }
  119. }
  120. }).fail(function (e, f, g) {
  121. console.log("err: " + e + f + g);
  122. });
  123. },
  124. },
  125. mounted: function () {
  126. //this.list_tags();
  127. if ($(this).bootstrapMaterialDesign)
  128. $(this).bootstrapMaterialDesign();
  129. },
  130. };