From 4bea3f8d80621fc8b5d76f7efaec407e5bddaaee Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 25 Apr 2019 11:35:38 +0200 Subject: [PATCH] buttons are disabled globaly (not lnoy on the first page) --- CHANGELOG | 2 ++ .../main/js/gui/admin/CommentsAdminPanel.js | 31 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 52de3e16e3..df5c2274e4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,8 @@ minerva (12.2.3) stable; urgency=medium * Bug fix: updating terms of use could crash when list of users was removed in separate tab or by another user (#797) * Bug fix: name of the checkbox in ADD PROJECT window adjusted (#799) + * Bug fix: when user didn't have privileges to remove comments the button was + active on pages other than page 1 (#792) * Bug fix: export of reaction to SBML didn't work when lines on the map were too short (#805) diff --git a/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js b/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js index a140ba3530..2347aba39d 100644 --- a/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js +++ b/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js @@ -104,31 +104,36 @@ CommentsAdminPanel.prototype.init = function () { */ CommentsAdminPanel.prototype.refreshComments = function () { var self = this; + var comments; - return ServerConnector.getComments({ + return self.getServerConnector().getComments({ projectId: self.getProject().getProjectId() - }).then(function (comments) { - var dataTable = $($("[name='commentsTable']", self.getElement())[0]).DataTable(); - var data = []; - for (var i = 0; i < comments.length; i++) { - data.push(self.commentToTableRow(comments[i])); - } - dataTable.clear().rows.add(data).draw(); + }).then(function (result) { + comments = result; return self.getServerConnector().getLoggedUser(); }).then(function (user) { var type = self.getConfiguration().getPrivilegeType(PrivilegeType.EDIT_COMMENTS_PROJECT); + var disable = false; if (!user.hasPrivilege(type, self.getProject().getId())) { - $("[name='removeComment']", self.getElement()).attr("disabled", true); + disable = true; + } + + var dataTable = $($("[name='commentsTable']", self.getElement())[0]).DataTable(); + var data = []; + for (var i = 0; i < comments.length; i++) { + data.push(self.commentToTableRow(comments[i], disable)); } + dataTable.clear().rows.add(data).draw(); }); }; /** * + * @param {boolean} disable * @param {Comment} comment * @returns {string[]} */ -CommentsAdminPanel.prototype.commentToTableRow = function (comment) { +CommentsAdminPanel.prototype.commentToTableRow = function (comment, disable) { var self = this; var projectId = self.getProject().getProjectId(); var toYesNo = function (val) { @@ -150,11 +155,15 @@ CommentsAdminPanel.prototype.commentToTableRow = function (comment) { title = comment.getTitle(); } + var disabled = ""; + if (disable) { + disabled = " disabled "; + } var remove = null; if (comment.isRemoved()) { remove = "YES (" + comment.getRemoveReason() + ")"; } else { - remove = "<button name='removeComment' data='" + comment.getId() + "'><i class='fa fa-trash-o' style='font-size:17px'></button>"; + remove = "<button name='removeComment' data='" + comment.getId() + "'" + disabled + "><i class='fa fa-trash-o' style='font-size:17px'></button>"; } var author = comment.getAuthor(); -- GitLab