| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * `cr-radio-group` wraps a radio-group and set of radio-buttons that control | |
| 8 * a supplied preference. | |
| 9 * | |
| 10 * Example: | |
| 11 * <cr-settings-radio-group pref="{{prefs.settings.foo}}" | |
| 12 * label="Foo Options." buttons="{{fooOptionsList}}"> | |
| 13 * </cr-settings-radio-group> | |
| 14 * | |
| 15 * @element cr-settings-radio-group | |
| 16 */ | |
| 17 Polymer({ | |
| 18 is: 'cr-settings-radio-group', | |
| 19 | |
| 20 properties: { | |
| 21 /** | |
| 22 * The preference object to control. | |
| 23 * @type {chrome.settingsPrivate.PrefObject|undefined} | |
| 24 */ | |
| 25 pref: { | |
| 26 type: Object, | |
| 27 notify: true, | |
| 28 observer: 'prefChanged_' | |
| 29 }, | |
| 30 | |
| 31 /** | |
| 32 * IronSelectableBehavior selected attribute | |
| 33 */ | |
| 34 selected: { | |
| 35 type: String, | |
| 36 observer: 'selectedChanged_' | |
| 37 }, | |
| 38 }, | |
| 39 | |
| 40 /** @private */ | |
| 41 prefChanged_: function() { | |
| 42 if (!this.pref) | |
| 43 return; | |
| 44 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER || | |
| 45 this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) { | |
| 46 this.selected = this.pref.value.toString(); | |
| 47 } else { | |
| 48 assert(this.pref.type != chrome.settingsPrivate.PrefType.LIST); | |
| 49 this.selected = /** @type {string} */(this.pref.value); | |
| 50 } | |
| 51 }, | |
| 52 | |
| 53 /** @private */ | |
| 54 selectedChanged_: function() { | |
| 55 if (!this.pref) | |
| 56 return; | |
| 57 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { | |
| 58 var n = parseInt(this.selected, 10); | |
| 59 if (isNaN(n)) { | |
| 60 console.error('Bad selected name for numerical pref: ' + this.selected); | |
| 61 return; | |
| 62 } | |
| 63 this.set('pref.value', n); | |
| 64 } else if (this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) { | |
| 65 this.set('pref.value', this.selected == 'true'); | |
| 66 } else { | |
| 67 assert(this.pref.type != chrome.settingsPrivate.PrefType.LIST); | |
| 68 this.set('pref.value', this.selected); | |
| 69 } | |
| 70 }, | |
| 71 }); | |
| OLD | NEW |