Commit cb28d9f3 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when user is admin disable tab with project privileges

parent add727c3
......@@ -67,6 +67,12 @@ ServerConnector.init = function () {
self._projectsById = [];
self._users = [];
/**
*
* @type {Object.<string,User>}
* @private
*/
self._usersByLogin = [];
self._customMap = null;
......@@ -1528,13 +1534,16 @@ ServerConnector.grantUserPrivileges = function (params) {
}).then(function (content) {
var obj = JSON.parse(content);
var user = new User(obj);
var promise = Promise.resolve();
if (self._usersByLogin[user.getLogin()] !== undefined) {
self._usersByLogin[user.getLogin()].update(user);
promise = self._usersByLogin[user.getLogin()].update(user);
} else {
self._usersByLogin[user.getLogin()] = user;
}
return self._usersByLogin[user.getLogin()];
}).then(null, function (error) {
return promise;
}).then(function () {
return self._usersByLogin[params.user.getLogin()];
}).catch(function (error) {
return self.processNetworkError(error);
});
};
......
......@@ -204,7 +204,7 @@ EditUserDialog.prototype.createGeneralTabContent = function () {
});
$(result).on("click", "[name='userRole']", function () {
$(result).on("click", "[name='user-role-" + self.getUser().getLogin() + "']", function () {
var field = this;
var role = $('[name="user-role-' + self.getUser().getLogin() + '"]:checked', field).val();
var promises = [];
......@@ -212,14 +212,17 @@ EditUserDialog.prototype.createGeneralTabContent = function () {
promises.push(self.grantPrivilege({privilegeType: PrivilegeType.IS_ADMIN}));
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_CURATOR}));
$("[name='user-can-create-overlay-div']", result).css("display", "none");
guiUtils.disableTab($(".minerva-project-privileges-tab", self.getElement())[0], "Admin can do everything")
} else if (role === "CURATOR") {
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_ADMIN}));
promises.push(self.grantPrivilege({privilegeType: PrivilegeType.IS_CURATOR}));
$("[name='user-can-create-overlay-div']", result).css("display", "none");
guiUtils.enableTab($(".minerva-project-privileges-tab", self.getElement())[0]);
} else if (role === "USER") {
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_ADMIN}));
promises.push(self.revokePrivilege({privilegeType: PrivilegeType.IS_CURATOR}));
$("[name='user-can-create-overlay-div']", result).css("display", "block");
guiUtils.enableTab($(".minerva-project-privileges-tab", self.getElement())[0]);
} else {
GuiConnector.alert("Invalid role: " + role);
}
......@@ -237,7 +240,8 @@ EditUserDialog.prototype.createProjectsTabContent = function () {
var self = this;
var result = Functions.createElement({
type: "div",
style: "margin-top:10px;"
style: "margin-top:10px;",
className: "minerva-project-privileges-tab"
});
result.appendChild(self._createProjectsTable());
return result;
......@@ -342,6 +346,7 @@ EditUserDialog.prototype.refresh = function () {
if (user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_ADMIN))) {
adminChecked = " checked ";
guiUtils.disableTab($(".minerva-project-privileges-tab", self.getElement())[0], "Admin can do everything");
} else if (user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_CURATOR))) {
curatorChecked = " checked ";
} else {
......
......@@ -1193,18 +1193,36 @@ GuiUtils.prototype.hideTab = function (abstractGuiElement, panel) {
* @param {string} message
*/
GuiUtils.prototype.disableTab = function (element, message) {
$(element).children().css("visibility", "hidden");
$("[class='minerva-help-button']", element).children().css("visibility", "visible");
var hideReasonDiv = document.createElement("div");
hideReasonDiv.className = "searchPanel";
var center = document.createElement("center");
var messageDiv = document.createElement("h4");
messageDiv.innerHTML = message;
center.appendChild(messageDiv);
hideReasonDiv.appendChild(center);
$(element).prepend(hideReasonDiv);
var hideReason = $(".minerva-hide-reason", element);
if (hideReason.length === 0) {
console.log("not hidden");
$(element).children().css("visibility", "hidden");
$("[class='minerva-help-button']", element).children().css("visibility", "visible");
var hideReasonDiv = document.createElement("div");
hideReasonDiv.className = "searchPanel minerva-hide-reason";
var center = document.createElement("center");
var messageDiv = document.createElement("h4");
messageDiv.innerHTML = message;
center.appendChild(messageDiv);
hideReasonDiv.appendChild(center);
$(element).prepend(hideReasonDiv);
}
};
/**
*
* @param {HTMLElement} element
*/
GuiUtils.prototype.enableTab = function (element) {
var hideReason = $(".minerva-hide-reason", element);
if (hideReason.length > 0) {
hideReason.remove();
$(element).children().css("visibility", "visible");
$("[class='minerva-help-button']", element).children().css("visibility", "visible");
}
};
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment