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. */
40 observer: 'checkedChanged_',
41 reflectToAttribute: true
44 /** Disabled property for the element. */
49 reflectToAttribute: true
52 /** Checkbox label. */
58 /** Additional sub-label for the checkbox. */
66 'prefValueChanged_(pref.value)'
71 this.$.events.forward(this.$.checkbox, ['change']);
75 * Polymer observer for pref.value.
76 * @param {*} prefValue
79 prefValueChanged_: function(prefValue) {
80 this.checked = this.getNewValue_(prefValue);
84 * Polymer observer for checked.
87 checkedChanged_: function() {
88 this.set('pref.value', this.getNewValue_(this.checked));
93 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
96 getNewValue_: function(value) {
97 return this.inverted ? !value : !!value;
101 * @param {boolean} disabled
102 * @param {?chrome.settingsPrivate.PrefObject} pref
103 * @return {boolean} Whether the checkbox should be disabled.
106 checkboxDisabled_: function(disabled, pref) {
107 return disabled || (!!pref &&
108 pref.policyEnforcement ==
109 chrome.settingsPrivate.PolicyEnforcement.ENFORCED);