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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 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 class="content card om-card">
  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. selected: [],
  72. taglist: data,
  73. };
  74. },
  75. methods: {
  76. saveTagsToArray: function() {
  77. tagArray = this.selected;
  78. console.info(tagArray);
  79. },
  80. createMsg: function () {
  81. var _subject = $("#subject").val();
  82. var _message = $("#message").val();
  83. var _tag = tagArray;
  84. var _user = $("#user").val();
  85. //console.log("Message Created: " + _tag + " " + _message + " " + _user);
  86. $.ajax({
  87. url: "api/msg",
  88. data: {
  89. subject: _subject,
  90. message: _message,
  91. user: _user,
  92. tag: _tag
  93. },
  94. method: "POST"
  95. }).done(have_result).fail(have_error);
  96. function have_result(res) {
  97. //console.log(res);
  98. router.push('/home')
  99. }
  100. function have_error(err) {
  101. console.log("error: " + err.responseText);
  102. console.log(err);
  103. }
  104. },
  105. getFilteredTags(text) {
  106. this.taglist = data.filter((option) => {
  107. return option
  108. .toString()
  109. .toLowerCase()
  110. .indexOf(text.toLowerCase()) >= 0
  111. })
  112. },
  113. list_tags: function () {
  114. $.ajax({url: "api/tag/ids",method: "GET"})
  115. .done(jd => {
  116. // NICHT SO wg. Vue: _messagelist = jd;
  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. }).fail(function (e, f, g) {
  126. console.log("err: " + e + f + g);
  127. });
  128. }
  129. },
  130. mounted: function () {
  131. this.list_tags();
  132. if ($(this).bootstrapMaterialDesign)
  133. $(this).bootstrapMaterialDesign();
  134. },
  135. };
  136. function get_insert_tag(id){
  137. $.ajax({ url: "api/tag/"+id, method: "GET" }).done(function (tag) {
  138. data.push("#" + tag.name);
  139. console.log("Array:"+this.data);
  140. }).fail(function (e, f, g) {
  141. console.log("cannot load " + id + ".json: " + e + f + g);
  142. })
  143. }