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 OptionsPage = options.OptionsPage; | 7 var OptionsPage = options.OptionsPage; |
8 var ArrayDataModel = cr.ui.ArrayDataModel; | 8 var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 // State variables. | 10 // State variables. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 }; | 50 }; |
51 $('customize-sync').onclick = function(event) { | 51 $('customize-sync').onclick = function(event) { |
52 SyncSetupOverlay.showSetupUI(); | 52 SyncSetupOverlay.showSetupUI(); |
53 }; | 53 }; |
54 | 54 |
55 // Profiles. | 55 // Profiles. |
56 var profilesList = $('profiles-list'); | 56 var profilesList = $('profiles-list'); |
57 options.personal_options.ProfileList.decorate(profilesList); | 57 options.personal_options.ProfileList.decorate(profilesList); |
58 profilesList.autoExpands = true; | 58 profilesList.autoExpands = true; |
59 | 59 |
60 profilesList.onchange = function(event) { | 60 profilesList.onchange = self.setProfileViewButtonsStatus_; |
61 var selectedProfile = profilesList.selectedItem; | |
62 var hasSelection = selectedProfile != null; | |
63 var hasSingleProfile = profilesList.dataModel.length == 1; | |
64 $('profiles-manage').disabled = !hasSelection || | |
65 !selectedProfile.isCurrentProfile; | |
66 $('profiles-delete').disabled = !hasSingleProfile && !hasSelection; | |
67 }; | |
68 $('profiles-create').onclick = function(event) { | 61 $('profiles-create').onclick = function(event) { |
69 chrome.send('createProfile'); | 62 chrome.send('createProfile'); |
70 }; | 63 }; |
71 $('profiles-manage').onclick = function(event) { | 64 $('profiles-manage').onclick = function(event) { |
72 var selectedProfile = self.getSelectedProfileItem_(); | 65 var selectedProfile = self.getSelectedProfileItem_(); |
73 if (selectedProfile) | 66 if (selectedProfile) |
74 ManageProfileOverlay.showManageDialog(selectedProfile); | 67 ManageProfileOverlay.showManageDialog(selectedProfile); |
75 }; | 68 }; |
76 $('profiles-delete').onclick = function(event) { | 69 $('profiles-delete').onclick = function(event) { |
77 var selectedProfile = self.getSelectedProfileItem_(); | 70 var selectedProfile = self.getSelectedProfileItem_(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (profilesList.hidden) { | 207 if (profilesList.hidden) { |
215 if (profilesList.dataModel.length > 0) | 208 if (profilesList.dataModel.length > 0) |
216 return profilesList.dataModel.item(0); | 209 return profilesList.dataModel.item(0); |
217 } else { | 210 } else { |
218 return profilesList.selectedItem; | 211 return profilesList.selectedItem; |
219 } | 212 } |
220 return null; | 213 return null; |
221 }, | 214 }, |
222 | 215 |
223 /** | 216 /** |
| 217 * Helper function to set the status of profile view buttons to disabled or |
| 218 * enabled, depending on the number of profiles and selection status of the |
| 219 * profiles list. |
| 220 */ |
| 221 setProfileViewButtonsStatus_: function() { |
| 222 var profilesList = $('profiles-list'); |
| 223 var selectedProfile = profilesList.selectedItem; |
| 224 var hasSelection = selectedProfile != null; |
| 225 var hasSingleProfile = profilesList.dataModel.length == 1; |
| 226 $('profiles-manage').disabled = !hasSelection; |
| 227 $('profiles-delete').disabled = !hasSelection || hasSingleProfile; |
| 228 }, |
| 229 |
| 230 /** |
224 * Display the correct dialog layout, depending on how many profiles are | 231 * Display the correct dialog layout, depending on how many profiles are |
225 * available. | 232 * available. |
226 * @param {number} numProfiles The number of profiles to display. | 233 * @param {number} numProfiles The number of profiles to display. |
227 */ | 234 */ |
228 setProfileViewSingle_: function(numProfiles) { | 235 setProfileViewSingle_: function(numProfiles) { |
229 var hasSingleProfile = numProfiles == 1; | 236 var hasSingleProfile = numProfiles == 1; |
230 $('profiles-list').hidden = hasSingleProfile; | 237 $('profiles-list').hidden = hasSingleProfile; |
231 $('profiles-single-message').hidden = !hasSingleProfile; | 238 $('profiles-single-message').hidden = !hasSingleProfile; |
232 $('profiles-manage').hidden = hasSingleProfile; | 239 $('profiles-manage').hidden = hasSingleProfile; |
233 $('profiles-delete').textContent = hasSingleProfile ? | 240 $('profiles-delete').textContent = hasSingleProfile ? |
(...skipping 10 matching lines...) Expand all Loading... |
244 * iconURL: "chrome://path/to/icon/image", | 251 * iconURL: "chrome://path/to/icon/image", |
245 * filePath: "/path/to/profile/data/on/disk", | 252 * filePath: "/path/to/profile/data/on/disk", |
246 * isCurrentProfile: false | 253 * isCurrentProfile: false |
247 * }; | 254 * }; |
248 */ | 255 */ |
249 setProfilesInfo_: function(profiles) { | 256 setProfilesInfo_: function(profiles) { |
250 this.setProfileViewSingle_(profiles.length); | 257 this.setProfileViewSingle_(profiles.length); |
251 // add it to the list, even if the list is hidden so we can access it | 258 // add it to the list, even if the list is hidden so we can access it |
252 // later. | 259 // later. |
253 $('profiles-list').dataModel = new ArrayDataModel(profiles); | 260 $('profiles-list').dataModel = new ArrayDataModel(profiles); |
| 261 this.setProfileViewButtonsStatus_(); |
254 }, | 262 }, |
255 | 263 |
256 setStartStopButtonVisible_: function(visible) { | 264 setStartStopButtonVisible_: function(visible) { |
257 $('start-stop-sync').hidden = !visible; | 265 $('start-stop-sync').hidden = !visible; |
258 }, | 266 }, |
259 | 267 |
260 setStartStopButtonEnabled_: function(enabled) { | 268 setStartStopButtonEnabled_: function(enabled) { |
261 $('start-stop-sync').disabled = !enabled; | 269 $('start-stop-sync').disabled = !enabled; |
262 }, | 270 }, |
263 | 271 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 PersonalOptions.getInstance()[name + '_'](value); | 348 PersonalOptions.getInstance()[name + '_'](value); |
341 }; | 349 }; |
342 }); | 350 }); |
343 | 351 |
344 // Export | 352 // Export |
345 return { | 353 return { |
346 PersonalOptions: PersonalOptions | 354 PersonalOptions: PersonalOptions |
347 }; | 355 }; |
348 | 356 |
349 }); | 357 }); |
OLD | NEW |