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