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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 }, | 200 }, |
167 | 201 |
168 setSyncActionLinkLabel_: function(status) { | 202 setSyncActionLinkLabel_: function(status) { |
169 $('sync-action-link').textContent = status; | 203 $('sync-action-link').textContent = status; |
170 | 204 |
171 // link-button does is not zero-area when the contents of the button are | 205 // link-button does is not zero-area when the contents of the button are |
172 // empty, so explicitly hide the element. | 206 // empty, so explicitly hide the element. |
173 $('sync-action-link').hidden = !status.length; | 207 $('sync-action-link').hidden = !status.length; |
174 }, | 208 }, |
175 | 209 |
| 210 /** |
| 211 * Display or hide the profiles section of the page. This is used for |
| 212 * multi-profile settings. |
| 213 * @param {boolean} visible True to show the section. |
| 214 * @private |
| 215 */ |
176 setProfilesSectionVisible_: function(visible) { | 216 setProfilesSectionVisible_: function(visible) { |
177 $('profiles-create').hidden = !visible; | 217 $('profiles-section').hidden = !visible; |
178 }, | 218 }, |
179 | 219 |
180 setNewProfileButtonEnabled_: function(enabled) { | 220 /** |
181 $('new-profile').disabled = !enabled; | 221 * Get the selected profile item from the profile list. This also works |
182 if (enabled) | 222 * correctly if the list is not displayed. |
183 $('profiles-create').classList.remove('disabled'); | 223 * @return {Object} the profile item object, or null if nothing is selected. |
184 else | 224 * @private |
185 $('profiles-create').classList.add('disabled'); | 225 */ |
| 226 getSelectedProfileItem_: function() { |
| 227 var profilesList = $('profiles-list'); |
| 228 if (profilesList.hidden) { |
| 229 if (profilesList.dataModel.length > 0) |
| 230 return profilesList.dataModel.item(0); |
| 231 } else { |
| 232 return profilesList.selectedItem; |
| 233 } |
| 234 return null; |
| 235 }, |
| 236 |
| 237 /** |
| 238 * Display the correct dialog layout, depending on how many profiles are |
| 239 * available. |
| 240 * @param {number} numProfiles The number of profiles to display. |
| 241 */ |
| 242 setProfileViewSingle_: function(numProfiles) { |
| 243 $('profiles-list').hidden = numProfiles <= 1; |
| 244 $('profiles-manage').hidden = numProfiles <= 1; |
| 245 $('profiles-delete').hidden = numProfiles <= 1; |
| 246 }, |
| 247 |
| 248 /** |
| 249 * Adds all |profiles| to the list. |
| 250 * @param {Array.<Object>} An array of profile info objects. |
| 251 * each object is of the form: |
| 252 * profileInfo = { |
| 253 * name: "Profile Name", |
| 254 * iconURL: "chrome://path/to/icon/image", |
| 255 * filePath: "/path/to/profile/data/on/disk", |
| 256 * isCurrentProfile: false |
| 257 * }; |
| 258 */ |
| 259 setProfilesInfo_: function(profiles) { |
| 260 this.setProfileViewSingle_(profiles.length); |
| 261 // add it to the list, even if the list is hidden so we can access it |
| 262 // later. |
| 263 $('profiles-list').dataModel = new ArrayDataModel(profiles); |
186 }, | 264 }, |
187 | 265 |
188 setStartStopButtonVisible_: function(visible) { | 266 setStartStopButtonVisible_: function(visible) { |
189 $('start-stop-sync').hidden = !visible; | 267 $('start-stop-sync').hidden = !visible; |
190 }, | 268 }, |
191 | 269 |
192 setStartStopButtonEnabled_: function(enabled) { | 270 setStartStopButtonEnabled_: function(enabled) { |
193 $('start-stop-sync').disabled = !enabled; | 271 $('start-stop-sync').disabled = !enabled; |
194 }, | 272 }, |
195 | 273 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 327 |
250 // Forward public APIs to private implementations. | 328 // Forward public APIs to private implementations. |
251 [ | 329 [ |
252 'setSyncEnabled', | 330 'setSyncEnabled', |
253 'setSyncSetupCompleted', | 331 'setSyncSetupCompleted', |
254 'setAccountPicture', | 332 'setAccountPicture', |
255 'setSyncStatus', | 333 'setSyncStatus', |
256 'setSyncStatusErrorVisible', | 334 'setSyncStatusErrorVisible', |
257 'setSyncActionLinkEnabled', | 335 'setSyncActionLinkEnabled', |
258 'setSyncActionLinkLabel', | 336 'setSyncActionLinkLabel', |
| 337 'setProfilesInfo', |
259 'setProfilesSectionVisible', | 338 'setProfilesSectionVisible', |
260 'setNewProfileButtonEnabled', | |
261 'setStartStopButtonVisible', | 339 'setStartStopButtonVisible', |
262 'setStartStopButtonEnabled', | 340 'setStartStopButtonEnabled', |
263 'setStartStopButtonLabel', | 341 'setStartStopButtonLabel', |
264 'setGtkThemeButtonEnabled', | 342 'setGtkThemeButtonEnabled', |
265 'setThemesResetButtonEnabled', | 343 'setThemesResetButtonEnabled', |
266 'hideSyncSection', | 344 'hideSyncSection', |
267 'setRegisteredDataTypes', | 345 'setRegisteredDataTypes', |
268 ].forEach(function(name) { | 346 ].forEach(function(name) { |
269 PersonalOptions[name] = function(value) { | 347 PersonalOptions[name] = function(value) { |
270 PersonalOptions.getInstance()[name + '_'](value); | 348 PersonalOptions.getInstance()[name + '_'](value); |
271 }; | 349 }; |
272 }); | 350 }); |
273 | 351 |
274 // Export | 352 // Export |
275 return { | 353 return { |
276 PersonalOptions: PersonalOptions | 354 PersonalOptions: PersonalOptions |
277 }; | 355 }; |
278 | 356 |
279 }); | 357 }); |
280 | 358 |
OLD | NEW |