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>
33 comment.page_id = this.commentObj.page_id;
34 comment.id = this.commentObj.id;
35 } else if (this.isEdit) {
36 comment = this.commentObj;
46 saveComment: function (event) {
47 let pageId = this.comment.page_id || this.pageId;
48 let commentText = this.comment.text;
50 return this.$events.emit('error', trans('errors.empty_comment'))
52 let commentHTML = md.render(commentText);
53 let serviceUrl = `/ajax/page/${pageId}/comment/`;
54 let httpMethod = 'post';
60 if (this.isEdit === true) {
61 // this will be set when editing the comment.
62 serviceUrl = `/ajax/page/${pageId}/comment/${this.comment.id}`;
64 } else if (this.isReply === true) {
65 // if its reply, get the parent comment id
66 reqObj.parent_id = this.comment.id;
68 $http[httpMethod](window.baseUrl(serviceUrl), reqObj).then(resp => {
69 if (!isCommentOpSuccess(resp)) {
70 this.$events.emit('error', getErrorMsg(resp));
73 // hide the comments first, and then retrigger the refresh
75 this.$emit('comment-edited', event, resp.data.comment);
77 this.comment.text = '';
78 this.$emit('comment-added', event);
79 if (this.isReply === true) {
80 this.$emit('comment-replied', event, resp.data.comment);
82 this.$parent.$emit('new-comment', event, resp.data.comment);
85 this.$events.emit('success', resp.data.message);
87 this.$events.emit('error', trans('errors.comment_add'))
90 closeBox: function (event) {
91 this.$emit('editor-removed', event);
97 function isCommentOpSuccess(resp) {
98 if (resp && resp.data && resp.data.status === 'success') {
104 function getErrorMsg(response) {
106 return response.data.message;
108 return trans('errors.comment_add');
112 module.exports = { name: 'comment-reply', template, data, props, methods, computed };