Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2752)

Unified Diff: chrome/browser/resources/settings/checkbox/checkbox.js

Issue 1310373008: Add cr_policy_indicator for settings controls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_settings_compiled_resources_3
Patch Set: Elim unused tyep Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/checkbox/checkbox.js
diff --git a/chrome/browser/resources/settings/checkbox/checkbox.js b/chrome/browser/resources/settings/checkbox/checkbox.js
index d4bdeb4fc378da44e7864b61c7b6c070f9f80383..6799c6264e1e96a08d3dc20abc0500288f360583 100644
--- a/chrome/browser/resources/settings/checkbox/checkbox.js
+++ b/chrome/browser/resources/settings/checkbox/checkbox.js
@@ -19,29 +19,47 @@ Polymer({
properties: {
/**
* The boolean preference object to control.
- * @type {?PrefObject}
+ * @type {?chrome.settingsPrivate.PrefObject}
*/
pref: {
type: Object,
- notify: true
+ notify: true,
+ value: null
Dan Beam 2015/08/28 00:20:22 nit: we are not IE, feel free to add trailing , so
stevenjb 2015/08/28 23:18:07 I forget where it's OK and where it's not; I think
michaelpg 2015/09/14 05:14:51 also not OK in JSON
},
+ /** Whether the checkbox should represent the inverted value. */
inverted: {
type: Boolean,
value: false
},
+ /** Whether the checkbox is checked. */
checked: {
type: Boolean,
value: false,
observer: 'checkedChanged_'
},
+ /** Set to disable the element. */
+ disabled: {
+ type: Boolean,
+ value: false,
+ observer: 'disabledChanged_'
+ },
+
+ /** The disabled state of the checkbox (may be set by policy). */
+ checkboxDisabled: {
+ type: Boolean,
+ value: false
+ },
+
+ /** Checkbox label. */
label: {
type: String,
value: '',
},
+ /** Additional sub-label for the checkbox. */
subLabel: {
type: String,
value: '',
@@ -49,7 +67,7 @@ Polymer({
},
observers: [
- 'prefValueChanged_(pref.value)'
+ 'prefPropertyChanged_(pref.*)'
],
/** @override */
@@ -57,23 +75,55 @@ Polymer({
this.$.events.forward(this.$.checkbox, ['change']);
},
- /** @private */
- prefValueChanged_: function(prefValue) {
- // prefValue is initially undefined when Polymer initializes pref.
- if (prefValue !== undefined) {
- this.checked = this.getNewValue_(prefValue);
+ /**
+ * Polymer observer for pref.
+ * @param {?{path: string, value: *}} change
+ * @private
+ */
+ prefPropertyChanged_: function(change) {
+ if (change.path == 'pref.value')
+ this.checked = this.getNewValue_(change.value);
+ if (change.path == 'pref.policySource' ||
michaelpg 2015/08/27 23:40:01 else if
stevenjb 2015/08/28 23:18:07 Done.
+ change.path == 'pref.policyEnforcement') {
+ this.checkboxDisabled =
+ this.disabled || this.isSettingDisabled_(this.pref);
}
},
- /** @private */
+ /**
+ * Polymer observer for checked.
+ * @private
+ */
checkedChanged_: function() {
- if (this.pref) {
- this.pref.value = this.getNewValue_(this.checked);
- }
+ if (!this.pref)
+ return;
+ this.pref.value = this.getNewValue_(this.checked);
+ },
+
+ /**
+ * Polymer observer for disabled.
+ * @private
+ */
+ disabledChanged_: function() {
+ this.checkboxDisabled = this.disabled || this.isSettingDisabled_(this.pref);
michaelpg 2015/08/27 23:40:01 nit: instead of adding listeners like disabledChan
stevenjb 2015/08/28 23:18:07 Probably... I'll look into that after I merge with
michaelpg 2015/09/14 05:14:51 could you revisit this? I think having a computed
stevenjb 2015/09/14 23:05:30 Done.
},
- /** @private */
- getNewValue_: function(val) {
- return this.inverted ? !val : val;
- }
+ /**
+ * @param {*} value
+ * @return {boolean} The value as a boolean, inverted if |inverted| is true.
+ * @private
+ */
+ getNewValue_: function(value) {
+ return this.inverted ? !value : !!value;
+ },
+
+ /**
+ * @param {?chrome.settingsPrivate.PrefObject} pref
+ * @return {boolean} True if the setting is either explicitly disabled, or
+ * disabled by the policyEnforcement property.
+ */
+ isSettingDisabled_: function(pref) {
+ return !!pref && pref.policyEnforcement ==
+ chrome.settingsPrivate.PolicyEnforcement.ENFORCED;
+ },
});

Powered by Google App Engine
This is Rietveld 408576698