-
-
Notifications
You must be signed in to change notification settings - Fork 554
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 #2649
Changes from 2 commits
0a9f8bc
f584f33
78ca48e
c37f989
b2f2a7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,44 +57,42 @@ window.MSCheckbox = Class.create({ | |
this.state = defaultState; | ||
this.states = [0,1,2]; // 0 = undefined; 1 = allow, 2 = deny | ||
this.nrstates = this.states.length; | ||
this.images = [ | ||
"$xwiki.getSkinFile('js/xwiki/usersandgroups/img/none.png')", | ||
"$xwiki.getSkinFile('js/xwiki/usersandgroups/img/allow.png')", | ||
"$xwiki.getSkinFile('js/xwiki/usersandgroups/img/deny1.png')" | ||
this.icons = [ | ||
"", | ||
"$escapetool.javascript($services.icon.renderHTML('check'))", | ||
"$escapetool.javascript($services.icon.renderHTML('cross'))" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be cleaner to move out the velocity calls, as it's recommended in https://dev.xwiki.org/xwiki/bin/view/Community/DevelopmentPractices#HJavaScriptBestPractices (and what you used in https://github.com/xwiki/xwiki-platform/pull/2648/files#diff-14e05ae329b087de0d0f45b460cdb1b33da4382f3d9c806125daf81cfac152bbR51 for example) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 78ca48e 👍 |
||
]; | ||
this.stateClasses = [ | ||
"none", | ||
"yes", | ||
"no" | ||
]; | ||
|
||
|
||
|
||
this.button = document.createElement("button"); | ||
this.button.className = "rights-edit"; | ||
this.button.className = "btn btn-default btn-xs rights-edit"; | ||
this.button.addEventListener('click', this.createClickHandler(this)); | ||
|
||
var img = document.createElement("img"); | ||
|
||
this.button.appendChild(img); | ||
|
||
$(domNode).appendChild(this.button); | ||
this.draw(this.state); | ||
this.draw(); | ||
}, | ||
|
||
/** | ||
* @todo Draw with the current this.state, don't pass as an argument. | ||
*/ | ||
draw: function(state) | ||
|
||
draw: function() | ||
{ | ||
//Change display image | ||
var img = this.button.firstChild; | ||
img.src = this.images[state]; | ||
//Change display icon | ||
this.button.innerHTML = this.icons[this.state]; | ||
this.button.classList.add(this.stateClasses[this.state]); | ||
|
||
//Update the description of the button for accessibility. | ||
var button = this.button; | ||
var state = this.state; | ||
require(['xwiki-l10n!users-and-groups-translation-keys'], function(l10n) { | ||
var alts = [ | ||
l10n['undefined'], | ||
l10n['allowed'], | ||
l10n['denied'] | ||
]; | ||
img.alt = alts[state]; | ||
button.title = alts[state]; | ||
}); | ||
}, | ||
|
@@ -105,13 +103,16 @@ window.MSCheckbox = Class.create({ | |
|
||
next: function() | ||
{ | ||
// Reinitialize class list | ||
this.button.classList.remove(this.stateClasses[this.state]); | ||
|
||
this.state = this.nextState(); | ||
if (this.table != undefined) { | ||
// TODO: Just update the cache, don't invalidate the row, once the rights are as stored as an | ||
// array, and not as a string. | ||
delete this.table.fetchedRows[this.idx]; | ||
} | ||
this.draw(this.state); | ||
this.draw(); | ||
}, | ||
|
||
/* Confirmation cases: | ||
|
@@ -553,11 +554,9 @@ function setBooleanPropertyFromLiveCheckbox(self, saveDocumentURL, configuration | |
} | ||
var pivot = self; | ||
var newAlt = "yes"; | ||
var newSrc = "$xwiki.getSkinFile('js/xwiki/usersandgroups/img/allow-black.png')"; | ||
var setValue = "1"; | ||
if (self.getAttribute('alt') == "yes") { | ||
newAlt = "no"; | ||
newSrc = "$xwiki.getSkinFile('js/xwiki/usersandgroups/img/none.png')"; | ||
setValue = "0"; | ||
} | ||
var paramMap = {}; | ||
|
@@ -567,7 +566,6 @@ function setBooleanPropertyFromLiveCheckbox(self, saveDocumentURL, configuration | |
paramMap["parameters"]["comment"] = "$services.localization.render('authenticate_viewedit_savecomment')"; | ||
paramMap["onSuccess"] = function() { | ||
pivot.alt = newAlt; | ||
pivot.src = newSrc; | ||
} | ||
new Ajax.Request(saveURL, paramMap); | ||
}; | ||
|
@@ -589,15 +587,13 @@ function setGuestExtendedRights(self) | |
parameters: {"XWiki.XWikiPreferences_0_authenticate_view" : "0"}, | ||
onSuccess: function() { | ||
pivot.alt = "no"; | ||
pivot.src = "$xwiki.getSkinFile('js/xwiki/usersandgroups/img/none.png')"; | ||
}}); | ||
} else { | ||
new Ajax.Request(url, { | ||
method: 'post', | ||
parameters: {"XWiki.XWikiPreferences_0_authenticate_edit" : "0"}, | ||
onSuccess: function() { | ||
pivot.alt = "no"; | ||
pivot.src = "$xwiki.getSkinFile('js/xwiki/usersandgroups/img/none.png')"; | ||
}}); | ||
} | ||
} else { | ||
|
@@ -607,15 +603,13 @@ function setGuestExtendedRights(self) | |
parameters: {"XWiki.XWikiPreferences_0_authenticate_view" : "1"}, | ||
onSuccess: function() { | ||
pivot.alt = "yes"; | ||
pivot.src = "$xwiki.getSkinFile('js/xwiki/usersandgroups/img/allow-black.png')"; | ||
}}); | ||
} else { | ||
new Ajax.Request(url, { | ||
method: 'post', | ||
parameters: {"XWiki.XWikiPreferences_0_authenticate_edit" : "1"}, | ||
onSuccess: function() { | ||
pivot.alt = "yes"; | ||
pivot.src = "$xwiki.getSkinFile('js/xwiki/usersandgroups/img/allow-black.png')"; | ||
}}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit weird here to use
notification(Success|Error)Color
, now maybe that's the best practice in themes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's some of the old colortheme variables. I'm not sure we have a best practice for this. I think I did use those old variables since others are used all throughout the file and I'd rather keep consistent inside one file.
To be honest this whole file looks quite old and breaks current CSS codestyles in multiple places.
I opened a topic on the forum about introducing a new type of label for codestyle, this file could really use a ticket :)
I just checked our HTML and CSS best practices and the entry
don't hard code colors in properties - use [ColorTheme variables](https://extensions.xwiki.org/xwiki/bin/view/Extension/Color%20Theme%20Application#HUsingColorThemesvariables)
points to a doc that uses the old colortheme variables. We might want to update the link or the doc.I'll look a bit more into the state of deprecation of this old colortheme, it's not clear to me what it is yet. Using the old colortheme everywhere does not look like something we should recommend...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the doc to include a link to how to use the new variables.