1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference.
10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}"
11 * label="Enable foo setting." subLabel="(bar also)">
12 * </cr-settings-checkbox>
14 * @element cr-settings-checkbox
17 is
: 'cr-settings-checkbox',
21 * The boolean preference object to control.
22 * @type {?chrome.settingsPrivate.PrefObject}
29 /** Whether the checkbox should represent the inverted value. */
35 /** Whether the checkbox is checked. */
39 observer
: 'checkedChanged_',
42 /** Disabled property for the element. */
48 /** Checkbox label. */
54 /** Additional sub-label for the checkbox. */
62 'prefValueChanged_(pref.value)'
67 this.$.events
.forward(this.$.checkbox
, ['change']);
71 * Polymer observer for pref.value.
72 * @param {*} prefValue
75 prefValueChanged_: function(prefValue
) {
76 this.checked
= this.getNewValue_(prefValue
);
80 * Polymer observer for checked.
83 checkedChanged_: function() {
84 this.set('pref.value', this.getNewValue_(this.checked
));
89 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
92 getNewValue_: function(value
) {
93 return this.inverted
? !value
: !!value
;
97 * @param {boolean} disabled
98 * @param {?chrome.settingsPrivate.PrefObject} pref
99 * @return {boolean} Whether the checkbox should be disabled.
102 checkboxDisabled_: function(disabled
, pref
) {
103 return disabled
|| (!!pref
&&
104 pref
.policyEnforcement
==
105 chrome
.settingsPrivate
.PolicyEnforcement
.ENFORCED
);