Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-21597: Make the rights UI use icon themes #2991

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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];
});
Expand Down Expand Up @@ -142,13 +147,13 @@ window.MSCheckbox = Class.create({

var action = "";
var nxtst = (self.state + 1) % self.nrstates;

require(['xwiki-l10n!users-and-groups-translation-keys'], function(l10n) {
Sereza7 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not fully convinced by this part being asynchronous. Couldn't we define this at a more global place. cc @mflorea if you have some idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to require the translations above the MSCheckbox class definition, but this ended in an error in another (synchronous) script that couldn't find MSCheckbox.

// 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;
Expand All @@ -158,7 +163,7 @@ window.MSCheckbox = Class.create({
}
}
} 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;
}
Expand All @@ -167,10 +172,10 @@ window.MSCheckbox = Class.create({
// 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";
Expand All @@ -181,7 +186,7 @@ window.MSCheckbox = Class.create({
}
}
} 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;
Expand All @@ -191,20 +196,19 @@ window.MSCheckbox = Class.create({
// 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;
}
} 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;
}
}
}

if (action == "") {
if (nxtst == 0) {
action = "clear";
Expand All @@ -227,18 +231,19 @@ window.MSCheckbox = Class.create({
//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')");
alert(l10n['platform.core.rightsManagement.saveFailure']);
var rURL = unescape(window.location.pathname);
window.location.href = rURL;
}
},
onFailure: function() {
alert("$services.localization.render('platform.core.rightsManagement.ajaxFailure')");
alert(l10n['platform.core.rightsManagement.ajaxFailure']);
},
onComplete: function() {
delete self.req;
}
});
});
}
}
});
Expand Down