#47 - Fixes a couple of issues found during testing - delete not updating the UI, delete none not working properly.

This commit is contained in:
Abijeet 2017-06-07 23:45:29 +05:30
parent 652a67ad65
commit 38fe756725
3 changed files with 20 additions and 12 deletions

View 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);

View 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

View 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>