Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 | 6 |
| 7 var Preferences = options.Preferences; | 7 var Preferences = options.Preferences; |
| 8 ///////////////////////////////////////////////////////////////////////////// | 8 ///////////////////////////////////////////////////////////////////////////// |
| 9 // PrefCheckbox class: | 9 // PrefCheckbox class: |
| 10 // TODO(jhawkins): Refactor all this copy-pasted code! | 10 // TODO(jhawkins): Refactor all this copy-pasted code! |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 Preferences.setBooleanPref(self.pref, | 133 Preferences.setBooleanPref(self.pref, |
| 134 self.value == 'true', self.metric); | 134 self.value == 'true', self.metric); |
| 135 } else { | 135 } else { |
| 136 Preferences.setIntegerPref(self.pref, | 136 Preferences.setIntegerPref(self.pref, |
| 137 parseInt(self.value, 10), self.metric); | 137 parseInt(self.value, 10), self.metric); |
| 138 } | 138 } |
| 139 }); | 139 }); |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Getter for preference name attribute. | 143 * The name of the preference. |
| 144 * @type {string} | |
| 144 */ | 145 */ |
| 145 get pref() { | 146 get pref() { |
| 146 return this.getAttribute('pref'); | 147 return this.getAttribute('pref'); |
| 147 }, | 148 }, |
| 148 | |
| 149 /** | |
| 150 * Setter for preference name attribute. | |
| 151 */ | |
| 152 set pref(name) { | 149 set pref(name) { |
| 153 this.setAttribute('pref', name); | 150 this.setAttribute('pref', name); |
| 154 } | 151 } |
| 155 }; | 152 }; |
| 156 | 153 |
| 157 /** | 154 /** |
| 158 * The user metric string. | 155 * The user metric string. |
| 159 * @type {string} | 156 * @type {string} |
| 160 */ | 157 */ |
| 161 cr.defineProperty(PrefRadio, 'metric', cr.PropertyKind.ATTR); | 158 cr.defineProperty(PrefRadio, 'metric', cr.PropertyKind.ATTR); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 if (!found) | 398 if (!found) |
| 402 self.selectedIndex = 0; | 399 self.selectedIndex = 0; |
| 403 | 400 |
| 404 if (self.onchange != undefined) | 401 if (self.onchange != undefined) |
| 405 self.onchange(event); | 402 self.onchange(event); |
| 406 }); | 403 }); |
| 407 | 404 |
| 408 // Listen to user events. | 405 // Listen to user events. |
| 409 this.addEventListener('change', | 406 this.addEventListener('change', |
| 410 function(e) { | 407 function(e) { |
| 411 if (!self.dataType) | 408 if (!self.dataType) { |
| 412 console.error('unknown data type for <select> pref'); | 409 console.error('undefined data type for <select> pref'); |
| 410 return; | |
| 411 } | |
| 413 | 412 |
| 414 switch(self.dataType) { | 413 switch(self.dataType) { |
| 415 case 'number': | 414 case 'number': |
| 416 Preferences.setIntegerPref(self.pref, | 415 Preferences.setIntegerPref(self.pref, |
| 417 self.options[self.selectedIndex].value, self.metric); | 416 self.options[self.selectedIndex].value, self.metric); |
| 418 break; | 417 break; |
| 418 case 'real': | |
| 419 Preferences.setRealPref(self.pref, | |
| 420 self.options[self.selectedIndex].value, self.metric); | |
| 421 break; | |
| 419 case 'boolean': | 422 case 'boolean': |
| 420 var option = self.options[self.selectedIndex]; | 423 var option = self.options[self.selectedIndex]; |
| 421 var value = (option.value == 'true') ? true : false; | 424 var value = (option.value == 'true') ? true : false; |
| 422 Preferences.setBooleanPref(self.pref, value, self.metric); | 425 Preferences.setBooleanPref(self.pref, value, self.metric); |
| 423 break; | 426 break; |
| 424 case 'string': | 427 case 'string': |
| 425 case undefined: // Assume the pref is a string. | |
| 426 Preferences.setStringPref(self.pref, | 428 Preferences.setStringPref(self.pref, |
| 427 self.options[self.selectedIndex].value, self.metric); | 429 self.options[self.selectedIndex].value, self.metric); |
| 428 break; | 430 break; |
| 431 default: | |
| 432 console.error('unknown data type for <select> pref: ' + | |
| 433 self.dataType); | |
| 429 } | 434 } |
| 430 }); | 435 }); |
| 431 }, | 436 }, |
| 437 | |
| 438 /** | |
| 439 * The data type for the preference options. | |
| 440 * @type {string} | |
| 441 */ | |
| 442 get dataType() { | |
|
arv (Not doing code reviews)
2011/01/13 20:51:10
There is a macro for this.
cr.defineProperty(Pref
| |
| 443 return this.getAttribute('dataType'); | |
| 444 }, | |
| 445 set dataType(name) { | |
| 446 this.setAttribute('dataType', name); | |
| 447 } | |
| 432 }; | 448 }; |
| 433 | 449 |
| 434 /** | 450 /** |
| 435 * The preference name. | 451 * The preference name. |
| 436 * @type {string} | 452 * @type {string} |
| 437 */ | 453 */ |
| 438 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); | 454 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); |
| 439 | 455 |
| 440 /** | 456 /** |
| 441 * The user metric string. | 457 * The user metric string. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 PrefCheckbox: PrefCheckbox, | 521 PrefCheckbox: PrefCheckbox, |
| 506 PrefNumber: PrefNumber, | 522 PrefNumber: PrefNumber, |
| 507 PrefNumeric: PrefNumeric, | 523 PrefNumeric: PrefNumeric, |
| 508 PrefRadio: PrefRadio, | 524 PrefRadio: PrefRadio, |
| 509 PrefRange: PrefRange, | 525 PrefRange: PrefRange, |
| 510 PrefSelect: PrefSelect, | 526 PrefSelect: PrefSelect, |
| 511 PrefTextField: PrefTextField | 527 PrefTextField: PrefTextField |
| 512 }; | 528 }; |
| 513 | 529 |
| 514 }); | 530 }); |
| OLD | NEW |