Chromium Code Reviews| 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 | 9 |
| 9 // State variables. | 10 // State variables. |
| 10 var syncEnabled = false; | 11 var syncEnabled = false; |
| 11 var syncSetupCompleted = false; | 12 var syncSetupCompleted = false; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Encapsulated handling of personal options page. | 15 * Encapsulated handling of personal options page. |
| 15 * @constructor | 16 * @constructor |
| 16 */ | 17 */ |
| 17 function PersonalOptions() { | 18 function PersonalOptions() { |
| 18 OptionsPage.call(this, 'personal', | 19 OptionsPage.call(this, 'personal', |
| 19 templateData.personalPageTabTitle, | 20 templateData.personalPageTabTitle, |
| 20 'personal-page'); | 21 'personal-page'); |
| 21 } | 22 } |
| 22 | 23 |
| 23 cr.addSingletonGetter(PersonalOptions); | 24 cr.addSingletonGetter(PersonalOptions); |
| 24 | 25 |
| 25 PersonalOptions.prototype = { | 26 PersonalOptions.prototype = { |
| 26 // Inherit PersonalOptions from OptionsPage. | 27 // Inherit PersonalOptions from OptionsPage. |
| 27 __proto__: options.OptionsPage.prototype, | 28 __proto__: options.OptionsPage.prototype, |
| 28 | 29 |
| 29 // Initialize PersonalOptions page. | 30 // Initialize PersonalOptions page. |
| 30 initializePage: function() { | 31 initializePage: function() { |
| 31 // Call base class implementation to start preference initialization. | 32 // Call base class implementation to start preference initialization. |
| 32 OptionsPage.prototype.initializePage.call(this); | 33 OptionsPage.prototype.initializePage.call(this); |
| 33 | 34 |
| 34 var self = this; | 35 var self = this; |
| 36 | |
| 37 // sync | |
|
James Hawkins
2011/07/19 20:22:09
Sync.
Capitalize comment sentences (or word) and
| |
| 35 $('sync-action-link').onclick = function(event) { | 38 $('sync-action-link').onclick = function(event) { |
| 36 SyncSetupOverlay.showErrorUI(); | 39 SyncSetupOverlay.showErrorUI(); |
| 37 }; | 40 }; |
| 38 $('start-stop-sync').onclick = function(event) { | 41 $('start-stop-sync').onclick = function(event) { |
| 39 if (self.syncSetupCompleted) | 42 if (self.syncSetupCompleted) |
| 40 SyncSetupOverlay.showStopSyncingUI(); | 43 SyncSetupOverlay.showStopSyncingUI(); |
| 41 else | 44 else |
| 42 SyncSetupOverlay.showSetupUI(); | 45 SyncSetupOverlay.showSetupUI(); |
| 43 }; | 46 }; |
| 44 $('customize-sync').onclick = function(event) { | 47 $('customize-sync').onclick = function(event) { |
| 45 SyncSetupOverlay.showSetupUI(); | 48 SyncSetupOverlay.showSetupUI(); |
| 46 }; | 49 }; |
| 50 | |
| 51 // profiles | |
| 52 var profilesList = $('profiles-list'); | |
| 53 options.personal_options.ProfileList.decorate(profilesList); | |
| 54 profilesList.autoExpands = true; | |
| 55 | |
| 56 profilesList.addEventListener('change', function(event) { | |
|
James Hawkins
2011/07/19 20:22:09
onchange = function(...
| |
| 57 var selectedProfile = profilesList.selectedItem; | |
| 58 var hasSelection = selectedProfile != null; | |
| 59 $('profiles-manage').disabled = !hasSelection; | |
| 60 $('profiles-delete').disabled = !hasSelection; | |
| 61 }); | |
| 62 $('profiles-create').onclick = function(event) { | |
| 63 chrome.send('profilesCreate'); | |
| 64 }; | |
| 65 $('profiles-manage').onclick = function(event) { | |
| 66 var selectedProfile = self.getSelectedProfileItem_(); | |
| 67 if (selectedProfile) { | |
| 68 ProfilesManageOverlay.show(selectedProfile); | |
| 69 } | |
| 70 }; | |
| 71 $('profiles-delete').onclick = function(event) { | |
| 72 var selectedProfile = self.getSelectedProfileItem_(); | |
| 73 if (!selectedProfile) | |
| 74 return; | |
| 75 | |
| 76 ProfilesManageOverlay.showDeleteDialog(selectedProfile); | |
| 77 chrome.send('profilesDeleteShowWarnings', selectedProfile.filePath); | |
| 78 }; | |
| 79 | |
| 80 // passwords | |
| 47 $('manage-passwords').onclick = function(event) { | 81 $('manage-passwords').onclick = function(event) { |
| 48 OptionsPage.navigateToPage('passwords'); | 82 OptionsPage.navigateToPage('passwords'); |
| 49 OptionsPage.showTab($('passwords-nav-tab')); | 83 OptionsPage.showTab($('passwords-nav-tab')); |
| 50 chrome.send('coreOptionsUserMetricsAction', | 84 chrome.send('coreOptionsUserMetricsAction', |
| 51 ['Options_ShowPasswordManager']); | 85 ['Options_ShowPasswordManager']); |
| 52 }; | 86 }; |
| 87 | |
| 88 // autofill | |
| 53 $('autofill-settings').onclick = function(event) { | 89 $('autofill-settings').onclick = function(event) { |
| 54 OptionsPage.navigateToPage('autofill'); | 90 OptionsPage.navigateToPage('autofill'); |
| 55 chrome.send('coreOptionsUserMetricsAction', | 91 chrome.send('coreOptionsUserMetricsAction', |
| 56 ['Options_ShowAutofillSettings']); | 92 ['Options_ShowAutofillSettings']); |
| 57 }; | 93 }; |
| 94 | |
| 95 // appearance | |
| 58 $('themes-reset').onclick = function(event) { | 96 $('themes-reset').onclick = function(event) { |
| 59 chrome.send('themesReset'); | 97 chrome.send('themesReset'); |
| 60 }; | 98 }; |
| 61 | 99 |
| 62 if (!cr.isChromeOS) { | 100 if (!cr.isChromeOS) { |
| 63 $('import-data').onclick = function(event) { | 101 $('import-data').onclick = function(event) { |
| 64 // Make sure that any previous import success message is hidden, and | 102 // Make sure that any previous import success message is hidden, and |
| 65 // we're showing the UI to import further data. | 103 // we're showing the UI to import further data. |
| 66 $('import-data-configure').hidden = false; | 104 $('import-data-configure').hidden = false; |
| 67 $('import-data-success').hidden = true; | 105 $('import-data-success').hidden = true; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 }, | 204 }, |
| 167 | 205 |
| 168 setSyncActionLinkLabel_: function(status) { | 206 setSyncActionLinkLabel_: function(status) { |
| 169 $('sync-action-link').textContent = status; | 207 $('sync-action-link').textContent = status; |
| 170 | 208 |
| 171 // link-button does is not zero-area when the contents of the button are | 209 // link-button does is not zero-area when the contents of the button are |
| 172 // empty, so explicitly hide the element. | 210 // empty, so explicitly hide the element. |
| 173 $('sync-action-link').hidden = !status.length; | 211 $('sync-action-link').hidden = !status.length; |
| 174 }, | 212 }, |
| 175 | 213 |
| 214 /** | |
| 215 * Display or hide the profiles section of the page. This is used for | |
| 216 * multi-profile settings. | |
| 217 * @param {boolean} visible True to show the section. | |
| 218 * @private | |
| 219 */ | |
| 176 setProfilesSectionVisible_: function(visible) { | 220 setProfilesSectionVisible_: function(visible) { |
| 177 $('profiles-create').hidden = !visible; | 221 $('profiles-section').hidden = !visible; |
| 178 }, | 222 }, |
| 179 | 223 |
| 180 setNewProfileButtonEnabled_: function(enabled) { | 224 /** |
| 181 $('new-profile').disabled = !enabled; | 225 * Get the selected profile item from the profile list. This also works |
| 182 if (enabled) | 226 * correctly if the list is not displayed. |
| 183 $('profiles-create').classList.remove('disabled'); | 227 * @return {Object} the profile item object, or null if nothing is selected. |
| 184 else | 228 * @private |
| 185 $('profiles-create').classList.add('disabled'); | 229 */ |
| 230 getSelectedProfileItem_: function() { | |
| 231 var profilesList = $('profiles-list'); | |
| 232 if (profilesList.hidden) { | |
| 233 if (profilesList.dataModel.length > 0) | |
| 234 return profilesList.dataModel.item(0); | |
| 235 } else { | |
| 236 return profilesList.selectedItem; | |
| 237 } | |
| 238 return null; | |
| 239 }, | |
| 240 | |
| 241 /** | |
| 242 * Delete the profile given by |profileInfo|. | |
| 243 * @param {Object} profileInfo The profile info object of the profile that | |
| 244 * should be deleted. | |
| 245 */ | |
| 246 deleteProfile_: function(profileInfo) { | |
| 247 chrome.send('profilesDelete', [profileInfo.filePath]); | |
|
James Hawkins
2011/07/19 20:22:09
rename: deleteProfile
| |
| 248 }, | |
| 249 | |
| 250 /** | |
| 251 * Display the correct dialog layout, depending on how many profiles are | |
| 252 * available. | |
| 253 * @param {number} The number of profiles to display. | |
|
James Hawkins
2011/07/19 20:22:09
@param {number} numProfiles The...
| |
| 254 */ | |
| 255 setProfileViewSingle_: function(numProfiles) { | |
| 256 $('profiles-list').hidden = numProfiles <= 1; | |
|
James Hawkins
2011/07/19 20:22:09
You can do the same for profiles-manage and profil
| |
| 257 if (numProfiles <= 1) { | |
| 258 $('profiles-manage').hidden = true; | |
| 259 $('profiles-delete').hidden = true; | |
| 260 } else { | |
| 261 $('profiles-list').redraw(); | |
| 262 $('profiles-manage').hidden = false; | |
| 263 $('profiles-delete').hidden = false; | |
| 264 } | |
| 265 }, | |
| 266 | |
| 267 /** | |
| 268 * Called by the C++ handler. Adds all |profiles| to the list. | |
|
James Hawkins
2011/07/19 20:22:09
No need to specify the first sentence.
| |
| 269 * @param {Array.<Object>} An array of profile info objects. | |
| 270 * each object is like: | |
|
James Hawkins
2011/07/19 20:22:09
s/like/of the form/
| |
| 271 * profileInfo = { | |
| 272 * name: "Profile Name", | |
| 273 * iconURL: "chrome://path/to/icon/image", | |
| 274 * filePath: "/path/to/profile/data/on/disk", | |
| 275 * isCurrentProfile: false | |
| 276 * }; | |
| 277 */ | |
| 278 setProfilesInfo_: function(profiles) { | |
| 279 this.setProfileViewSingle_(profiles.length); | |
| 280 // add it to the list, even if the list is hidden so we can access it | |
| 281 // later. | |
| 282 $('profiles-list').dataModel = new ArrayDataModel(profiles); | |
| 186 }, | 283 }, |
| 187 | 284 |
| 188 setStartStopButtonVisible_: function(visible) { | 285 setStartStopButtonVisible_: function(visible) { |
| 189 $('start-stop-sync').hidden = !visible; | 286 $('start-stop-sync').hidden = !visible; |
| 190 }, | 287 }, |
| 191 | 288 |
| 192 setStartStopButtonEnabled_: function(enabled) { | 289 setStartStopButtonEnabled_: function(enabled) { |
| 193 $('start-stop-sync').disabled = !enabled; | 290 $('start-stop-sync').disabled = !enabled; |
| 194 }, | 291 }, |
| 195 | 292 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 346 |
| 250 // Forward public APIs to private implementations. | 347 // Forward public APIs to private implementations. |
| 251 [ | 348 [ |
| 252 'setSyncEnabled', | 349 'setSyncEnabled', |
| 253 'setSyncSetupCompleted', | 350 'setSyncSetupCompleted', |
| 254 'setAccountPicture', | 351 'setAccountPicture', |
| 255 'setSyncStatus', | 352 'setSyncStatus', |
| 256 'setSyncStatusErrorVisible', | 353 'setSyncStatusErrorVisible', |
| 257 'setSyncActionLinkEnabled', | 354 'setSyncActionLinkEnabled', |
| 258 'setSyncActionLinkLabel', | 355 'setSyncActionLinkLabel', |
| 356 'setProfilesInfo', | |
| 259 'setProfilesSectionVisible', | 357 'setProfilesSectionVisible', |
| 260 'setNewProfileButtonEnabled', | |
| 261 'setStartStopButtonVisible', | 358 'setStartStopButtonVisible', |
| 262 'setStartStopButtonEnabled', | 359 'setStartStopButtonEnabled', |
| 263 'setStartStopButtonLabel', | 360 'setStartStopButtonLabel', |
| 264 'setGtkThemeButtonEnabled', | 361 'setGtkThemeButtonEnabled', |
| 265 'setThemesResetButtonEnabled', | 362 'setThemesResetButtonEnabled', |
| 266 'hideSyncSection', | 363 'hideSyncSection', |
| 267 'setRegisteredDataTypes', | 364 'setRegisteredDataTypes', |
| 268 ].forEach(function(name) { | 365 ].forEach(function(name) { |
| 269 PersonalOptions[name] = function(value) { | 366 PersonalOptions[name] = function(value) { |
| 270 PersonalOptions.getInstance()[name + '_'](value); | 367 PersonalOptions.getInstance()[name + '_'](value); |
| 271 }; | 368 }; |
| 272 }); | 369 }); |
| 273 | 370 |
| 274 // Export | 371 // Export |
| 275 return { | 372 return { |
| 276 PersonalOptions: PersonalOptions | 373 PersonalOptions: PersonalOptions |
| 277 }; | 374 }; |
| 278 | 375 |
| 279 }); | 376 }); |
| 280 | 377 |
| OLD | NEW |