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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. var tagArray = [];
  2. const data=[
  3. '#th',
  4. '#efi',
  5. '#wichtig',
  6. ];
  7. const CreateMsgRouter = {
  8. template: `
  9. <div class="content card om-card">
  10. <h4>Neue Nachricht erstellen</h4>
  11. <b-field>
  12. <b-input placeholder="User" id="user"></b-input>
  13. </b-field>
  14. <b-field>
  15. <b-input placeholder="Betreff" id="subject"></b-input>
  16. </b-field>
  17. <b-field label="Tags">
  18. <b-taginput
  19. id="tag"
  20. v-model="selected"
  21. :data=taglist
  22. autocomplete
  23. allow-new:false
  24. icon="label"
  25. placeholder="#"
  26. @typing="getFilteredTags"
  27. @input="saveTagsToArray">
  28. </b-taginput>
  29. </b-field>
  30. <b-field>
  31. <b-input placeholder="Nachricht" id="message" type="textarea"></b-input>
  32. </b-field>
  33. <b-button @click="$router.go(-1)">ABBRECHEN</b-button>
  34. <b-button type="is-primary" @click="createMsg">SENDEN</b-button>
  35. </div>
  36. `,
  37. data: function () {
  38. return {
  39. selected: [],
  40. taglist: data,
  41. };
  42. },
  43. methods: {
  44. saveTagsToArray: function() {
  45. tagArray = this.selected;
  46. console.info(tagArray);
  47. },
  48. createMsg: function () {
  49. var _subject = $("#subject").val();
  50. var _message = $("#message").val();
  51. var _tag = tagArray;
  52. var _user = $("#user").val();
  53. //console.log("Message Created: " + _tag + " " + _message + " " + _user);
  54. $.ajax({
  55. url: "api/msg",
  56. data: {
  57. subject: _subject,
  58. message: _message,
  59. user: _user,
  60. tag: _tag
  61. },
  62. method: "POST"
  63. }).done(have_result).fail(have_error);
  64. function have_result(res) {
  65. //console.log(res);
  66. router.push('/home')
  67. }
  68. function have_error(err) {
  69. console.log("error: " + err.responseText);
  70. console.log(err);
  71. }
  72. },
  73. getFilteredTags(text) {
  74. this.taglist = data.filter((option) => {
  75. return option
  76. .toString()
  77. .toLowerCase()
  78. .indexOf(text.toLowerCase()) >= 0
  79. })
  80. },
  81. list_tags: function () {
  82. $.ajax({url: "api/tag/ids",method: "GET"})
  83. .done(jd => {
  84. // NICHT SO wg. Vue: _messagelist = jd;
  85. _taglist.splice(0, _taglist.length);
  86. _taglist.push.apply(_taglist, jd);
  87. console.log("tag: jd: " + jd);
  88. for (var e in jd) {
  89. if (!_tags[jd[e]]) {
  90. get_insert_tag(jd[e]);
  91. }
  92. }
  93. }).fail(function (e, f, g) {
  94. console.log("err: " + e + f + g);
  95. });
  96. }
  97. },
  98. mounted: function () {
  99. this.list_tags();
  100. if ($(this).bootstrapMaterialDesign)
  101. $(this).bootstrapMaterialDesign();
  102. },
  103. };
  104. function get_insert_tag(id){
  105. $.ajax({ url: "api/tag/"+id, method: "GET" }).done(function (tag) {
  106. data.push(tag.name);
  107. console.log("it worked!");
  108. }).fail(function (e, f, g) {
  109. console.log("cannot load " + id + ".json: " + e + f + g);
  110. })
  111. }