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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. var tagArray = [];
  2. const CreateMsgRouter = {
  3. template: `
  4. <div class="content">
  5. <div class="is-hidden-desktop">
  6. <div id="mobile" class="content card om-card">
  7. <h4>Neue Nachricht erstellen</h4>
  8. <b-field>
  9. <b-input placeholder="User" id="user"></b-input>
  10. </b-field>
  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 class="column is-three-quarters is-pulled-right is-hidden-touch content-desktop">
  34. <div id="desktop" class="content card om-card">
  35. <h4>Neue Nachricht erstellen</h4>
  36. <b-field>
  37. <b-input placeholder="User" id="user"></b-input>
  38. </b-field>
  39. <b-field>
  40. <b-input placeholder="Betreff" id="subject"></b-input>
  41. </b-field>
  42. <b-field label="Tags">
  43. <b-taginput
  44. id="tag"
  45. v-model="selected"
  46. :data="filteredDataArray"
  47. autocomplete
  48. allow-new:false
  49. icon="label"
  50. placeholder="#"
  51. @input="saveTagsToArray">
  52. </b-taginput>
  53. </b-field>
  54. <b-field>
  55. <b-input placeholder="Nachricht" id="message" type="textarea"></b-input>
  56. </b-field>
  57. <b-button @click="$router.go(-1)">ABBRECHEN</b-button>
  58. <b-button type="is-primary" @click="createMsg">SENDEN</b-button>
  59. </div>
  60. </div>
  61. </div>`,
  62. data: function () {
  63. return {
  64. auth: auth,
  65. isDisabled: false,
  66. selected: [],
  67. searchtext : "",
  68. taglist: data,
  69. };
  70. },
  71. computed:{
  72. filteredDataArray() {
  73. return this.taglist.filter((option) => {
  74. return option
  75. .toString()
  76. .toLowerCase()
  77. .indexOf(this.searchtext.toLowerCase()) >= 0
  78. })
  79. }
  80. },
  81. methods: {
  82. saveTagsToArray: function() {
  83. tagArray = this.selected;
  84. console.info(tagArray);
  85. },
  86. createMsg: function () {
  87. var _subject = $("#subject").val();
  88. var _message = $("#message").val();
  89. var _tag = tagArray;
  90. var _user = auth.name ? auth.name : $("#user").val();
  91. //console.log("Message Created: " + _tag + " " + _message + " " + _user);
  92. $.ajax({
  93. url: "api/msg",
  94. data: {
  95. subject: _subject,
  96. message: _message,
  97. user: _user,
  98. tag: _tag
  99. },
  100. method: "POST"
  101. }).done(have_result).fail(have_error);
  102. function have_result(res) {
  103. //console.log(res);
  104. router.push('/home')
  105. }
  106. function have_error(err) {
  107. console.log("error: " + err.responseText);
  108. console.log(err);
  109. }
  110. },
  111. getFilteredTags(text) {
  112. this.taglist = data.filter((option) => {
  113. return option
  114. .toString()
  115. .toLowerCase()
  116. .indexOf(text.toLowerCase()) >= 0
  117. })
  118. },
  119. list_tags: function () {
  120. $.ajax({url: "api/tag/ids",method: "GET"})
  121. .done(jd => {
  122. // NICHT SO wg. Vue: _messagelist = jd;
  123. console.log("DATA: "+data);
  124. if(data == ""){
  125. _taglist.splice(0, _taglist.length);
  126. _taglist.push.apply(_taglist, jd);
  127. console.log("tag: jd: " + jd);
  128. for (var e in jd) {
  129. if (!_tags[jd[e]]) {
  130. get_insert_tag(jd[e]);
  131. }
  132. }
  133. }
  134. }).fail(function (e, f, g) {
  135. console.log("err: " + e + f + g);
  136. });
  137. }
  138. },
  139. mounted: function () {
  140. var userField = $('#user');
  141. if (auth != null && auth.mail != '') {
  142. // userField.prop('placeholder',auth.name);
  143. var authorName = auth.name.split(' ');
  144. authorName = authorName[1] + ', ' + authorName[0];
  145. userField.val(authorName);
  146. userField.prop('disabled',true);
  147. } else {
  148. userField.prop('placeholder','User');
  149. userField.prop('disabled',false);
  150. }
  151. //this.list_tags();
  152. if ($(this).bootstrapMaterialDesign)
  153. $(this).bootstrapMaterialDesign();
  154. },
  155. };