| 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. |
| 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.onchange = function(event) { |
| 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('createProfile'); |
| 64 }; |
| 65 $('profiles-manage').onclick = function(event) { |
| 66 var selectedProfile = self.getSelectedProfileItem_(); |
| 67 if (selectedProfile) |
| 68 ManageProfileOverlay.showManageDialog(selectedProfile); |
| 69 }; |
| 70 $('profiles-delete').onclick = function(event) { |
| 71 var selectedProfile = self.getSelectedProfileItem_(); |
| 72 if (selectedProfile) |
| 73 ManageProfileOverlay.showDeleteDialog(selectedProfile); |
| 74 }; |
| 75 |
| 76 // Passwords. |
| 47 $('manage-passwords').onclick = function(event) { | 77 $('manage-passwords').onclick = function(event) { |
| 48 OptionsPage.navigateToPage('passwords'); | 78 OptionsPage.navigateToPage('passwords'); |
| 49 OptionsPage.showTab($('passwords-nav-tab')); | 79 OptionsPage.showTab($('passwords-nav-tab')); |
| 50 chrome.send('coreOptionsUserMetricsAction', | 80 chrome.send('coreOptionsUserMetricsAction', |
| 51 ['Options_ShowPasswordManager']); | 81 ['Options_ShowPasswordManager']); |
| 52 }; | 82 }; |
| 83 |
| 84 // Autofill. |
| 53 $('autofill-settings').onclick = function(event) { | 85 $('autofill-settings').onclick = function(event) { |
| 54 OptionsPage.navigateToPage('autofill'); | 86 OptionsPage.navigateToPage('autofill'); |
| 55 chrome.send('coreOptionsUserMetricsAction', | 87 chrome.send('coreOptionsUserMetricsAction', |
| 56 ['Options_ShowAutofillSettings']); | 88 ['Options_ShowAutofillSettings']); |
| 57 }; | 89 }; |
| 90 |
| 91 // Appearance. |
| 58 $('themes-reset').onclick = function(event) { | 92 $('themes-reset').onclick = function(event) { |
| 59 chrome.send('themesReset'); | 93 chrome.send('themesReset'); |
| 60 }; | 94 }; |
| 61 | 95 |
| 62 if (!cr.isChromeOS) { | 96 if (!cr.isChromeOS) { |
| 63 $('import-data').onclick = function(event) { | 97 $('import-data').onclick = function(event) { |
| 64 // Make sure that any previous import success message is hidden, and | 98 // Make sure that any previous import success message is hidden, and |
| 65 // we're showing the UI to import further data. | 99 // we're showing the UI to import further data. |
| 66 $('import-data-configure').hidden = false; | 100 $('import-data-configure').hidden = false; |
| 67 $('import-data-success').hidden = true; | 101 $('import-data-success').hidden = true; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 }, | 172 }, |
| 139 | 173 |
| 140 setSyncActionLinkLabel_: function(status) { | 174 setSyncActionLinkLabel_: function(status) { |
| 141 $('sync-action-link').textContent = status; | 175 $('sync-action-link').textContent = status; |
| 142 | 176 |
| 143 // link-button does is not zero-area when the contents of the button are | 177 // link-button does is not zero-area when the contents of the button are |
| 144 // empty, so explicitly hide the element. | 178 // empty, so explicitly hide the element. |
| 145 $('sync-action-link').hidden = !status.length; | 179 $('sync-action-link').hidden = !status.length; |
| 146 }, | 180 }, |
| 147 | 181 |
| 182 /** |
| 183 * Display or hide the profiles section of the page. This is used for |
| 184 * multi-profile settings. |
| 185 * @param {boolean} visible True to show the section. |
| 186 * @private |
| 187 */ |
| 148 setProfilesSectionVisible_: function(visible) { | 188 setProfilesSectionVisible_: function(visible) { |
| 149 $('profiles-create').hidden = !visible; | 189 $('profiles-section').hidden = !visible; |
| 150 }, | 190 }, |
| 151 | 191 |
| 152 setNewProfileButtonEnabled_: function(enabled) { | 192 /** |
| 153 $('new-profile').disabled = !enabled; | 193 * Get the selected profile item from the profile list. This also works |
| 154 if (enabled) | 194 * correctly if the list is not displayed. |
| 155 $('profiles-create').classList.remove('disabled'); | 195 * @return {Object} the profile item object, or null if nothing is selected. |
| 156 else | 196 * @private |
| 157 $('profiles-create').classList.add('disabled'); | 197 */ |
| 198 getSelectedProfileItem_: function() { |
| 199 var profilesList = $('profiles-list'); |
| 200 if (profilesList.hidden) { |
| 201 if (profilesList.dataModel.length > 0) |
| 202 return profilesList.dataModel.item(0); |
| 203 } else { |
| 204 return profilesList.selectedItem; |
| 205 } |
| 206 return null; |
| 207 }, |
| 208 |
| 209 /** |
| 210 * Display the correct dialog layout, depending on how many profiles are |
| 211 * available. |
| 212 * @param {number} numProfiles The number of profiles to display. |
| 213 */ |
| 214 setProfileViewSingle_: function(numProfiles) { |
| 215 $('profiles-list').hidden = numProfiles <= 1; |
| 216 $('profiles-manage').hidden = numProfiles <= 1; |
| 217 $('profiles-delete').hidden = numProfiles <= 1; |
| 218 }, |
| 219 |
| 220 /** |
| 221 * Adds all |profiles| to the list. |
| 222 * @param {Array.<Object>} An array of profile info objects. |
| 223 * each object is of the form: |
| 224 * profileInfo = { |
| 225 * name: "Profile Name", |
| 226 * iconURL: "chrome://path/to/icon/image", |
| 227 * filePath: "/path/to/profile/data/on/disk", |
| 228 * isCurrentProfile: false |
| 229 * }; |
| 230 */ |
| 231 setProfilesInfo_: function(profiles) { |
| 232 this.setProfileViewSingle_(profiles.length); |
| 233 // add it to the list, even if the list is hidden so we can access it |
| 234 // later. |
| 235 $('profiles-list').dataModel = new ArrayDataModel(profiles); |
| 158 }, | 236 }, |
| 159 | 237 |
| 160 setStartStopButtonVisible_: function(visible) { | 238 setStartStopButtonVisible_: function(visible) { |
| 161 $('start-stop-sync').hidden = !visible; | 239 $('start-stop-sync').hidden = !visible; |
| 162 }, | 240 }, |
| 163 | 241 |
| 164 setStartStopButtonEnabled_: function(enabled) { | 242 setStartStopButtonEnabled_: function(enabled) { |
| 165 $('start-stop-sync').disabled = !enabled; | 243 $('start-stop-sync').disabled = !enabled; |
| 166 }, | 244 }, |
| 167 | 245 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 299 |
| 222 // Forward public APIs to private implementations. | 300 // Forward public APIs to private implementations. |
| 223 [ | 301 [ |
| 224 'setSyncEnabled', | 302 'setSyncEnabled', |
| 225 'setSyncSetupCompleted', | 303 'setSyncSetupCompleted', |
| 226 'setAccountPicture', | 304 'setAccountPicture', |
| 227 'setSyncStatus', | 305 'setSyncStatus', |
| 228 'setSyncStatusErrorVisible', | 306 'setSyncStatusErrorVisible', |
| 229 'setSyncActionLinkEnabled', | 307 'setSyncActionLinkEnabled', |
| 230 'setSyncActionLinkLabel', | 308 'setSyncActionLinkLabel', |
| 309 'setProfilesInfo', |
| 231 'setProfilesSectionVisible', | 310 'setProfilesSectionVisible', |
| 232 'setNewProfileButtonEnabled', | |
| 233 'setStartStopButtonVisible', | 311 'setStartStopButtonVisible', |
| 234 'setStartStopButtonEnabled', | 312 'setStartStopButtonEnabled', |
| 235 'setStartStopButtonLabel', | 313 'setStartStopButtonLabel', |
| 236 'setGtkThemeButtonEnabled', | 314 'setGtkThemeButtonEnabled', |
| 237 'setThemesResetButtonEnabled', | 315 'setThemesResetButtonEnabled', |
| 238 'hideSyncSection', | 316 'hideSyncSection', |
| 239 'setRegisteredDataTypes', | 317 'setRegisteredDataTypes', |
| 240 ].forEach(function(name) { | 318 ].forEach(function(name) { |
| 241 PersonalOptions[name] = function(value) { | 319 PersonalOptions[name] = function(value) { |
| 242 PersonalOptions.getInstance()[name + '_'](value); | 320 PersonalOptions.getInstance()[name + '_'](value); |
| 243 }; | 321 }; |
| 244 }); | 322 }); |
| 245 | 323 |
| 246 // Export | 324 // Export |
| 247 return { | 325 return { |
| 248 PersonalOptions: PersonalOptions | 326 PersonalOptions: PersonalOptions |
| 249 }; | 327 }; |
| 250 | 328 |
| 251 }); | 329 }); |
| OLD | NEW |