X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/5bd9da60544dbfde9a121589b33bf92b372f9490..refs/pull/261/head:/resources/assets/js/controllers.js diff --git a/resources/assets/js/controllers.js b/resources/assets/js/controllers.js index 3ef02d41f..aebde8da4 100644 --- a/resources/assets/js/controllers.js +++ b/resources/assets/js/controllers.js @@ -272,7 +272,6 @@ module.exports = function (ngApp, events) { $scope.draftsEnabled = $attrs.draftsEnabled === 'true'; $scope.isUpdateDraft = Number($attrs.pageUpdateDraft) === 1; $scope.isNewPageDraft = Number($attrs.pageNewDraft) === 1; - $scope.commentsLoaded = false; // Set initial header draft text if ($scope.isUpdateDraft || $scope.isNewPageDraft) { @@ -687,7 +686,6 @@ module.exports = function (ngApp, events) { const MarkdownIt = require("markdown-it"); const md = new MarkdownIt({html: true}); let vm = this; - $scope.errors = {}; vm.saveComment = function () { let pageId = $scope.comment.pageId || $scope.pageId; @@ -747,7 +745,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,22 +759,22 @@ 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')); } }); }; }]); // Controller used to fetch all comments for a page - ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { + ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', '$location', function ($scope, $http, $timeout, $location) { let vm = this; $scope.errors = {}; // keep track of comment levels @@ -794,17 +792,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; }; @@ -812,9 +814,15 @@ module.exports = function (ngApp, events) { return vm.permissions.comment_create; }; + // check if there are is any direct linking + let linkedCommentId = $location.search().cm; + $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; @@ -822,6 +830,13 @@ module.exports = function (ngApp, events) { vm.permissions = resp.data.permissions; vm.current_user_id = resp.data.user_id; setTotalCommentMsg(); + if (!linkedCommentId) { + return; + } + $timeout(function() { + // wait for the UI to render. + focusLinkedComment(linkedCommentId); + }); }, checkError); }); @@ -837,6 +852,15 @@ module.exports = function (ngApp, events) { } } + function focusLinkedComment(linkedCommentId) { + let comment = angular.element('#' + linkedCommentId); + if (comment.length === 0) { + return; + } + + window.setupPageShow.goToText(linkedCommentId); + } + function checkError(response) { let msg = null; if (isCommentOpSuccess(response)) { @@ -845,7 +869,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);