Commit e20e3b27 authored by michaelpg's avatar michaelpg Committed by Commit bot

Fix wallpaper button in Guest mode settings

R=stevenjb@chromium.org
BUG=401640

Review URL: https://codereview.chromium.org/599723002

Cr-Commit-Position: refs/heads/master@{#299046}
parent 29fa9447
......@@ -1508,16 +1508,15 @@ cr.define('options', function() {
* @param {boolean} managed
*/
setWallpaperManaged_: function(managed) {
var button = $('set-wallpaper');
button.disabled = !!managed;
if (managed)
$('set-wallpaper').disabled = true;
else
this.enableElementIfPossible_($('set-wallpaper'));
// Create a synthetic pref change event decorated as
// CoreOptionsHandler::CreateValueForPref() does.
var event = new Event('wallpaper');
if (managed)
event.value = { controlledBy: 'policy' };
else
event.value = {};
event.value = managed ? { controlledBy: 'policy' } : {};
$('wallpaper-indicator').handlePrefChange(event);
},
......@@ -1968,6 +1967,18 @@ cr.define('options', function() {
handleSetTime_: function() {
chrome.send('showSetTime');
},
/**
* Enables the given element if possible; on Chrome OS, it won't enable
* an element that must stay disabled for the session type.
* @param {!Element} element Element to enable.
*/
enableElementIfPossible_: function(element) {
if (cr.isChromeOS)
UIAccountTweaks.enableElementIfPossible(element);
else
element.disabled = false;
},
};
//Forward public APIs to private implementations.
......
......@@ -56,6 +56,26 @@ cr.define('uiAccountTweaks', function() {
return loadTimeData.getBoolean('loggedInAsSupervisedUser');
};
/**
* Enables an element unless it should be disabled for the session type.
*
* @param {!Element} element Element that should be enabled.
*/
UIAccountTweaks.enableElementIfPossible = function(element) {
var sessionType;
if (UIAccountTweaks.loggedInAsGuest())
sessionType = SESSION_TYPE_GUEST;
else if (UIAccountTweaks.loggedInAsPublicAccount())
sessionType = SESSION_TYPE_PUBLIC;
if (sessionType &&
element.getAttribute(sessionType + '-visibility') == 'disabled') {
return;
}
element.disabled = false;
}
/**
* Disables or hides some elements in specified type of session in ChromeOS.
* All elements within given document with *sessionType*-visibility
......@@ -68,10 +88,10 @@ cr.define('uiAccountTweaks', function() {
*/
UIAccountTweaks.applySessionTypeVisibility_ = function(document,
sessionType) {
var elements = document.querySelectorAll('['+ sessionType +'-visibility]');
var elements = document.querySelectorAll('['+ sessionType + '-visibility]');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var visibility = element.getAttribute(sessionType +'-visibility');
var visibility = element.getAttribute(sessionType + '-visibility');
if (visibility == 'hidden')
element.hidden = true;
else if (visibility == 'disabled')
......@@ -86,7 +106,7 @@ cr.define('uiAccountTweaks', function() {
* @param {Document} document Document that should processed.
*/
UIAccountTweaks.applyGuestSessionVisibility = function(document) {
if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsGuest())
if (!UIAccountTweaks.loggedInAsGuest())
return;
UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_GUEST);
}
......@@ -98,7 +118,7 @@ cr.define('uiAccountTweaks', function() {
* @param {Document} document Document that should processed.
*/
UIAccountTweaks.applyPublicSessionVisibility = function(document) {
if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsPublicAccount())
if (!UIAccountTweaks.loggedInAsPublicAccount())
return;
UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_PUBLIC);
}
......
Markdown is supported
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