1 const commentReply = require('./comment-reply');
4 <div class="comment-box">
5 <div class='page-comment' :id="commentId">
6 <div class="user-image">
7 <img :src="comment.created_by.avatar_url" alt="user avatar">
9 <div class="comment-container">
10 <div class="comment-header">
11 <a :href="comment.created_by.profile_url">{{comment.created_by.name}}</a>
13 <div v-html="comment.html" v-if="comment.active" class="comment-body" v-bind:class="{ 'comment-inactive' : !comment.active }">
16 <div v-if="!comment.active" class="comment-body comment-inactive">
17 {{ trans('entities.comment_deleted') }}
19 <div class="comment-actions">
21 <li v-if="(level < 4 && canComment)">
22 <a href="#" comment="comment" v-on:click.prevent="replyComment">{{ trans('entities.comment_reply') }}</a>
24 <li v-if="canEditOrDelete('update')">
25 <a href="#" comment="comment" v-on:click.prevent="editComment">{{ trans('entities.comment_edit') }}</a>
27 <li v-if="canEditOrDelete('delete')">
28 <a href="#" comment="comment" v-on:click.prevent="deleteComment">{{ trans('entities.comment_delete') }}</a>
30 <li>{{ trans('entities.comment_create') }}
31 <a :title="comment.created.day_time_str" :href="commentHref">{{comment.created.diff}}</a>
33 <li v-if="comment.updated">
34 <span :title="comment.updated.day_time_str">{{trans('entities.comment_updated_text', { updateDiff: comment.updated.diff }) }}
35 <a :href="comment.updated_by.profile_url">{{comment.updated_by.name}}</a>
40 <div v-if="showEditor">
41 <comment-reply :page-id="comment.page_id" :comment-obj="comment"
42 v-on:editor-removed.stop.prevent="hideComment"
43 v-on:comment-replied.stop="commentReplied(...arguments)"
44 v-on:comment-edited.stop="commentEdited(...arguments)"
45 v-on:comment-added.stop="commentAdded"
46 :is-reply="isReply" :is-edit="isEdit">
49 <comment v-for="(comment, index) in comments" :initial-comment="comment" :index="index"
50 :level="nextLevel" :key="comment.id" :permissions="permissions" :current-user-id="currentUserId"
51 v-on:comment-added.stop="commentAdded"></comment>
58 const props = ['initialComment', 'index', 'level', 'permissions', 'currentUserId'];
66 comment: this.initialComment,
67 nextLevel: this.level + 1
72 deleteComment: function () {
73 var resp = window.confirm(trans('entities.comment_delete_confirm'));
77 this.$http.delete(window.baseUrl(`/ajax/comment/${this.comment.id}`)).then(resp => {
78 if (!isCommentOpSuccess(resp)) {
79 this.$events.emit('error', trans('error.comment_delete'));
82 this.$events.emit('success', trans('entities.comment_deleted'));
83 this.comment = resp.data.comment;
85 this.$events.emit('error', trans('error.comment_delete'));
88 replyComment: function () {
89 this.toggleEditor(false);
91 editComment: function () {
92 this.toggleEditor(true);
94 hideComment: function () {
95 this.showEditor = false;
97 toggleEditor: function (isEdit) {
98 this.showEditor = false;
100 this.isReply = !isEdit;
101 this.showEditor = true;
103 commentReplied: function (event, comment) {
104 this.comments.push(comment);
105 this.showEditor = false;
107 commentEdited: function (event, comment) {
108 this.comment = comment;
109 this.showEditor = false;
111 commentAdded: function (event, comment) {
112 // this is to handle non-parent child relationship
113 // we want to make it go up.
114 this.$emit('comment-added', event);
116 canEditOrDelete: function (prop) {
117 if (!this.comment.active) {
121 if (!this.permissions) {
125 let propAll = 'comment_' + prop + '_all';
126 let propOwn = 'comment_' + prop + '_own';
128 if (this.permissions[propAll]) {
132 if (this.permissions[propOwn] && this.comment.created_by.id === this.currentUserId) {
138 canComment: function () {
139 if (!this.permissions) {
142 return this.permissions.comment_create === true;
149 return `comment-${this.comment.page_id}-${this.comment.id}`;
152 this.commentHref = `#?cm=${this.commentId}`
158 if (this.comment.sub_comments && this.comment.sub_comments.length) {
159 // set this so that we can render the next set of sub comments.
160 this.comments = this.comment.sub_comments;
164 function isCommentOpSuccess(resp) {
165 if (resp && resp.data && resp.data.status === 'success') {
173 template, data, props, methods, computed, mounted, components: {