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 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 var ArrayDataModel = cr.ui.ArrayDataModel; | 7 var ArrayDataModel = cr.ui.ArrayDataModel; |
8 | 8 |
9 const localStrings = new LocalStrings(); | 9 const localStrings = new LocalStrings(); |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 /** | 36 /** |
37 * Initialize the page. | 37 * Initialize the page. |
38 */ | 38 */ |
39 initializePage: function() { | 39 initializePage: function() { |
40 // Call base class implementation to start preference initialization. | 40 // Call base class implementation to start preference initialization. |
41 OptionsPage.prototype.initializePage.call(this); | 41 OptionsPage.prototype.initializePage.call(this); |
42 | 42 |
43 var self = this; | 43 var self = this; |
44 var iconGrid = $('manage-profile-icon-grid'); | 44 var iconGrid = $('manage-profile-icon-grid'); |
45 options.ProfilesIconGrid.decorate(iconGrid); | 45 options.ProfilesIconGrid.decorate(iconGrid); |
| 46 iconGrid.addEventListener('change', function(e) { |
| 47 self.onIconGridSelectionChanged_(); |
| 48 }); |
46 | 49 |
47 $('manage-profile-name').oninput = this.onNameChanged_.bind(this); | 50 $('manage-profile-name').oninput = this.onNameChanged_.bind(this); |
48 $('manage-profile-cancel').onclick = | 51 $('manage-profile-cancel').onclick = |
49 $('delete-profile-cancel').onclick = function(event) { | 52 $('delete-profile-cancel').onclick = function(event) { |
50 OptionsPage.closeOverlay(); | 53 OptionsPage.closeOverlay(); |
51 }; | 54 }; |
52 $('manage-profile-ok').onclick = function(event) { | 55 $('manage-profile-ok').onclick = function(event) { |
53 OptionsPage.closeOverlay(); | 56 OptionsPage.closeOverlay(); |
54 self.submitManageChanges_(); | 57 self.submitManageChanges_(); |
55 }; | 58 }; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 * }; | 90 * }; |
88 * @private | 91 * @private |
89 */ | 92 */ |
90 setProfileInfo_: function(profileInfo) { | 93 setProfileInfo_: function(profileInfo) { |
91 this.profileInfo_ = profileInfo; | 94 this.profileInfo_ = profileInfo; |
92 $('manage-profile-name').value = profileInfo.name; | 95 $('manage-profile-name').value = profileInfo.name; |
93 $('manage-profile-icon-grid').selectedItem = profileInfo.iconURL; | 96 $('manage-profile-icon-grid').selectedItem = profileInfo.iconURL; |
94 }, | 97 }, |
95 | 98 |
96 /** | 99 /** |
| 100 * Sets the name of the currently edited profile. |
| 101 * @private |
| 102 */ |
| 103 setProfileName_: function(name) { |
| 104 if (this.profileInfo_) |
| 105 this.profileInfo_.name = name; |
| 106 $('manage-profile-name').value = name; |
| 107 }, |
| 108 |
| 109 /** |
97 * Set an array of default icon URLs. These will be added to the grid that | 110 * Set an array of default icon URLs. These will be added to the grid that |
98 * the user will use to choose their profile icon. | 111 * the user will use to choose their profile icon. |
99 * @param {Array.<string>} iconURLs An array of icon URLs. | 112 * @param {Array.<string>} iconURLs An array of icon URLs. |
100 * @private | 113 * @private |
101 */ | 114 */ |
102 receiveDefaultProfileIcons_: function(iconURLs) { | 115 receiveDefaultProfileIcons_: function(iconURLs) { |
103 $('manage-profile-icon-grid').dataModel = new ArrayDataModel(iconURLs); | 116 $('manage-profile-icon-grid').dataModel = new ArrayDataModel(iconURLs); |
104 | 117 |
105 // Changing the dataModel resets the selectedItem. Re-select it, if there | 118 // Changing the dataModel resets the selectedItem. Re-select it, if there |
106 // is one. | 119 // is one. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 * @private | 185 * @private |
173 */ | 186 */ |
174 submitManageChanges_: function() { | 187 submitManageChanges_: function() { |
175 var name = $('manage-profile-name').value; | 188 var name = $('manage-profile-name').value; |
176 var iconURL = $('manage-profile-icon-grid').selectedItem; | 189 var iconURL = $('manage-profile-icon-grid').selectedItem; |
177 chrome.send('setProfileNameAndIcon', | 190 chrome.send('setProfileNameAndIcon', |
178 [this.profileInfo_.filePath, name, iconURL]); | 191 [this.profileInfo_.filePath, name, iconURL]); |
179 }, | 192 }, |
180 | 193 |
181 /** | 194 /** |
| 195 * Called when the selected icon in the icon grid changes. |
| 196 * @private |
| 197 */ |
| 198 onIconGridSelectionChanged_: function() { |
| 199 var iconURL = $('manage-profile-icon-grid').selectedItem; |
| 200 chrome.send('profileIconSelectionChanged', |
| 201 [this.profileInfo_.filePath, iconURL]); |
| 202 }, |
| 203 |
| 204 /** |
182 * Display the "Manage Profile" dialog. | 205 * Display the "Manage Profile" dialog. |
183 * @param {Object} profileInfo The profile object of the profile to manage. | 206 * @param {Object} profileInfo The profile object of the profile to manage. |
184 * @private | 207 * @private |
185 */ | 208 */ |
186 showManageDialog_: function(profileInfo) { | 209 showManageDialog_: function(profileInfo) { |
187 ManageProfileOverlay.setProfileInfo(profileInfo); | 210 ManageProfileOverlay.setProfileInfo(profileInfo); |
188 $('manage-profile-overlay-manage').hidden = false; | 211 $('manage-profile-overlay-manage').hidden = false; |
189 $('manage-profile-overlay-delete').hidden = true; | 212 $('manage-profile-overlay-delete').hidden = true; |
190 ManageProfileOverlay.getInstance().hideErrorBubble_(); | 213 ManageProfileOverlay.getInstance().hideErrorBubble_(); |
191 | 214 |
(...skipping 18 matching lines...) Expand all Loading... |
210 // people trying to navigate here by hand. | 233 // people trying to navigate here by hand. |
211 OptionsPage.showPageByName('manageProfile', false); | 234 OptionsPage.showPageByName('manageProfile', false); |
212 }, | 235 }, |
213 }; | 236 }; |
214 | 237 |
215 // Forward public APIs to private implementations. | 238 // Forward public APIs to private implementations. |
216 [ | 239 [ |
217 'receiveDefaultProfileIcons', | 240 'receiveDefaultProfileIcons', |
218 'receiveProfileNames', | 241 'receiveProfileNames', |
219 'setProfileInfo', | 242 'setProfileInfo', |
| 243 'setProfileName', |
220 'showManageDialog', | 244 'showManageDialog', |
221 'showDeleteDialog', | 245 'showDeleteDialog', |
222 ].forEach(function(name) { | 246 ].forEach(function(name) { |
223 ManageProfileOverlay[name] = function(value) { | 247 ManageProfileOverlay[name] = function(value) { |
224 ManageProfileOverlay.getInstance()[name + '_'](value); | 248 ManageProfileOverlay.getInstance()[name + '_'](value); |
225 }; | 249 }; |
226 }); | 250 }); |
227 | 251 |
228 // Export | 252 // Export |
229 return { | 253 return { |
230 ManageProfileOverlay: ManageProfileOverlay | 254 ManageProfileOverlay: ManageProfileOverlay |
231 }; | 255 }; |
232 }); | 256 }); |
OLD | NEW |