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

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