view-message.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var app = new Vue({
  2. el: "#ViewMessage",
  3. data: {
  4. message: [],
  5. replies: []
  6. },
  7. mounted: function() {
  8. this.fetchMessage();
  9. },
  10. methods: {
  11. fetchMessage: function() {
  12. let messageId = window.location.href.substr(window.location.href.lastIndexOf("/") + 1);
  13. // console.log("messageId: " + messageId);
  14. // get the primary message
  15. $.ajax({
  16. url: "/api/messages/" + messageId,
  17. method: "GET",
  18. // if successful, get the replies.
  19. success: message => {
  20. this.message = message;
  21. $.ajax({
  22. url: "/api/messages/replies/" + messageId,
  23. method: "GET",
  24. success: replies => {
  25. this.replies = replies;
  26. $(".ui.active.dimmer").removeClass("active");
  27. }
  28. });
  29. }
  30. });
  31. }
  32. }
  33. });
  34. /* START reply to message */
  35. $("#ReplyButton").click(function() {
  36. $("#NewReplyModal").modal("show");
  37. });
  38. $("#PostReplyButton").click(function() {
  39. let replyData = {
  40. messageId: $("#messageId").val(),
  41. content: $("#replyContent").val()
  42. };
  43. replyData.content = replyData.content.trim();
  44. let animationName = "shake";
  45. let badData = false;
  46. if (replyData.content.length == 0) {
  47. $("#replyContent").transition(animationName);
  48. badData = true;
  49. }
  50. if (badData) {
  51. return false;
  52. }
  53. //replyData = JSON.stringify(replyData);
  54. //console.log("Reply Data: " + replyData);
  55. $.ajax({
  56. url: "/api/messages/reply/",
  57. method: "POST",
  58. data: replyData,
  59. //contentType: "application/json; charset=utf-8",
  60. //dataType: "json",
  61. success: function(newReply) {
  62. app._data.replies.push(newReply);
  63. $("#NewReplyModal").modal("hide");
  64. }
  65. });
  66. });
  67. /* END reply to message */