Commit 5ae37bcc authored by mnissler@chromium.org's avatar mnissler@chromium.org

Add support for recommended settings to the internet details dialog.

Extend the controlled settings bubble code to allow for an event to be
fired upon user request to apply the recommended setting. Handle the
recommended case properly for the internet detail dialog by enabling
controls for recommended settings and handling resets by restoring the
default value in the control.

BUG=chromium-os:23124
TEST=Configure recommended settings for a network (currently only AutoConnect is relevant) and check the "Options" dialog for that network.

Review URL: http://codereview.chromium.org/8815014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114624 0039d316-1c4b-4281-b951-d872f2087c98
parent ee63f326
...@@ -40,6 +40,70 @@ cr.define('options.internet', function() { ...@@ -40,6 +40,70 @@ cr.define('options.internet', function() {
OptionsPage.prototype.initializePage.call(this); OptionsPage.prototype.initializePage.call(this);
}, },
/**
* Initializes the controlled setting indicators for the page.
* @param {Object} data Dictionary with metadata about the settings.
*/
initializeControlledSettingIndicators: function(data) {
indicators =
this.pageDiv.querySelectorAll('.controlled-setting-indicator');
for (var i = 0; i < indicators.length; i++) {
var dataProperty = indicators[i].getAttribute('data');
if (dataProperty && data[dataProperty]) {
this.initializeIndicator_(indicators[i],
data[dataProperty].controlledBy,
data[dataProperty].default);
}
}
},
/**
* Sets up a single controlled setting indicator, setting the controlledBy
* property and an event handler for resetting to the default value if
* appropriate.
* @param {Object} indicator The indicator element.
* @param {string} controlledBy The entity that controls the setting.
* @param {Object} defaultValue The default value to reset to, if
* applicable.
*/
initializeIndicator_ : function(indicator, controlledBy, defaultValue) {
var forElement = $(indicator.getAttribute('for'));
var recommended = controlledBy == 'recommended';
if (!controlledBy || (recommended && !defaultValue))
controlledBy = null;
indicator.controlledBy = controlledBy;
if (forElement) {
forElement.disabled = !recommended;
// Special handling for radio buttons:
// - If the setting is recommended, show the recommended indicator
// next to the choice that is recommended.
// - Else, show the indicator next to the selected choice.
if (forElement.type == 'radio') {
if (recommended)
indicator.hidden = (defaultValue != forElement.value);
else
indicator.hidden = !forElement.checked;
}
indicator.setAttribute('allow-reset');
indicator.addEventListener(
'reset',
function(element, e) {
if (forElement.type == 'radio' || forElement.type == 'checkbox') {
// The recommended setting indicator is always shown next to
// the recommended choice.
forElement.checked = true;
} else {
forElement.value = defaultValue;
}
e.preventDefault();
});
}
},
/** /**
* Update details page controls. * Update details page controls.
* @private * @private
......
...@@ -673,25 +673,7 @@ cr.define('options', function() { ...@@ -673,25 +673,7 @@ cr.define('options', function() {
detailsPage.gsm = false; detailsPage.gsm = false;
} }
// Update controlled option indicators. detailsPage.initializeControlledSettingIndicators(data)
indicators = cr.doc.querySelectorAll(
'#detailsInternetPage .controlled-setting-indicator');
for (var i = 0; i < indicators.length; i++) {
var dataProperty = indicators[i].getAttribute('data');
if (dataProperty && data[dataProperty]) {
var controlledBy = data[dataProperty].controlledBy;
if (controlledBy) {
indicators[i].controlledBy = controlledBy;
var forElement = $(indicators[i].getAttribute('for'));
if (forElement)
forElement.disabled = true;
if (forElement.type == 'radio' && !forElement.checked)
indicators[i].hidden = true;
} else {
indicators[i].controlledBy = null;
}
}
}
// Don't show page name in address bar and in history to prevent people // Don't show page name in address bar and in history to prevent people
// navigate here by hand and solve issue with page session restore. // navigate here by hand and solve issue with page session restore.
......
...@@ -98,8 +98,8 @@ cr.define('options', function() { ...@@ -98,8 +98,8 @@ cr.define('options', function() {
bubbleText.className = 'controlled-setting-bubble-text'; bubbleText.className = 'controlled-setting-bubble-text';
bubbleText.textContent = text; bubbleText.textContent = text;
var pref = self.getAttribute('pref'); var allowReset = self.getAttribute('allow-reset');
if (self.controlledBy == 'recommended' && pref) { if (self.controlledBy == 'recommended' && allowReset) {
var container = doc.createElement('div'); var container = doc.createElement('div');
var action = doc.createElement('button'); var action = doc.createElement('button');
action.classList.add('link-button'); action.classList.add('link-button');
...@@ -109,7 +109,12 @@ cr.define('options', function() { ...@@ -109,7 +109,12 @@ cr.define('options', function() {
action.addEventListener( action.addEventListener(
'click', 'click',
function(e) { function(e) {
Preferences.clearPref(pref); // Fire the reset event, falling back to just resetting the pref.
if (!cr.dispatchSimpleEvent(self, 'reset', true, true)) {
var pref = self.getAttribute('pref');
if (pref)
Preferences.clearPref(pref);
}
}); });
container.appendChild(action); container.appendChild(action);
bubbleText.appendChild(container); bubbleText.appendChild(container);
......
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