1 const comment = require('./components/comments/comment');
2 const commentReply = require('./components/comments/comment-reply');
5 totalCommentsStr: trans('entities.comments_loading'),
14 commentAdded: function () {
22 return this.commentCount;
24 set: function (value) {
25 this.commentCount = value;
27 this.totalCommentsStr = trans('entities.no_comments');
28 } else if (value === 1) {
29 this.totalCommentsStr = trans('entities.one_comment');
31 this.totalCommentsStr = trans('entities.x_comments', {
37 canComment: function () {
38 if (!this.permissions) {
41 return this.permissions.comment_create === true;
46 this.pageId = Number(this.$el.getAttribute('page-id'));
47 // let linkedCommentId = this.$route.query.cm;
48 let linkedCommentId = null;
49 this.$http.get(window.baseUrl(`/ajax/page/${this.pageId}/comments/`)).then(resp => {
50 if (!isCommentOpSuccess(resp)) {
51 // just show that no comments are available.
55 this.comments = resp.data.comments;
56 this.totalComments = +resp.data.total;
57 this.permissions = resp.data.permissions;
58 this.currentUserId = resp.data.user_id;
59 if (!linkedCommentId) {
63 // wait for the UI to render.
64 focusLinkedComment(linkedCommentId);
66 }, checkError('errors.comment_list'));
69 function isCommentOpSuccess(resp) {
70 if (resp && resp.data && resp.data.status === 'success') {
76 function checkError(msgKey) {
77 return function(response) {
79 if (isCommentOpSuccess(response)) {
82 } else if (response.data) {
83 msg = response.data.message;
88 events.emit('success', msg);
94 this.$on('new-comment', function (event, comment) {
95 this.comments.push(comment);
99 function beforeDestroy() {
100 this.$off('new-comment');
104 data, methods, mounted, computed, components : {
105 comment, commentReply
107 created, beforeDestroy