OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
6 * The |name| is shown in the gui. The |value| us use to set or compare with | 6 * The |name| is shown in the gui. The |value| us use to set or compare with |
7 * the preference value. | 7 * the preference value. |
8 * @typedef {{ | 8 * @typedef {{ |
9 * name: string, | 9 * name: string, |
10 * value: (number|string) | 10 * value: (number|string) |
(...skipping 11 matching lines...) Expand all Loading... |
22 * in the settings. | 22 * in the settings. |
23 * | 23 * |
24 * Example: | 24 * Example: |
25 * | 25 * |
26 * <settings-dropdown-menu pref="{{prefs.foo}}"> | 26 * <settings-dropdown-menu pref="{{prefs.foo}}"> |
27 * </settings-dropdown-menu> | 27 * </settings-dropdown-menu> |
28 */ | 28 */ |
29 Polymer({ | 29 Polymer({ |
30 is: 'settings-dropdown-menu', | 30 is: 'settings-dropdown-menu', |
31 | 31 |
| 32 behaviors: [CrPolicyPrefBehavior, PrefControlBehavior], |
| 33 |
32 properties: { | 34 properties: { |
33 /** | 35 /** |
34 * List of options for the drop-down menu. | 36 * List of options for the drop-down menu. |
35 * @type {?DropdownMenuOptionList} | 37 * @type {?DropdownMenuOptionList} |
36 */ | 38 */ |
37 menuOptions: { | 39 menuOptions: { |
38 type: Array, | 40 type: Array, |
39 value: null, | 41 value: null, |
40 }, | 42 }, |
41 | 43 |
42 /** Whether the dropdown menu should be disabled. */ | 44 /** Whether the dropdown menu should be disabled. */ |
43 disabled: { | 45 disabled: { |
44 type: Boolean, | 46 type: Boolean, |
45 reflectToAttribute: true, | 47 reflectToAttribute: true, |
46 value: false, | 48 value: false, |
47 }, | 49 }, |
48 | 50 |
49 /** | 51 /** |
50 * The value of the "custom" item. | 52 * The value of the "custom" item. |
51 * @private | 53 * @private |
52 */ | 54 */ |
53 notFoundValue_: { | 55 notFoundValue_: { |
54 type: String, | 56 type: String, |
55 value: 'SETTINGS_DROPDOWN_NOT_FOUND_ITEM', | 57 value: 'SETTINGS_DROPDOWN_NOT_FOUND_ITEM', |
56 readOnly: true, | 58 readOnly: true, |
57 }, | 59 }, |
58 }, | 60 }, |
59 | 61 |
60 behaviors: [ | |
61 PrefControlBehavior, | |
62 ], | |
63 | |
64 observers: [ | 62 observers: [ |
65 'updateSelected_(menuOptions, pref.value)', | 63 'updateSelected_(menuOptions, pref.value)', |
66 ], | 64 ], |
67 | 65 |
68 /** | 66 /** |
69 * Pass the selection change to the pref value. | 67 * Pass the selection change to the pref value. |
70 * @private | 68 * @private |
71 */ | 69 */ |
72 onChange_: function() { | 70 onChange_: function() { |
73 var selected = this.$.dropdownMenu.value; | 71 var selected = this.$.dropdownMenu.value; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return menuItem.value == prefValue; | 116 return menuItem.value == prefValue; |
119 }); | 117 }); |
120 return !option; | 118 return !option; |
121 }, | 119 }, |
122 | 120 |
123 /** | 121 /** |
124 * @return {boolean} | 122 * @return {boolean} |
125 * @private | 123 * @private |
126 */ | 124 */ |
127 shouldDisableMenu_: function() { | 125 shouldDisableMenu_: function() { |
128 return this.disabled || this.menuOptions === null || | 126 return this.disabled || this.isPrefEnforced() || |
129 this.menuOptions.length == 0; | 127 this.menuOptions === null || this.menuOptions.length == 0; |
130 }, | 128 }, |
131 }); | 129 }); |
OLD | NEW |