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 * This tuple is made up of a (value, name, attribute). The value and name are | 6 * The |name| is shown in the gui. The |value| us use to set or compare with |
7 * used by the dropdown menu. The attribute is optional 'user data' that is | 7 * the preference value. |
8 * ignored by the dropdown menu. | |
9 * @typedef {{ | 8 * @typedef {{ |
10 * 0: (number|string), | 9 * name: string, |
11 * 1: string, | 10 * value: (number|string) |
12 * 2: (string|undefined) | |
13 * }} | 11 * }} |
14 */ | 12 */ |
15 var DropdownMenuOption; | 13 var DropdownMenuOption; |
16 | 14 |
17 /** | 15 /** |
18 * @typedef {!Array<!DropdownMenuOption>} | 16 * @typedef {!Array<!DropdownMenuOption>} |
19 */ | 17 */ |
20 var DropdownMenuOptionList; | 18 var DropdownMenuOptionList; |
21 | 19 |
22 /** | 20 /** |
(...skipping 10 matching lines...) Expand all Loading... |
33 */ | 31 */ |
34 Polymer({ | 32 Polymer({ |
35 is: 'settings-dropdown-menu', | 33 is: 'settings-dropdown-menu', |
36 | 34 |
37 properties: { | 35 properties: { |
38 /** A text label for the drop-down menu. */ | 36 /** A text label for the drop-down menu. */ |
39 label: String, | 37 label: String, |
40 | 38 |
41 /** | 39 /** |
42 * List of options for the drop-down menu. | 40 * List of options for the drop-down menu. |
43 * TODO(michaelpg): use named properties instead of indices. | |
44 * @type {DropdownMenuOptionList} | 41 * @type {DropdownMenuOptionList} |
45 */ | 42 */ |
46 menuOptions: { | 43 menuOptions: { |
47 type: Array, | 44 type: Array, |
48 value: function() { return []; }, | 45 value: function() { return []; }, |
49 }, | 46 }, |
50 | 47 |
51 /** | 48 /** |
52 * A single Preference object being tracked. | 49 * A single Preference object being tracked. |
53 * @type {!chrome.settingsPrivate.PrefObject|undefined} | 50 * @type {!chrome.settingsPrivate.PrefObject|undefined} |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 129 |
133 /** | 130 /** |
134 * Updates the selected item when the pref or menuOptions change. | 131 * Updates the selected item when the pref or menuOptions change. |
135 * @private | 132 * @private |
136 */ | 133 */ |
137 updateSelected_: function() { | 134 updateSelected_: function() { |
138 if (!this.pref) | 135 if (!this.pref) |
139 return; | 136 return; |
140 var prefValue = this.pref.value; | 137 var prefValue = this.pref.value; |
141 var option = this.menuOptions.find(function(menuItem) { | 138 var option = this.menuOptions.find(function(menuItem) { |
142 return menuItem[0] == prefValue; | 139 return menuItem.value == prefValue; |
143 }); | 140 }); |
144 if (option == undefined) | 141 if (option == undefined) |
145 this.selected_ = this.notFoundValue_; | 142 this.selected_ = this.notFoundValue_; |
146 else | 143 else |
147 this.selected_ = Settings.PrefUtil.prefToString(this.pref); | 144 this.selected_ = Settings.PrefUtil.prefToString(this.pref); |
148 }, | 145 }, |
149 | 146 |
150 /** | 147 /** |
151 * @param {string} selected | 148 * @param {string} selected |
152 * @return {boolean} | 149 * @return {boolean} |
153 * @private | 150 * @private |
154 */ | 151 */ |
155 isSelectedNotFound_: function(selected) { | 152 isSelectedNotFound_: function(selected) { |
156 return this.menuOptions && selected == this.notFoundValue_; | 153 return this.menuOptions && selected == this.notFoundValue_; |
157 }, | 154 }, |
158 | 155 |
159 /** | 156 /** |
160 * @return {boolean} | 157 * @return {boolean} |
161 * @private | 158 * @private |
162 */ | 159 */ |
163 shouldDisableMenu_: function() { | 160 shouldDisableMenu_: function() { |
164 return this.disabled || !this.menuOptions.length; | 161 return this.disabled || !this.menuOptions.length; |
165 }, | 162 }, |
166 }); | 163 }); |
OLD | NEW |