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

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