1 const MarkdownIt = require("markdown-it");
2 const md = new MarkdownIt({html: true});
5 <div class="comment-editor" v-cloak>
7 <textarea name="markdown" rows="3" v-model="comment.text" :placeholder="trans('entities.comment_placeholder')"></textarea>
8 <input type="hidden" v-model="comment.pageId" name="comment.pageId" :value="pageId">
9 <button type="button" v-if="isReply || isEdit" class="button muted" v-on:click="closeBox">{{ trans('entities.comment_cancel') }}</button>
10 <button type="submit" class="button pos" v-on:click.prevent="saveComment">{{ trans('entities.comment_save') }}</button>
28 // initialize comment if not passed.
29 if (!this.commentObj || this.isReply) {
35 comment.page_id = this.commentObj.page_id;
36 comment.id = this.commentObj.id;
39 comment = this.commentObj;
50 saveComment: function (event) {
51 let pageId = this.comment.page_id || this.pageId;
52 let commentText = this.comment.text;
54 return this.$emit('evt.empty-comment');
56 let commentHTML = md.render(commentText);
57 let serviceUrl = `/ajax/page/${pageId}/comment/`;
58 let httpMethod = 'post';
64 if (this.isEdit === true) {
65 // this will be set when editing the comment.
66 serviceUrl = `/ajax/page/${pageId}/comment/${this.comment.id}`;
68 } else if (this.isReply === true) {
69 // if its reply, get the parent comment id
70 reqObj.parent_id = this.comment.id;
73 $http[httpMethod](window.baseUrl(serviceUrl), reqObj).then(resp => {
74 if (!isCommentOpSuccess(resp)) {
77 // hide the comments first, and then retrigger the refresh
79 this.$emit('comment-edited', event, resp.data.comment);
81 this.comment.text = '';
82 this.$emit('comment-added', event);
83 if (this.isReply === true) {
84 this.$emit('comment-replied', event, resp.data.comment);
86 this.$parent.$emit('new-comment', event, resp.data.comment);
88 this.$emit('evt.comment-success', null, true);
93 closeBox: function (event) {
94 this.$emit('editor-removed', event);
100 function isCommentOpSuccess(resp) {
101 if (resp && resp.data && resp.data.status === 'success') {
107 function checkError(msgKey) {
108 return function(response) {
110 if (isCommentOpSuccess(response)) {
113 } else if (response.data) {
114 msg = response.data.message;
119 events.emit('success', msg);
124 module.exports = {name: 'comment-reply', template, data, props, methods, computed};