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..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 @@ -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]; }); @@ -142,102 +147,102 @@ window.MSCheckbox = Class.create({ var action = ""; var nxtst = (self.state + 1) % self.nrstates; - - // 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); - if (!confirm(denymessage)) { - var clearmessage = "$escapetool.javascript($services.localization.render('rightsmanager.clearrightforcurrentuserinstead'))".replace('__right__', self.right); - if (confirm(clearmessage)) { - action = "clear"; - self.state = 2; - nxtst = 0; - } else { + 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 { + return; + } + } + } else if (nxtst == 0) { + var clearmessage = l10n['rightsmanager.clearrightforcurrentuser'].replace('__right__', self.right); + if (!confirm(clearmessage)) { return; } } - } else if (nxtst == 0) { - var clearmessage = "$escapetool.javascript($services.localization.render('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 = "$escapetool.javascript($services.localization.render('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); + // 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 = "$escapetool.javascript($services.localization.render('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 = "$escapetool.javascript($services.localization.render('rightsmanager.denyrightforuorg'))".replace('__right__', self.right); - denymessage = denymessage.replace('__name__', self.currentUorG); - if (!confirm(denymessage)) { - return; - } - } else if (nxtst == 0) { - var clearmessage = "$escapetool.javascript($services.localization.render('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("$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; - } + }); }); } }