Index: chrome/browser/resources/options/personal_options.js |
diff --git a/chrome/browser/resources/options/personal_options.js b/chrome/browser/resources/options/personal_options.js |
index e5c17532b1a782c2d563a4e32dcfa7cd2ee6aba5..b76b22ac849de91532a8f535c0b0ca59d325d8ae 100644 |
--- a/chrome/browser/resources/options/personal_options.js |
+++ b/chrome/browser/resources/options/personal_options.js |
@@ -5,6 +5,7 @@ |
cr.define('options', function() { |
var OptionsPage = options.OptionsPage; |
+ var ArrayDataModel = cr.ui.ArrayDataModel; |
// State variables. |
var syncEnabled = false; |
@@ -32,6 +33,8 @@ cr.define('options', function() { |
OptionsPage.prototype.initializePage.call(this); |
var self = this; |
+ |
+ // sync |
James Hawkins
2011/07/19 20:22:09
Sync.
Capitalize comment sentences (or word) and
|
$('sync-action-link').onclick = function(event) { |
SyncSetupOverlay.showErrorUI(); |
}; |
@@ -44,17 +47,52 @@ cr.define('options', function() { |
$('customize-sync').onclick = function(event) { |
SyncSetupOverlay.showSetupUI(); |
}; |
+ |
+ // profiles |
+ var profilesList = $('profiles-list'); |
+ options.personal_options.ProfileList.decorate(profilesList); |
+ profilesList.autoExpands = true; |
+ |
+ profilesList.addEventListener('change', function(event) { |
James Hawkins
2011/07/19 20:22:09
onchange = function(...
|
+ var selectedProfile = profilesList.selectedItem; |
+ var hasSelection = selectedProfile != null; |
+ $('profiles-manage').disabled = !hasSelection; |
+ $('profiles-delete').disabled = !hasSelection; |
+ }); |
+ $('profiles-create').onclick = function(event) { |
+ chrome.send('profilesCreate'); |
+ }; |
+ $('profiles-manage').onclick = function(event) { |
+ var selectedProfile = self.getSelectedProfileItem_(); |
+ if (selectedProfile) { |
+ ProfilesManageOverlay.show(selectedProfile); |
+ } |
+ }; |
+ $('profiles-delete').onclick = function(event) { |
+ var selectedProfile = self.getSelectedProfileItem_(); |
+ if (!selectedProfile) |
+ return; |
+ |
+ ProfilesManageOverlay.showDeleteDialog(selectedProfile); |
+ chrome.send('profilesDeleteShowWarnings', selectedProfile.filePath); |
+ }; |
+ |
+ // passwords |
$('manage-passwords').onclick = function(event) { |
OptionsPage.navigateToPage('passwords'); |
OptionsPage.showTab($('passwords-nav-tab')); |
chrome.send('coreOptionsUserMetricsAction', |
['Options_ShowPasswordManager']); |
}; |
+ |
+ // autofill |
$('autofill-settings').onclick = function(event) { |
OptionsPage.navigateToPage('autofill'); |
chrome.send('coreOptionsUserMetricsAction', |
['Options_ShowAutofillSettings']); |
}; |
+ |
+ // appearance |
$('themes-reset').onclick = function(event) { |
chrome.send('themesReset'); |
}; |
@@ -173,16 +211,75 @@ cr.define('options', function() { |
$('sync-action-link').hidden = !status.length; |
}, |
+ /** |
+ * Display or hide the profiles section of the page. This is used for |
+ * multi-profile settings. |
+ * @param {boolean} visible True to show the section. |
+ * @private |
+ */ |
setProfilesSectionVisible_: function(visible) { |
- $('profiles-create').hidden = !visible; |
+ $('profiles-section').hidden = !visible; |
+ }, |
+ |
+ /** |
+ * Get the selected profile item from the profile list. This also works |
+ * correctly if the list is not displayed. |
+ * @return {Object} the profile item object, or null if nothing is selected. |
+ * @private |
+ */ |
+ getSelectedProfileItem_: function() { |
+ var profilesList = $('profiles-list'); |
+ if (profilesList.hidden) { |
+ if (profilesList.dataModel.length > 0) |
+ return profilesList.dataModel.item(0); |
+ } else { |
+ return profilesList.selectedItem; |
+ } |
+ return null; |
+ }, |
+ |
+ /** |
+ * Delete the profile given by |profileInfo|. |
+ * @param {Object} profileInfo The profile info object of the profile that |
+ * should be deleted. |
+ */ |
+ deleteProfile_: function(profileInfo) { |
+ chrome.send('profilesDelete', [profileInfo.filePath]); |
James Hawkins
2011/07/19 20:22:09
rename: deleteProfile
|
}, |
- setNewProfileButtonEnabled_: function(enabled) { |
- $('new-profile').disabled = !enabled; |
- if (enabled) |
- $('profiles-create').classList.remove('disabled'); |
- else |
- $('profiles-create').classList.add('disabled'); |
+ /** |
+ * Display the correct dialog layout, depending on how many profiles are |
+ * available. |
+ * @param {number} The number of profiles to display. |
James Hawkins
2011/07/19 20:22:09
@param {number} numProfiles The...
|
+ */ |
+ setProfileViewSingle_: function(numProfiles) { |
+ $('profiles-list').hidden = numProfiles <= 1; |
James Hawkins
2011/07/19 20:22:09
You can do the same for profiles-manage and profil
|
+ if (numProfiles <= 1) { |
+ $('profiles-manage').hidden = true; |
+ $('profiles-delete').hidden = true; |
+ } else { |
+ $('profiles-list').redraw(); |
+ $('profiles-manage').hidden = false; |
+ $('profiles-delete').hidden = false; |
+ } |
+ }, |
+ |
+ /** |
+ * 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.
|
+ * @param {Array.<Object>} An array of profile info objects. |
+ * each object is like: |
James Hawkins
2011/07/19 20:22:09
s/like/of the form/
|
+ * profileInfo = { |
+ * name: "Profile Name", |
+ * iconURL: "chrome://path/to/icon/image", |
+ * filePath: "/path/to/profile/data/on/disk", |
+ * isCurrentProfile: false |
+ * }; |
+ */ |
+ setProfilesInfo_: function(profiles) { |
+ this.setProfileViewSingle_(profiles.length); |
+ // add it to the list, even if the list is hidden so we can access it |
+ // later. |
+ $('profiles-list').dataModel = new ArrayDataModel(profiles); |
}, |
setStartStopButtonVisible_: function(visible) { |
@@ -256,8 +353,8 @@ cr.define('options', function() { |
'setSyncStatusErrorVisible', |
'setSyncActionLinkEnabled', |
'setSyncActionLinkLabel', |
+ 'setProfilesInfo', |
'setProfilesSectionVisible', |
- 'setNewProfileButtonEnabled', |
'setStartStopButtonVisible', |
'setStartStopButtonEnabled', |
'setStartStopButtonLabel', |