Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * `settings-checkbox` is a checkbox that controls a supplied preference. | 7 * `settings-checkbox` is a checkbox that controls a supplied preference. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * <settings-checkbox pref="{{prefs.settings.enableFoo}}" | 10 * <settings-checkbox pref="{{prefs.settings.enableFoo}}" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 */ | 80 */ |
| 81 prefValueChanged_: function(prefValue) { | 81 prefValueChanged_: function(prefValue) { |
| 82 this.checked = this.getNewValue_(prefValue); | 82 this.checked = this.getNewValue_(prefValue); |
| 83 }, | 83 }, |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * Polymer observer for checked. | 86 * Polymer observer for checked. |
| 87 * @private | 87 * @private |
| 88 */ | 88 */ |
| 89 checkedChanged_: function() { | 89 checkedChanged_: function() { |
| 90 this.set('pref.value', this.getNewValue_(this.checked)); | 90 if (!this.pref) |
| 91 return; | |
| 92 /** @type {boolean} */ var newValue = this.getNewValue_(this.checked); | |
| 93 // Ensure that newValue is the correct type for the pref type, either | |
| 94 // a bolean or a number. | |
|
Dan Beam
2015/12/02 05:11:59
boolean
stevenjb
2015/12/02 18:14:51
Done.
| |
| 95 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { | |
| 96 this.set('pref.value', newValue ? 1 : 0); | |
| 97 return; | |
| 98 } | |
| 99 this.set('pref.value', newValue); | |
| 91 }, | 100 }, |
| 92 | 101 |
| 93 /** | 102 /** |
| 94 * @param {*} value | 103 * @param {*} value |
| 95 * @return {boolean} The value as a boolean, inverted if |inverted| is true. | 104 * @return {boolean} The value as a boolean, inverted if |inverted| is true. |
| 96 * @private | 105 * @private |
| 97 */ | 106 */ |
| 98 getNewValue_: function(value) { | 107 getNewValue_: function(value) { |
| 99 return this.inverted ? !value : !!value; | 108 return this.inverted ? !value : !!value; |
| 100 }, | 109 }, |
| 101 | 110 |
| 102 /** | 111 /** |
| 103 * @param {boolean} disabled | 112 * @param {boolean} disabled |
| 104 * @param {!chrome.settingsPrivate.PrefObject} pref | 113 * @param {!chrome.settingsPrivate.PrefObject} pref |
| 105 * @return {boolean} Whether the checkbox should be disabled. | 114 * @return {boolean} Whether the checkbox should be disabled. |
| 106 * @private | 115 * @private |
| 107 */ | 116 */ |
| 108 checkboxDisabled_: function(disabled, pref) { | 117 checkboxDisabled_: function(disabled, pref) { |
| 109 return disabled || this.isPrefPolicyControlled(pref); | 118 return disabled || this.isPrefPolicyControlled(pref); |
| 110 }, | 119 }, |
| 111 }); | 120 }); |
| OLD | NEW |