| 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 * `cr-radio-group` wraps a radio-group and set of radio-buttons that control | 7 * `cr-radio-group` wraps a radio-group and set of radio-buttons that control |
| 8 * a supplied preference. | 8 * a supplied preference. |
| 9 * | 9 * |
| 10 * Example: | 10 * Example: |
| 11 * <settings-radio-group pref="{{prefs.settings.foo}}" | 11 * <settings-radio-group pref="{{prefs.settings.foo}}" |
| 12 * label="Foo Options." buttons="{{fooOptionsList}}"> | 12 * label="Foo Options." buttons="{{fooOptionsList}}"> |
| 13 * </settings-radio-group> | 13 * </settings-radio-group> |
| 14 */ | 14 */ |
| 15 Polymer({ | 15 Polymer({ |
| 16 is: 'settings-radio-group', | 16 is: 'settings-radio-group', |
| 17 | 17 |
| 18 behaviors: [CrPolicyPrefBehavior, PrefControlBehavior], | 18 behaviors: [PrefControlBehavior], |
| 19 | 19 |
| 20 properties: { | 20 properties: { |
| 21 disabled_: { | |
| 22 observer: 'disabledChanged_', | |
| 23 type: Boolean, | |
| 24 value: false, | |
| 25 }, | |
| 26 | |
| 27 /** | 21 /** |
| 28 * IronSelectableBehavior selected attribute. | 22 * IronSelectableBehavior selected attribute. |
| 29 */ | 23 */ |
| 30 selected: { | 24 selected: { |
| 31 type: String, | 25 type: String, |
| 32 notify: true, | 26 notify: true, |
| 33 observer: 'selectedChanged_' | 27 observer: 'selectedChanged_' |
| 34 }, | 28 }, |
| 35 }, | 29 }, |
| 36 | 30 |
| 37 observers: [ | 31 observers: [ |
| 38 'prefChanged_(pref.*)', | 32 'prefChanged_(pref.*)', |
| 39 ], | 33 ], |
| 40 | 34 |
| 41 /** @private */ | 35 /** @private */ |
| 42 prefChanged_: function() { | 36 prefChanged_: function() { |
| 43 var pref = /** @type {!chrome.settingsPrivate.PrefObject} */(this.pref); | 37 var pref = /** @type {!chrome.settingsPrivate.PrefObject} */(this.pref); |
| 44 this.disabled_ = this.isPrefPolicyControlled(pref); | |
| 45 this.selected = Settings.PrefUtil.prefToString(pref); | 38 this.selected = Settings.PrefUtil.prefToString(pref); |
| 46 }, | 39 }, |
| 47 | 40 |
| 48 /** @private */ | 41 /** @private */ |
| 49 disabledChanged_: function() { | |
| 50 var radioButtons = this.queryAllEffectiveChildren('paper-radio-button'); | |
| 51 for (var i = 0; i < radioButtons.length; ++i) { | |
| 52 radioButtons[i].disabled = this.disabled_; | |
| 53 } | |
| 54 }, | |
| 55 | |
| 56 /** @private */ | |
| 57 selectedChanged_: function(selected) { | 42 selectedChanged_: function(selected) { |
| 58 if (!this.pref) | 43 if (!this.pref) |
| 59 return; | 44 return; |
| 60 this.set('pref.value', | 45 this.set('pref.value', |
| 61 Settings.PrefUtil.stringToPrefValue(selected, this.pref)); | 46 Settings.PrefUtil.stringToPrefValue(selected, this.pref)); |
| 62 }, | 47 }, |
| 63 }); | 48 }); |
| OLD | NEW |