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 /** | 9 /** |
10 * Helper function update element's state from pref change event. | 10 * Helper function update element's state from pref change event. |
11 * @private | 11 * @private |
12 * @param {!HTMLElement} el The element to update. | 12 * @param {!HTMLElement} el The element to update. |
13 * @param {!Event} event The pref change event. | 13 * @param {!Event} event The pref change event. |
14 */ | 14 */ |
15 function updateElementState_(el, event) { | 15 function updateElementState_(el, event) { |
16 el.managed = event.value && event.value['managed'] != undefined ? | 16 el.managed = false; |
17 event.value['managed'] : false; | |
18 | 17 |
19 // Managed UI elements can only be disabled as a result of being | 18 if (!event.value) |
20 // managed. They cannot be enabled as a result of a pref being | 19 return; |
21 // unmanaged. | |
22 if (el.managed) | |
23 el.disabled = true; | |
24 | 20 |
25 // Disable UI elements if backend says so. | 21 el.managed = event.value['managed']; |
26 if (!el.disabled && event.value && event.value['disabled']) | 22 |
27 el.disabled = true; | 23 // If the value is controlled by an extension, set an explanatory title |
24 // attribute on the nearest containing <label> element. | |
25 var label = findAncestor(el, function(node) { | |
26 return (node instanceof HTMLLabelElement); | |
27 }); | |
28 if (label) { | |
29 label.title = event.value['extensionControlled'] ? | |
30 templateData.extensionManagedPrefsTitle : | |
31 null; | |
Evan Stade
2011/07/07 20:06:45
this will overwrite whatever other title the label
Bernhard Bauer
2011/07/07 20:45:14
Per the UI leads, we're going to add an infobar li
| |
32 } | |
33 | |
34 // Disable UI elements if the backend says so. | |
35 // |reenable| is a flag that tells us if the element is disabled because the | |
36 // preference is not modifiable by the user. If the element is disabled but | |
37 // the flag is not set, it means that the element has been disabled | |
38 // somewhere else, so we don't do anything. | |
39 if (el.disabled && !el.reenable) | |
40 return; | |
41 | |
42 el.disabled = event.value['disabled']; | |
Evan Stade
2011/07/07 20:06:45
this still doesn't seem very foolproof. reenable c
Bernhard Bauer
2011/07/07 20:45:14
I know :-/ This seemed like the easiest way withou
Evan Stade
2011/07/07 21:09:16
but how could the code check if it were disabled f
| |
43 el.reenable = event.value['disabled']; | |
28 } | 44 } |
29 | 45 |
30 ///////////////////////////////////////////////////////////////////////////// | 46 ///////////////////////////////////////////////////////////////////////////// |
31 // PrefCheckbox class: | 47 // PrefCheckbox class: |
32 // TODO(jhawkins): Refactor all this copy-pasted code! | 48 // TODO(jhawkins): Refactor all this copy-pasted code! |
33 | 49 |
34 // Define a constructor that uses an input element as its underlying element. | 50 // Define a constructor that uses an input element as its underlying element. |
35 var PrefCheckbox = cr.ui.define('input'); | 51 var PrefCheckbox = cr.ui.define('input'); |
36 | 52 |
37 PrefCheckbox.prototype = { | 53 PrefCheckbox.prototype = { |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 PrefCheckbox: PrefCheckbox, | 537 PrefCheckbox: PrefCheckbox, |
522 PrefNumber: PrefNumber, | 538 PrefNumber: PrefNumber, |
523 PrefNumeric: PrefNumeric, | 539 PrefNumeric: PrefNumeric, |
524 PrefRadio: PrefRadio, | 540 PrefRadio: PrefRadio, |
525 PrefRange: PrefRange, | 541 PrefRange: PrefRange, |
526 PrefSelect: PrefSelect, | 542 PrefSelect: PrefSelect, |
527 PrefTextField: PrefTextField | 543 PrefTextField: PrefTextField |
528 }; | 544 }; |
529 | 545 |
530 }); | 546 }); |
OLD | NEW |