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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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="column pull-right-sm is-four-fifths-desktop">
  11. <div id="mobile" class="om-card 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>`,
  40. data: function () {
  41. return {
  42. auth: auth,
  43. isDisabled: false,
  44. selected: [],
  45. taglist: data,
  46. };
  47. },
  48. methods: {
  49. saveTagsToArray: function() {
  50. tagArray = this.selected;
  51. console.info(tagArray);
  52. },
  53. createMsg: function () {
  54. var _subject = $("#subject").val();
  55. var _message = $("#message").val();
  56. var _tag = tagArray;
  57. var _user = auth.name ? auth.name : $("#user").val();
  58. //console.log("Message Created: " + _tag + " " + _message + " " + _user);
  59. $.ajax({
  60. url: "api/msg",
  61. data: {
  62. subject: _subject,
  63. message: _message,
  64. user: _user,
  65. tag: _tag
  66. },
  67. method: "POST"
  68. }).done(have_result).fail(have_error);
  69. function have_result(res) {
  70. //console.log(res);
  71. router.push('/home')
  72. }
  73. function have_error(err) {
  74. console.log("error: " + err.responseText);
  75. console.log(err);
  76. }
  77. },
  78. getFilteredTags(text) {
  79. this.taglist = data.filter((option) => {
  80. return option
  81. .toString()
  82. .toLowerCase()
  83. .indexOf(text.toLowerCase()) >= 0
  84. })
  85. },
  86. list_tags: function () {
  87. $.ajax({url: "api/tag/ids",method: "GET"})
  88. .done(jd => {
  89. // NICHT SO wg. Vue: _messagelist = jd;
  90. _taglist.splice(0, _taglist.length);
  91. _taglist.push.apply(_taglist, jd);
  92. console.log("tag: jd: " + jd);
  93. for (var e in jd) {
  94. if (!_tags[jd[e]]) {
  95. get_insert_tag(jd[e]);
  96. }
  97. }
  98. }).fail(function (e, f, g) {
  99. console.log("err: " + e + f + g);
  100. });
  101. }
  102. },
  103. mounted: function () {
  104. var userField = $('#user');
  105. if (auth != null && auth.mail != '') {
  106. // userField.prop('placeholder',auth.name);
  107. var authorName = auth.name.split(' ');
  108. authorName = authorName[1] + ', ' + authorName[0];
  109. userField.val(authorName);
  110. userField.prop('disabled',true);
  111. } else {
  112. userField.prop('placeholder','User');
  113. userField.prop('disabled',false);
  114. }
  115. this.list_tags();
  116. if ($(this).bootstrapMaterialDesign)
  117. $(this).bootstrapMaterialDesign();
  118. },
  119. };
  120. function get_insert_tag(id){
  121. $.ajax({ url: "api/tag/id/"+id, method: "GET" }).done(function (tag) {
  122. data.push("#" + tag.name);
  123. console.log("Array:"+this.data);
  124. }).fail(function (e, f, g) {
  125. console.log("cannot load " + id + ".json: " + e + f + g);
  126. })
  127. }