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

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