]> BookStack Code Mirror - bookstack/commitdiff
#47 - Fixes a couple of issues found during testing - delete not updating the UI...
authorAbijeet <redacted>
Wed, 7 Jun 2017 18:15:29 +0000 (23:45 +0530)
committerAbijeet <redacted>
Wed, 7 Jun 2017 18:15:29 +0000 (23:45 +0530)
resources/assets/js/controllers.js
resources/lang/en/errors.php
resources/views/comments/list-item.blade.php

index 3ef02d41fff19f7fb7709480125907e65a065b86..a929f4aed2543dad113c157c6efa563f24b8070c 100644 (file)
@@ -747,7 +747,7 @@ module.exports = function (ngApp, events) {
             } else if (response.data) {
                 msg = response.data.message;
             } else {
-                msg = trans('errors.comment_add_error');
+                msg = trans('errors.comment_add');
             }
             if (msg) {
                 events.emit('success', msg);
@@ -761,15 +761,15 @@ module.exports = function (ngApp, events) {
 
         vm.delete = function(comment) {
             $http.delete(window.baseUrl(`/ajax/comment/${comment.id}`)).then(resp => {
-                if (isCommentOpSuccess(resp)) {
+                if (!isCommentOpSuccess(resp)) {
                     return;
                 }
                 updateComment(comment, resp.data, $timeout, true);
             }, function (resp) {
                 if (isCommentOpSuccess(resp)) {
-                    events.emit('success', trans('entities.comment_delete_success'));
+                    events.emit('success', trans('entities.comment_deleted'));
                 } else {
-                    events.emit('error', trans('entities.comment_delete_fail'));
+                    events.emit('error', trans('error.comment_delete'));
                 }
             });
         };
@@ -794,17 +794,21 @@ module.exports = function (ngApp, events) {
             event.preventDefault();
         });
 
-        vm.canEdit = function (comment) {
+        vm.canEditDelete = function (comment, prop) {
             if (!comment.active) {
                 return false;
             }
-            if (vm.permissions.comment_update_all) {
+            let propAll = prop + '_all';
+            let propOwn = prop + '_own';
+
+            if (vm.permissions[propAll]) {
                 return true;
             }
 
-            if (vm.permissions.comment_update_own && comment.created_by.id === vm.current_user_id) {
+            if (vm.permissions[propOwn] && comment.created_by.id === vm.current_user_id) {
                 return true;
             }
+            
             return false;
         };
 
@@ -815,6 +819,9 @@ module.exports = function (ngApp, events) {
         $timeout(function() {
             $http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
                 if (!isCommentOpSuccess(resp)) {
+                    // just show that no comments are available.
+                    vm.totalComments = 0;
+                    setTotalCommentMsg();
                     return;
                 }
                 vm.comments = resp.data.comments;
@@ -845,7 +852,7 @@ module.exports = function (ngApp, events) {
             } else if (response.data) {
                 msg = response.data.message;
             } else {
-                msg = trans('errors.comment_error');
+                msg = trans('errors.comment_list');
             }
             if (msg) {
                 events.emit('success', msg);
index fc2ac73b5ef28bdbb412764bd94650bc9196bcf7..71bcd1f9aafbeb4186795ed444fd15dc5d137cec 100644 (file)
@@ -61,9 +61,10 @@ return [
     'role_registration_default_cannot_delete' => 'This role cannot be deleted while set as the default registration role',
 
     // Comments
-    'comment_error' => 'An error occurred while fetching the comments.',
+    'comment_list' => 'An error occurred while fetching the comments.',
     'cannot_add_comment_to_draft' => 'You cannot add comments to a draft.',
-    'comment_add_error' => 'An error occurred while adding the comment.',
+    'comment_add' => 'An error occurred while adding the comment.',
+    'comment_delete' => 'An error occurred while deleting the comment.',
     'empty_comment' => 'Cannot add an empty comment.',
 
     // Error pages
index eb2bcf8ab038e105297f07dc68008e41a5c11424..6904a4abfa2d423da174965ac598678acff0cbec 100644 (file)
@@ -15,8 +15,8 @@
         <div class="comment-actions">
             <ul ng-if="!comment.is_hidden">
                 <li ng-if="::(level < 3 && vm.canComment())"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" is-reply="true">{{ trans('entities.comment_reply') }}</a></li>
-                <li ng-if="::vm.canEdit(comment)"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" >{{ trans('entities.comment_edit') }}</a></li>
-                <li ng-if="::vm.canEdit(comment, true)"><a href="#" comment-delete-link comment="comment" >{{ trans('entities.comment_delete') }}</a></li>
+                <li ng-if="::vm.canEditDelete(comment, 'comment_update')"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" >{{ trans('entities.comment_edit') }}</a></li>
+                <li ng-if="::vm.canEditDelete(comment, 'comment_delete')"><a href="#" comment-delete-link comment="comment" >{{ trans('entities.comment_delete') }}</a></li>
                 <li>Created <a title="@{{::comment.created.day_time_str}}" href="#comment-@{{::comment.id}}-@{{::pageId}}">@{{::comment.created.diff}}</a></li>
                 <li ng-if="::comment.updated"><span title="@{{::comment.updated.day_time_str}}">@{{ ::vm.trans('entities.comment_updated_text', { updateDiff: comment.updated.diff }) }}
                         <a href="@{{::comment.updated_by.profile_url}}">@{{::comment.updated_by.name}}</a></span></li>