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

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