From 811a82235367bee75b73241fee555267aa71dbf5 Mon Sep 17 00:00:00 2001 From: LucasC Date: Fri, 15 Mar 2024 14:08:51 +0100 Subject: [PATCH 1/5] XWIKI-21597: Make the rights UI use icon themes * Updated the localisation method for the confirmation boxes and others * Changed the code to fit this new structure --- .../js/xwiki/usersandgroups/usersandgroups.js | 128 ++++++++++-------- 1 file changed, 68 insertions(+), 60 deletions(-) diff --git a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js index 7f5fe9aded3a..c566f4b96689 100644 --- a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js +++ b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js @@ -28,19 +28,24 @@ // Start JavaScript-only code. (function(icons) { "use strict"; -define('users-and-groups-translation-keys', { - prefix: 'platform.core.rightsManagement.', - keys: [ - "allowed", - "denied", - "undefined" - ] -}); - +define('users-and-groups-translation-keys', { keys: [ + "platform.core.rightsManagement.allowed", + "platform.core.rightsManagement.denied", + "platform.core.rightsManagement.undefined", + "rightsmanager.denyrightforcurrentuser", + "rightsmanager.clearrightforcurrentuserinstead", + "rightsmanager.clearrightforcurrentuser", + "rightsmanager.denyrightforgroup", + "rightsmanager.clearrightforgroupinstead", + "rightsmanager.clearrightforgroup", + "rightsmanager.denyrightforuorg", + "rightsmanager.clearrightforuorg", + "platform.core.rightsManagement.saveFailure", + "platform.core.rightsManagement.ajaxFailure" +]}); window.MSCheckbox = Class.create({ /** * @todo Make confirmations generic. - * @todo L10N * @todo Send the state number, or a generic map {state => sendValue} * @todo Configuration: automatic save, or just change the value. * @todo "Busy" icon when saving. @@ -100,9 +105,9 @@ window.MSCheckbox = Class.create({ var state = this.state; require(['xwiki-l10n!users-and-groups-translation-keys'], function(l10n) { var alts = [ - l10n['undefined'], - l10n['allowed'], - l10n['denied'] + l10n['platform.core.rightsManagement.undefined'], + l10n['platform.core.rightsManagement.allowed'], + l10n['platform.core.rightsManagement.denied'] ]; button.title = alts[state]; }); @@ -134,7 +139,7 @@ window.MSCheckbox = Class.create({ */ createClickHandler: function(self) { - return function(event) { + return function (event) { event.preventDefault(); if (self.req) { return; @@ -142,103 +147,106 @@ window.MSCheckbox = Class.create({ var action = ""; var nxtst = (self.state + 1) % self.nrstates; - + require(['xwiki-l10n!users-and-groups-translation-keys'], function(l10n) { + var cancelRequest = false; // 1. The current user is clearing / denying himself any right. if (self.currentUorG == window.currentUser) { if (nxtst == 2) { - var denymessage = "$escapetool.javascript($services.localization.render('rightsmanager.denyrightforcurrentuser'))".replace('__right__', self.right); + var denymessage = l10n['rightsmanager.denyrightforcurrentuser'].replace('__right__', self.right); if (!confirm(denymessage)) { - var clearmessage = "$escapetool.javascript($services.localization.render('rightsmanager.clearrightforcurrentuserinstead'))".replace('__right__', self.right); + var clearmessage = l10n['rightsmanager.clearrightforcurrentuserinstead'].replace('__right__', self.right); if (confirm(clearmessage)) { action = "clear"; self.state = 2; nxtst = 0; } else { - return; + cancelRequest = true; } } } else if (nxtst == 0) { - var clearmessage = "$escapetool.javascript($services.localization.render('rightsmanager.clearrightforcurrentuser'))".replace('__right__', self.right); + var clearmessage = l10n['rightsmanager.clearrightforcurrentuser'].replace('__right__', self.right); if (!confirm(clearmessage)) { - return; + cancelRequest = true; } } } // 2. The current user is clearing / denying any rights for a group he belongs to. else if (self.isUserInGroup || (window.currentUser == "XWiki.XWikiGuest" && self.currentUorG == "XWiki.XWikiAllGroup")) { if (nxtst == 2) { - var denymessage = "$escapetool.javascript($services.localization.render('rightsmanager.denyrightforgroup'))".replace(/__right__/g, self.right); + var denymessage = l10n['rightsmanager.denyrightforgroup'].replace(/__right__/g, self.right); denymessage = denymessage.replace('__name__', self.currentUorG); if (!confirm(denymessage)) { - var clearmessage = "$escapetool.javascript($services.localization.render('rightsmanager.clearrightforgroupinstead'))".replace(/__right__/g, self.right); + var clearmessage = l10n['rightsmanager.clearrightforgroupinstead'].replace(/__right__/g, self.right); clearmessage = clearmessage.replace('__name__', self.currentUorG); if (confirm(clearmessage)) { action = "clear"; self.state = 2; nxtst = 0; } else { - return; + cancelRequest = true; } } } else if (nxtst == 0) { - var clearmessage = "$escapetool.javascript($services.localization.render('rightsmanager.clearrightforgroup'))".replace(/__right__/g, self.right); + var clearmessage = l10n['rightsmanager.clearrightforgroup'].replace(/__right__/g, self.right); clearmessage = clearmessage.replace('__name__', self.currentUorG); if (!confirm(clearmessage)) { - return; + cancelRequest = true; } } } // 3. The current user is is clearing / denying admin right for any user / group. else if (self.right == "admin") { if (nxtst == 2) { - var denymessage = "$escapetool.javascript($services.localization.render('rightsmanager.denyrightforuorg'))".replace('__right__', self.right); + var denymessage = l10n['rightsmanager.denyrightforuorg'].replace('__right__', self.right); denymessage = denymessage.replace('__name__', self.currentUorG); if (!confirm(denymessage)) { - return; + cancelRequest = true; } } else if (nxtst == 0) { - var clearmessage = "$escapetool.javascript($services.localization.render('rightsmanager.clearrightforuorg'))".replace('__right__', self.right); + var clearmessage = l10n['rightsmanager.clearrightforuorg'].replace('__right__', self.right); clearmessage = clearmessage.replace('__name__', self.currentUorG); if (!confirm(clearmessage)) { - return; + cancelRequest = true; } } } - - if (action == "") { - if (nxtst == 0) { - action = "clear"; - } else if (nxtst == 1) { - action = "allow"; - } else { - action = "deny"; + if(!cancelRequest) { + if (action == "") { + if (nxtst == 0) { + action = "clear"; + } else if (nxtst == 1) { + action = "allow"; + } else { + action = "deny"; + } } - } - // Compose the complete URI - var url = self.saveUrl + "&action=" + action + "&right=" + self.right; + // Compose the complete URI + var url = self.saveUrl + "&action=" + action + "&right=" + self.right; - self.req = new Ajax.Request(url, { - method: 'get', - onSuccess: function(transport) { - if (transport.responseText.strip() == "SUCCESS") { - self.next(); - } else { - //if an error occurred while trying to save a right rule, display an alert - // and refresh the page, since probably the user does not have the right to perform - // that action - alert("$services.localization.render('platform.core.rightsManagement.saveFailure')"); - var rURL = unescape(window.location.pathname); - window.location.href = rURL; + self.req = new Ajax.Request(url, { + method: 'get', + onSuccess: function (transport) { + if (transport.responseText.strip() == "SUCCESS") { + self.next(); + } else { + //if an error occurred while trying to save a right rule, display an alert + // and refresh the page, since probably the user does not have the right to perform + // that action + alert(l10n['platform.core.rightsManagement.saveFailure']); + var rURL = unescape(window.location.pathname); + window.location.href = rURL; + } + }, + onFailure: function () { + alert(l10n['platform.core.rightsManagement.ajaxFailure']); + }, + onComplete: function () { + delete self.req; } - }, - onFailure: function() { - alert("$services.localization.render('platform.core.rightsManagement.ajaxFailure')"); - }, - onComplete: function() { - delete self.req; - } - }); + }); + } + }); } } }); From feefc2b2e5ce1bc384466d747f2f9671d7a23827 Mon Sep 17 00:00:00 2001 From: LucasC Date: Fri, 15 Mar 2024 14:20:56 +0100 Subject: [PATCH 2/5] XWIKI-21597: Make the rights UI use icon themes * Removed an unneeded change --- .../js/xwiki/usersandgroups/usersandgroups.js | 75 +++++++++---------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js index c566f4b96689..45f2cba15873 100644 --- a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js +++ b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js @@ -148,7 +148,6 @@ window.MSCheckbox = Class.create({ var action = ""; var nxtst = (self.state + 1) % self.nrstates; require(['xwiki-l10n!users-and-groups-translation-keys'], function(l10n) { - var cancelRequest = false; // 1. The current user is clearing / denying himself any right. if (self.currentUorG == window.currentUser) { if (nxtst == 2) { @@ -160,13 +159,13 @@ window.MSCheckbox = Class.create({ self.state = 2; nxtst = 0; } else { - cancelRequest = true; + return; } } } else if (nxtst == 0) { var clearmessage = l10n['rightsmanager.clearrightforcurrentuser'].replace('__right__', self.right); if (!confirm(clearmessage)) { - cancelRequest = true; + return; } } } @@ -183,14 +182,14 @@ window.MSCheckbox = Class.create({ self.state = 2; nxtst = 0; } else { - cancelRequest = true; + return; } } } else if (nxtst == 0) { var clearmessage = l10n['rightsmanager.clearrightforgroup'].replace(/__right__/g, self.right); clearmessage = clearmessage.replace('__name__', self.currentUorG); if (!confirm(clearmessage)) { - cancelRequest = true; + return; } } } @@ -200,52 +199,50 @@ window.MSCheckbox = Class.create({ var denymessage = l10n['rightsmanager.denyrightforuorg'].replace('__right__', self.right); denymessage = denymessage.replace('__name__', self.currentUorG); if (!confirm(denymessage)) { - cancelRequest = true; + return; } } else if (nxtst == 0) { var clearmessage = l10n['rightsmanager.clearrightforuorg'].replace('__right__', self.right); clearmessage = clearmessage.replace('__name__', self.currentUorG); if (!confirm(clearmessage)) { - cancelRequest = true; + return; } } } - if(!cancelRequest) { - if (action == "") { - if (nxtst == 0) { - action = "clear"; - } else if (nxtst == 1) { - action = "allow"; - } else { - action = "deny"; - } + if (action == "") { + if (nxtst == 0) { + action = "clear"; + } else if (nxtst == 1) { + action = "allow"; + } else { + action = "deny"; } + } - // Compose the complete URI - var url = self.saveUrl + "&action=" + action + "&right=" + self.right; + // Compose the complete URI + var url = self.saveUrl + "&action=" + action + "&right=" + self.right; - self.req = new Ajax.Request(url, { - method: 'get', - onSuccess: function (transport) { - if (transport.responseText.strip() == "SUCCESS") { - self.next(); - } else { - //if an error occurred while trying to save a right rule, display an alert - // and refresh the page, since probably the user does not have the right to perform - // that action - alert(l10n['platform.core.rightsManagement.saveFailure']); - var rURL = unescape(window.location.pathname); - window.location.href = rURL; - } - }, - onFailure: function () { - alert(l10n['platform.core.rightsManagement.ajaxFailure']); - }, - onComplete: function () { - delete self.req; + self.req = new Ajax.Request(url, { + method: 'get', + onSuccess: function (transport) { + if (transport.responseText.strip() == "SUCCESS") { + self.next(); + } else { + //if an error occurred while trying to save a right rule, display an alert + // and refresh the page, since probably the user does not have the right to perform + // that action + alert(l10n['platform.core.rightsManagement.saveFailure']); + var rURL = unescape(window.location.pathname); + window.location.href = rURL; } - }); - } + }, + onFailure: function () { + alert(l10n['platform.core.rightsManagement.ajaxFailure']); + }, + onComplete: function () { + delete self.req; + } + }); }); } } From fbdffd62cd2f12a4c2313fbf6f22b3801b0b8eb2 Mon Sep 17 00:00:00 2001 From: LucasC Date: Fri, 15 Mar 2024 14:23:06 +0100 Subject: [PATCH 3/5] XWIKI-21597: Make the rights UI use icon themes * Removed unwanted codestyle change --- .../resources/js/xwiki/usersandgroups/usersandgroups.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js index 45f2cba15873..d2eed758ee3e 100644 --- a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js +++ b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js @@ -224,7 +224,7 @@ window.MSCheckbox = Class.create({ self.req = new Ajax.Request(url, { method: 'get', - onSuccess: function (transport) { + onSuccess: function(transport) { if (transport.responseText.strip() == "SUCCESS") { self.next(); } else { @@ -236,10 +236,10 @@ window.MSCheckbox = Class.create({ window.location.href = rURL; } }, - onFailure: function () { + onFailure: function() { alert(l10n['platform.core.rightsManagement.ajaxFailure']); }, - onComplete: function () { + onComplete: function() { delete self.req; } }); From 18b6c89ec9a74f18a1d1dfa72468ec224fcb1a56 Mon Sep 17 00:00:00 2001 From: LucasC Date: Fri, 15 Mar 2024 14:23:49 +0100 Subject: [PATCH 4/5] XWIKI-21597: Make the rights UI use icon themes * Removed unwanted codestyle change --- .../webapp/resources/js/xwiki/usersandgroups/usersandgroups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js index d2eed758ee3e..59e9f63db480 100644 --- a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js +++ b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js @@ -139,7 +139,7 @@ window.MSCheckbox = Class.create({ */ createClickHandler: function(self) { - return function (event) { + return function(event) { event.preventDefault(); if (self.req) { return; From 56ef94abdb1120ce8e41dae39afb907b564791fe Mon Sep 17 00:00:00 2001 From: LucasC Date: Fri, 15 Mar 2024 14:32:02 +0100 Subject: [PATCH 5/5] XWIKI-21597: Make the rights UI use icon themes * Fixed indentation --- .../js/xwiki/usersandgroups/usersandgroups.js | 160 +++++++++--------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js index 59e9f63db480..6988dbbee153 100644 --- a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js +++ b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/usersandgroups/usersandgroups.js @@ -148,102 +148,102 @@ window.MSCheckbox = Class.create({ var action = ""; var nxtst = (self.state + 1) % self.nrstates; require(['xwiki-l10n!users-and-groups-translation-keys'], function(l10n) { - // 1. The current user is clearing / denying himself any right. - if (self.currentUorG == window.currentUser) { - if (nxtst == 2) { - var denymessage = l10n['rightsmanager.denyrightforcurrentuser'].replace('__right__', self.right); - if (!confirm(denymessage)) { - var clearmessage = l10n['rightsmanager.clearrightforcurrentuserinstead'].replace('__right__', self.right); - if (confirm(clearmessage)) { - action = "clear"; - self.state = 2; - nxtst = 0; - } else { + // 1. The current user is clearing / denying himself any right. + if (self.currentUorG == window.currentUser) { + if (nxtst == 2) { + var denymessage = l10n['rightsmanager.denyrightforcurrentuser'].replace('__right__', self.right); + if (!confirm(denymessage)) { + var clearmessage = l10n['rightsmanager.clearrightforcurrentuserinstead'].replace('__right__', self.right); + if (confirm(clearmessage)) { + action = "clear"; + self.state = 2; + nxtst = 0; + } else { + return; + } + } + } else if (nxtst == 0) { + var clearmessage = l10n['rightsmanager.clearrightforcurrentuser'].replace('__right__', self.right); + if (!confirm(clearmessage)) { return; } } - } else if (nxtst == 0) { - var clearmessage = l10n['rightsmanager.clearrightforcurrentuser'].replace('__right__', self.right); - if (!confirm(clearmessage)) { - return; - } } - } - // 2. The current user is clearing / denying any rights for a group he belongs to. - else if (self.isUserInGroup || (window.currentUser == "XWiki.XWikiGuest" && self.currentUorG == "XWiki.XWikiAllGroup")) { - if (nxtst == 2) { - var denymessage = l10n['rightsmanager.denyrightforgroup'].replace(/__right__/g, self.right); - denymessage = denymessage.replace('__name__', self.currentUorG); - if (!confirm(denymessage)) { - var clearmessage = l10n['rightsmanager.clearrightforgroupinstead'].replace(/__right__/g, self.right); + // 2. The current user is clearing / denying any rights for a group he belongs to. + else if (self.isUserInGroup || (window.currentUser == "XWiki.XWikiGuest" && self.currentUorG == "XWiki.XWikiAllGroup")) { + if (nxtst == 2) { + var denymessage = l10n['rightsmanager.denyrightforgroup'].replace(/__right__/g, self.right); + denymessage = denymessage.replace('__name__', self.currentUorG); + if (!confirm(denymessage)) { + var clearmessage = l10n['rightsmanager.clearrightforgroupinstead'].replace(/__right__/g, self.right); + clearmessage = clearmessage.replace('__name__', self.currentUorG); + if (confirm(clearmessage)) { + action = "clear"; + self.state = 2; + nxtst = 0; + } else { + return; + } + } + } else if (nxtst == 0) { + var clearmessage = l10n['rightsmanager.clearrightforgroup'].replace(/__right__/g, self.right); clearmessage = clearmessage.replace('__name__', self.currentUorG); - if (confirm(clearmessage)) { - action = "clear"; - self.state = 2; - nxtst = 0; - } else { + if (!confirm(clearmessage)) { return; } } - } else if (nxtst == 0) { - var clearmessage = l10n['rightsmanager.clearrightforgroup'].replace(/__right__/g, self.right); - clearmessage = clearmessage.replace('__name__', self.currentUorG); - if (!confirm(clearmessage)) { - return; - } } - } - // 3. The current user is is clearing / denying admin right for any user / group. - else if (self.right == "admin") { - if (nxtst == 2) { - var denymessage = l10n['rightsmanager.denyrightforuorg'].replace('__right__', self.right); - denymessage = denymessage.replace('__name__', self.currentUorG); - if (!confirm(denymessage)) { - return; - } - } else if (nxtst == 0) { - var clearmessage = l10n['rightsmanager.clearrightforuorg'].replace('__right__', self.right); - clearmessage = clearmessage.replace('__name__', self.currentUorG); - if (!confirm(clearmessage)) { - return; + // 3. The current user is is clearing / denying admin right for any user / group. + else if (self.right == "admin") { + if (nxtst == 2) { + var denymessage = l10n['rightsmanager.denyrightforuorg'].replace('__right__', self.right); + denymessage = denymessage.replace('__name__', self.currentUorG); + if (!confirm(denymessage)) { + return; + } + } else if (nxtst == 0) { + var clearmessage = l10n['rightsmanager.clearrightforuorg'].replace('__right__', self.right); + clearmessage = clearmessage.replace('__name__', self.currentUorG); + if (!confirm(clearmessage)) { + return; + } } } - } - if (action == "") { - if (nxtst == 0) { - action = "clear"; - } else if (nxtst == 1) { - action = "allow"; - } else { - action = "deny"; + if (action == "") { + if (nxtst == 0) { + action = "clear"; + } else if (nxtst == 1) { + action = "allow"; + } else { + action = "deny"; + } } - } - // Compose the complete URI - var url = self.saveUrl + "&action=" + action + "&right=" + self.right; + // Compose the complete URI + var url = self.saveUrl + "&action=" + action + "&right=" + self.right; - self.req = new Ajax.Request(url, { - method: 'get', - onSuccess: function(transport) { - if (transport.responseText.strip() == "SUCCESS") { - self.next(); - } else { - //if an error occurred while trying to save a right rule, display an alert - // and refresh the page, since probably the user does not have the right to perform - // that action - alert(l10n['platform.core.rightsManagement.saveFailure']); - var rURL = unescape(window.location.pathname); - window.location.href = rURL; + self.req = new Ajax.Request(url, { + method: 'get', + onSuccess: function(transport) { + if (transport.responseText.strip() == "SUCCESS") { + self.next(); + } else { + //if an error occurred while trying to save a right rule, display an alert + // and refresh the page, since probably the user does not have the right to perform + // that action + alert(l10n['platform.core.rightsManagement.saveFailure']); + var rURL = unescape(window.location.pathname); + window.location.href = rURL; + } + }, + onFailure: function() { + alert(l10n['platform.core.rightsManagement.ajaxFailure']); + }, + onComplete: function() { + delete self.req; } - }, - onFailure: function() { - alert(l10n['platform.core.rightsManagement.ajaxFailure']); - }, - onComplete: function() { - delete self.req; - } + }); }); - }); } } });