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.0KB

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