| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(jhawkins): Add dialog-pref support to all preference controls. | 5 // TODO(jhawkins): Add dialog-pref support to all preference controls. |
| 6 | 6 |
| 7 cr.define('options', function() { | 7 cr.define('options', function() { |
| 8 | 8 |
| 9 var Preferences = options.Preferences; | 9 var Preferences = options.Preferences; |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 * @param {!Event} event The pref change event. | 48 * @param {!Event} event The pref change event. |
| 49 */ | 49 */ |
| 50 function updateElementState_(el, event) { | 50 function updateElementState_(el, event) { |
| 51 el.controlledBy = null; | 51 el.controlledBy = null; |
| 52 | 52 |
| 53 if (!event.value) | 53 if (!event.value) |
| 54 return; | 54 return; |
| 55 | 55 |
| 56 updateDisabledState_(el, 'notUserModifiable', event.value.disabled); | 56 updateDisabledState_(el, 'notUserModifiable', event.value.disabled); |
| 57 | 57 |
| 58 el.controlledBy = event.value['controlledBy']; | 58 el.controlledBy = event.value.controlledBy; |
| 59 | 59 |
| 60 OptionsPage.updateManagedBannerVisibility(); | 60 OptionsPage.updateManagedBannerVisibility(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 ///////////////////////////////////////////////////////////////////////////// | 63 ///////////////////////////////////////////////////////////////////////////// |
| 64 // PrefCheckbox class: | 64 // PrefCheckbox class: |
| 65 // TODO(jhawkins): Refactor all this copy-pasted code! | 65 // TODO(jhawkins): Refactor all this copy-pasted code! |
| 66 | 66 |
| 67 // Define a constructor that uses an input element as its underlying element. | 67 // Define a constructor that uses an input element as its underlying element. |
| 68 var PrefCheckbox = cr.ui.define('input'); | 68 var PrefCheckbox = cr.ui.define('input'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 * Initialization function for the cr.ui framework. | 81 * Initialization function for the cr.ui framework. |
| 82 */ | 82 */ |
| 83 decorate: function() { | 83 decorate: function() { |
| 84 this.type = 'checkbox'; | 84 this.type = 'checkbox'; |
| 85 var self = this; | 85 var self = this; |
| 86 | 86 |
| 87 self.initializeValueType(self.getAttribute('value-type')); | 87 self.initializeValueType(self.getAttribute('value-type')); |
| 88 | 88 |
| 89 // Listen to pref changes. | 89 // Listen to pref changes. |
| 90 Preferences.getInstance().addEventListener(this.pref, function(event) { | 90 Preferences.getInstance().addEventListener(this.pref, function(event) { |
| 91 var value = event.value && event.value['value'] != undefined ? | 91 self.prefValue_ = Boolean(event.value.value); |
| 92 event.value['value'] : event.value; | |
| 93 | |
| 94 self.prefValue_ = Boolean(value); | |
| 95 self.resetPrefState(); | 92 self.resetPrefState(); |
| 96 | 93 |
| 97 updateElementState_(self, event); | 94 updateElementState_(self, event); |
| 98 }); | 95 }); |
| 99 | 96 |
| 100 // Listen to user events. | 97 // Listen to user events. |
| 101 this.addEventListener('change', function(e) { | 98 this.addEventListener('change', function(e) { |
| 102 if (self.customChangeHandler(e)) | 99 if (self.customChangeHandler(e)) |
| 103 return; | 100 return; |
| 104 | 101 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 */ | 214 */ |
| 218 decorate: function() { | 215 decorate: function() { |
| 219 this.type = 'radio'; | 216 this.type = 'radio'; |
| 220 var self = this; | 217 var self = this; |
| 221 | 218 |
| 222 // Listen to preference changes. | 219 // Listen to preference changes. |
| 223 Preferences.getInstance().addEventListener(this.pref, | 220 Preferences.getInstance().addEventListener(this.pref, |
| 224 function(event) { | 221 function(event) { |
| 225 if (self.customChangeHandler(event)) | 222 if (self.customChangeHandler(event)) |
| 226 return; | 223 return; |
| 227 var value = event.value && event.value['value'] != undefined ? | 224 self.checked = String(event.value.value) == self.value; |
| 228 event.value['value'] : event.value; | |
| 229 self.checked = String(value) == self.value; | |
| 230 self.storedValue_ = self.checked; | 225 self.storedValue_ = self.checked; |
| 231 | 226 |
| 232 updateElementState_(self, event); | 227 updateElementState_(self, event); |
| 233 }); | 228 }); |
| 234 | 229 |
| 235 // Dialog preferences are not saved until savePrefState() is explicitly | 230 // Dialog preferences are not saved until savePrefState() is explicitly |
| 236 // called. | 231 // called. |
| 237 if (!this.dialogPref) | 232 if (!this.dialogPref) |
| 238 this.onchange = this.savePrefState.bind(this); | 233 this.onchange = this.savePrefState.bind(this); |
| 239 }, | 234 }, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 313 |
| 319 /** | 314 /** |
| 320 * Initialization function for the cr.ui framework. | 315 * Initialization function for the cr.ui framework. |
| 321 */ | 316 */ |
| 322 decorate: function() { | 317 decorate: function() { |
| 323 var self = this; | 318 var self = this; |
| 324 | 319 |
| 325 // Listen to pref changes. | 320 // Listen to pref changes. |
| 326 Preferences.getInstance().addEventListener(this.pref, | 321 Preferences.getInstance().addEventListener(this.pref, |
| 327 function(event) { | 322 function(event) { |
| 328 self.value = event.value && event.value['value'] != undefined ? | 323 self.value = event.value.value; |
| 329 event.value['value'] : event.value; | |
| 330 | 324 |
| 331 updateElementState_(self, event); | 325 updateElementState_(self, event); |
| 332 }); | 326 }); |
| 333 | 327 |
| 334 // Listen to user events. | 328 // Listen to user events. |
| 335 this.addEventListener('change', | 329 this.addEventListener('change', |
| 336 function(e) { | 330 function(e) { |
| 337 if (this.validity.valid) { | 331 if (this.validity.valid) { |
| 338 Preferences.setIntegerPref(self.pref, self.value, self.metric); | 332 Preferences.setIntegerPref(self.pref, self.value, self.metric); |
| 339 } | 333 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 this.onchange = this.onChange_.bind(this); | 434 this.onchange = this.onChange_.bind(this); |
| 441 this.onkeyup = this.onmouseup = this.onInputUp_.bind(this); | 435 this.onkeyup = this.onmouseup = this.onInputUp_.bind(this); |
| 442 }, | 436 }, |
| 443 | 437 |
| 444 /** | 438 /** |
| 445 * Event listener that updates the UI when the underlying pref changes. | 439 * Event listener that updates the UI when the underlying pref changes. |
| 446 * @param {Event} event The event that details the pref change. | 440 * @param {Event} event The event that details the pref change. |
| 447 * @private | 441 * @private |
| 448 */ | 442 */ |
| 449 onPrefChange_: function(event) { | 443 onPrefChange_: function(event) { |
| 450 var value = event.value && event.value['value'] != undefined ? | 444 var value = event.value.value; |
| 451 event.value['value'] : event.value; | |
| 452 if (value != undefined) | 445 if (value != undefined) |
| 453 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; | 446 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; |
| 454 }, | 447 }, |
| 455 | 448 |
| 456 /** | 449 /** |
| 457 * onchange handler that sets the pref when the user changes the value of | 450 * onchange handler that sets the pref when the user changes the value of |
| 458 * the input element. | 451 * the input element. |
| 459 * @private | 452 * @private |
| 460 */ | 453 */ |
| 461 onChange_: function(event) { | 454 onChange_: function(event) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 prefValue_: null, | 544 prefValue_: null, |
| 552 | 545 |
| 553 /** | 546 /** |
| 554 * Initialization function for the cr.ui framework. | 547 * Initialization function for the cr.ui framework. |
| 555 */ | 548 */ |
| 556 decorate: function() { | 549 decorate: function() { |
| 557 var self = this; | 550 var self = this; |
| 558 | 551 |
| 559 // Listen to pref changes. | 552 // Listen to pref changes. |
| 560 Preferences.getInstance().addEventListener(this.pref, function(event) { | 553 Preferences.getInstance().addEventListener(this.pref, function(event) { |
| 561 var value = event.value && event.value['value'] != undefined ? | |
| 562 event.value['value'] : event.value; | |
| 563 | |
| 564 // Make sure |value| is a string, because the value is stored as a | 554 // Make sure |value| is a string, because the value is stored as a |
| 565 // string in the HTMLOptionElement. | 555 // string in the HTMLOptionElement. |
| 566 value = value.toString(); | 556 value = event.value.value.toString(); |
| 567 | 557 |
| 568 updateElementState_(self, event); | 558 updateElementState_(self, event); |
| 569 self.prefValue_ = value; | 559 self.prefValue_ = value; |
| 570 self.resetPrefState(); | 560 self.resetPrefState(); |
| 571 }); | 561 }); |
| 572 | 562 |
| 573 // Listen to user events. | 563 // Listen to user events. |
| 574 this.addEventListener('change', function(event) { | 564 this.addEventListener('change', function(event) { |
| 575 if (!self.dialogPref) | 565 if (!self.dialogPref) |
| 576 self.updatePreference_(self.prefValue_); | 566 self.updatePreference_(self.prefValue_); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 | 711 |
| 722 /** | 712 /** |
| 723 * Initialization function for the cr.ui framework. | 713 * Initialization function for the cr.ui framework. |
| 724 */ | 714 */ |
| 725 decorate: function() { | 715 decorate: function() { |
| 726 var self = this; | 716 var self = this; |
| 727 | 717 |
| 728 // Listen to pref changes. | 718 // Listen to pref changes. |
| 729 Preferences.getInstance().addEventListener(this.pref, | 719 Preferences.getInstance().addEventListener(this.pref, |
| 730 function(event) { | 720 function(event) { |
| 731 self.value = event.value && event.value['value'] != undefined ? | 721 self.value = event.value.value; |
| 732 event.value['value'] : event.value; | |
| 733 | 722 |
| 734 updateElementState_(self, event); | 723 updateElementState_(self, event); |
| 735 | 724 |
| 736 self.prefValue_ = self.value; | 725 self.prefValue_ = self.value; |
| 737 }); | 726 }); |
| 738 | 727 |
| 739 // Listen to user events. | 728 // Listen to user events. |
| 740 if (!this.dialogPref) | 729 if (!this.dialogPref) |
| 741 this.addEventListener('change', this.savePrefState.bind(this)); | 730 this.addEventListener('change', this.savePrefState.bind(this)); |
| 742 | 731 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 795 |
| 807 // Listen to pref changes. This element behaves like a normal button and | 796 // Listen to pref changes. This element behaves like a normal button and |
| 808 // doesn't affect the underlying preference; it just becomes disabled | 797 // doesn't affect the underlying preference; it just becomes disabled |
| 809 // when the preference is managed, and its value is false. | 798 // when the preference is managed, and its value is false. |
| 810 // This is useful for buttons that should be disabled when the underlying | 799 // This is useful for buttons that should be disabled when the underlying |
| 811 // boolean preference is set to false by a policy or extension. | 800 // boolean preference is set to false by a policy or extension. |
| 812 Preferences.getInstance().addEventListener(this.pref, | 801 Preferences.getInstance().addEventListener(this.pref, |
| 813 function(event) { | 802 function(event) { |
| 814 var e = { | 803 var e = { |
| 815 value: { | 804 value: { |
| 816 'disabled': event.value['disabled'] && !event.value['value'], | 805 'disabled': event.value.disabled && !event.value.value, |
| 817 'controlledBy': event.value['controlledBy'] | 806 'controlledBy': event.value.controlledBy |
| 818 } | 807 } |
| 819 }; | 808 }; |
| 820 updateElementState_(self, e); | 809 updateElementState_(self, e); |
| 821 }); | 810 }); |
| 822 }, | 811 }, |
| 823 | 812 |
| 824 /** | 813 /** |
| 825 * See |updateDisabledState_| above. | 814 * See |updateDisabledState_| above. |
| 826 */ | 815 */ |
| 827 setDisabled: function(reason, disabled) { | 816 setDisabled: function(reason, disabled) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 848 PrefNumber: PrefNumber, | 837 PrefNumber: PrefNumber, |
| 849 PrefNumeric: PrefNumeric, | 838 PrefNumeric: PrefNumeric, |
| 850 PrefRadio: PrefRadio, | 839 PrefRadio: PrefRadio, |
| 851 PrefRange: PrefRange, | 840 PrefRange: PrefRange, |
| 852 PrefSelect: PrefSelect, | 841 PrefSelect: PrefSelect, |
| 853 PrefTextField: PrefTextField, | 842 PrefTextField: PrefTextField, |
| 854 PrefButton: PrefButton | 843 PrefButton: PrefButton |
| 855 }; | 844 }; |
| 856 | 845 |
| 857 }); | 846 }); |
| OLD | NEW |