Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2149)

Unified Diff: chrome/browser/resources/settings/radio_group/radio_group.js

Issue 1347193003: Add cr-settings-radio-group wrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/radio_group/radio_group.js
diff --git a/chrome/browser/resources/settings/radio_group/radio_group.js b/chrome/browser/resources/settings/radio_group/radio_group.js
new file mode 100644
index 0000000000000000000000000000000000000000..0711680e3438c43491a1de7336e2d192adf0a010
--- /dev/null
+++ b/chrome/browser/resources/settings/radio_group/radio_group.js
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * `cr-radio-group` wraps a radio-group and set of radio-buttons that control
+ * a supplied preference.
+ *
+ * Example:
+ * <cr-settings-radio-group pref="{{prefs.settings.foo}}"
+ * label="Foo Options." buttons="{{fooOptionsList}}">
+ * </cr-settings-radio-group>
+ *
+ * @element cr-settings-radio-group
+ */
+Polymer({
+ is: 'cr-settings-radio-group',
+
+ properties: {
+ /**
+ * The preference object to control.
+ * @type {chrome.settingsPrivate.PrefObject|undefined}
+ */
+ pref: {
+ type: Object,
+ notify: true,
+ observer: 'prefChanged_'
+ },
+
+ /**
+ * IronSelectableBehavior selected attribute
+ */
+ selected: {
+ type: String,
+ observer: 'selectedChanged_'
+ },
+ },
+
+ /** @private */
+ prefChanged_: function() {
+ if (!this.pref)
+ return;
+ if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER ||
+ this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) {
+ this.selected = this.pref.value.toString();
+ } else {
+ assert(this.pref.type != chrome.settingsPrivate.PrefType.LIST);
+ this.selected = /** @type {string} */(this.pref.value);
+ }
+ },
+
+ /** @private */
+ selectedChanged_: function() {
+ if (!this.pref)
+ return;
+ if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
+ var n = parseInt(this.selected, 10);
+ if (isNaN(n)) {
+ console.error('Bad selected name for numerical pref: ' + this.selected);
Dan Beam 2015/09/16 22:29:37 why not just assert(!isNan(n))?
+ return;
+ }
+ this.set('pref.value', n);
+ } else if (this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) {
+ this.set('pref.value', this.selected == 'true');
+ } else {
+ assert(this.pref.type != chrome.settingsPrivate.PrefType.LIST);
+ this.set('pref.value', this.selected);
+ }
+ },
+});

Powered by Google App Engine
This is Rietveld 408576698