Chromium Code Reviews| Index: chrome/browser/resources/settings/input/input.js | 
| diff --git a/chrome/browser/resources/settings/input/input.js b/chrome/browser/resources/settings/input/input.js | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..9846b1ae72b76d84f7fa1673e72c4b6902dc9723 | 
| --- /dev/null | 
| +++ b/chrome/browser/resources/settings/input/input.js | 
| @@ -0,0 +1,132 @@ | 
| +// 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-settings-input` is a single-line text field for user input associated | 
| + * with a pref value. | 
| + * | 
| + * @element cr-settings-input | 
| + */ | 
| +Polymer({ | 
| + is: 'cr-settings-input', | 
| + | 
| + behaviors: [PolicyControllable], | 
| + | 
| + properties: { | 
| + /** | 
| + * The preference object to control. | 
| + * @type {chrome.settingsPrivate.PrefObject|undefined} | 
| + */ | 
| + pref: { | 
| + type: Object, | 
| + notify: true, | 
| + observer: 'prefChanged_' | 
| + }, | 
| + | 
| + /** | 
| + * The current value of the input, reflected to/from |pref|. | 
| + */ | 
| + value: { | 
| + type: String, | 
| + value: '', | 
| + notify: true, | 
| + }, | 
| + | 
| + /** | 
| + * Set to true to disable editing the input. | 
| + */ | 
| + disabled: { | 
| + type: Boolean, | 
| + value: false, | 
| + reflectToAttribute: true | 
| + }, | 
| + | 
| + /** Propagate the label property. */ | 
| + label: { type: String }, | 
| + | 
| + /** Propagate the no-label-float property. */ | 
| + noLabelFloat: { type: Boolean, value: false }, | 
| + | 
| + /** Propagate the required property. */ | 
| + required: { type: Boolean, value: false }, | 
| + | 
| + /** Propagate the pattern property. */ | 
| + pattern: { type: String }, | 
| + | 
| + /** Propagate the type property. */ | 
| + type: { type: String }, | 
| + | 
| + /** Propagate the errorMessage property. */ | 
| + errorMessage: { type: String }, | 
| + }, | 
| + | 
| + /** @override */ | 
| + ready: function() { | 
| + this.$.events.forward(this.$.input, ['change']); | 
| + }, | 
| + | 
| + /** | 
| + * Focuses the 'input' element. | 
| + */ | 
| + focus: function() { | 
| + this.$.input.inputElement.focus(); | 
| + }, | 
| + | 
| + /** | 
| + * Polymer changed observer for |pref|. | 
| + * @private | 
| + */ | 
| + prefChanged_: function() { | 
| + if (!this.pref) | 
| + return; | 
| + | 
| + // Ignore updates while the input is focused so that user input is not | 
| + // overwritten. | 
| + if (this.$.input.focused) | 
| + return; | 
| + | 
| + if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { | 
| + this.value = this.pref.value.toString(); | 
| + } else { | 
| + assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || | 
| + this.pref.type == chrome.settingsPrivate.PrefType.URL); | 
| + this.value = /** @type {string} */(this.pref.value); | 
| + } | 
| + }, | 
| + | 
| + /** | 
| + * Blur method for paper-input. Only update the pref value on a blur event. | 
| + * @private | 
| + */ | 
| + onBlur_: function() { | 
| + if (!this.pref) | 
| + return; | 
| + | 
| + if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { | 
| + if (!this.value) | 
| + return; // Ignore empty input field | 
| 
 
dschuyler
2015/09/24 20:39:05
Maybe set this.value to pref.value if value is emp
 
stevenjb
2015/09/24 21:22:15
Eventually we should do proper validation, but yea
 
 | 
| + var n = parseInt(this.value, 10); | 
| + if (isNaN(n)) { | 
| + console.error('Bad value for numerical pref: ' + this.value); | 
| + return; | 
| + } | 
| + this.set('pref.value', n); | 
| + } else { | 
| + assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || | 
| + this.pref.type == chrome.settingsPrivate.PrefType.URL); | 
| + this.set('pref.value', this.value); | 
| + } | 
| + }, | 
| + | 
| + /** | 
| + * @param {boolean} disabled | 
| + * @param {?chrome.settingsPrivate.PrefObject} pref | 
| + * @return {boolean} Whether the element should be disabled. | 
| + * @private | 
| + */ | 
| + isDisabled_: function(disabled, pref) { | 
| + return disabled || this.isPolicyControlled(pref); | 
| + }, | 
| +}); |