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',
19 behaviors
: [PolicyControllable
],
23 * The boolean preference object to control.
24 * @type {?chrome.settingsPrivate.PrefObject}
31 /** Whether the checkbox should represent the inverted value. */
37 /** Whether the checkbox is checked. */
42 observer
: 'checkedChanged_',
43 reflectToAttribute
: true
46 /** Disabled property for the element. */
51 reflectToAttribute
: true
54 /** Checkbox label. */
60 /** Additional sub-label for the checkbox. */
68 'prefValueChanged_(pref.value)'
73 this.$.events
.forward(this.$.checkbox
, ['change']);
77 * Polymer observer for pref.value.
78 * @param {*} prefValue
81 prefValueChanged_: function(prefValue
) {
82 this.checked
= this.getNewValue_(prefValue
);
86 * Polymer observer for checked.
89 checkedChanged_: function() {
90 this.set('pref.value', this.getNewValue_(this.checked
));
95 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
98 getNewValue_: function(value
) {
99 return this.inverted
? !value
: !!value
;
103 * @param {boolean} disabled
104 * @param {?chrome.settingsPrivate.PrefObject} pref
105 * @return {boolean} Whether the checkbox should be disabled.
108 checkboxDisabled_: function(disabled
, pref
) {
109 return disabled
|| this.isPolicyControlled(pref
);