Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: chrome/browser/resources/options2/manage_profile_overlay.js

Issue 10834142: [options2] Fix issue when deleting a user and pressing back. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 var OptionsPage = options.OptionsPage; 6 var OptionsPage = options.OptionsPage;
7 var ArrayDataModel = cr.ui.ArrayDataModel; 7 var ArrayDataModel = cr.ui.ArrayDataModel;
8 8
9 /** 9 /**
10 * ManageProfileOverlay class 10 * ManageProfileOverlay class
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 var name = $('create-profile-name').value; 78 var name = $('create-profile-name').value;
79 var icon_url = createIconGrid.selectedItem; 79 var icon_url = createIconGrid.selectedItem;
80 chrome.send('createProfile', [name, icon_url]); 80 chrome.send('createProfile', [name, icon_url]);
81 }; 81 };
82 }, 82 },
83 83
84 /** @inheritDoc */ 84 /** @inheritDoc */
85 didShowPage: function() { 85 didShowPage: function() {
86 chrome.send('requestDefaultProfileIcons'); 86 chrome.send('requestDefaultProfileIcons');
87 87
88 // Use the hash to specify the profile index. Note: the actual index 88 // didShowPage happens when a page is visited via explicit user action
89 // is ignored. Only the current profile may be edited. 89 // (e.g. a user clicks "Add User" or "Edit User") or when going back or
90 if (window.location.hash.length > 1) 90 // forward in history. If the user goes back to a #create page, generate a
91 // new profile info suggestion. Additionally, #edit is assumed as the
92 // default case for anything other than #create with a path of
93 // /manageProfile (as delete explicitly doesn't change the path nor
94 // generate any history events).
95 if (window.location.hash == '#create')
96 ManageProfileOverlay.getInstance().prepareForCreateDialog_();
97 else if (window.location.pathname == '/manageProfile')
91 ManageProfileOverlay.getInstance().prepareForManageDialog_(); 98 ManageProfileOverlay.getInstance().prepareForManageDialog_();
92
93 $('manage-profile-name').focus();
94 $('create-profile-name').focus();
95 }, 99 },
96 100
97 /** 101 /**
98 * Set the profile info used in the dialog. 102 * Set the profile info used in the dialog.
99 * @param {Object} profileInfo An object of the form: 103 * @param {Object} profileInfo An object of the form:
100 * profileInfo = { 104 * profileInfo = {
101 * name: "Profile Name", 105 * name: "Profile Name",
102 * iconURL: "chrome://path/to/icon/image", 106 * iconURL: "chrome://path/to/icon/image",
103 * filePath: "/path/to/profile/data/on/disk" 107 * filePath: "/path/to/profile/data/on/disk"
104 * isCurrentProfile: false, 108 * isCurrentProfile: false,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 onIconGridSelectionChanged_: function(mode) { 230 onIconGridSelectionChanged_: function(mode) {
227 var iconURL = $(mode + '-profile-icon-grid').selectedItem; 231 var iconURL = $(mode + '-profile-icon-grid').selectedItem;
228 if (!iconURL || iconURL == this.iconGridSelectedURL_) 232 if (!iconURL || iconURL == this.iconGridSelectedURL_)
229 return; 233 return;
230 this.iconGridSelectedURL_ = iconURL; 234 this.iconGridSelectedURL_ = iconURL;
231 chrome.send('profileIconSelectionChanged', 235 chrome.send('profileIconSelectionChanged',
232 [this.profileInfo_.filePath, iconURL]); 236 [this.profileInfo_.filePath, iconURL]);
233 }, 237 },
234 238
235 /** 239 /**
236 * Updates the contents of the "Manage Profile" section of the dialog, 240 * Updates the contents of the "Manage Profile" section of the dialog
237 * and shows that section. 241 * and shows that section.
238 * @private 242 * @private
239 */ 243 */
240 prepareForManageDialog_: function() { 244 prepareForManageDialog_: function() {
241 var profileInfo = BrowserOptions.getCurrentProfile(); 245 var profileInfo = BrowserOptions.getCurrentProfile();
242 ManageProfileOverlay.setProfileInfo(profileInfo, 'manage'); 246 ManageProfileOverlay.setProfileInfo(profileInfo, 'manage');
243 $('manage-profile-overlay-create').hidden = true; 247 this.hideAllDialogSections_($('manage-profile-overlay-manage'));
244 $('manage-profile-overlay-manage').hidden = false;
245 $('manage-profile-overlay-delete').hidden = true;
246 this.hideErrorBubble_('manage'); 248 this.hideErrorBubble_('manage');
249 $('manage-profile-name').focus();
247 }, 250 },
248 251
249 /** 252 /**
250 * Display the "Manage Profile" dialog. 253 * Display the "Manage Profile" dialog.
251 * @private 254 * @private
252 */ 255 */
253 showManageDialog_: function() { 256 showManageDialog_: function() {
254 this.prepareForManageDialog_(); 257 this.prepareForManageDialog_();
255 OptionsPage.navigateToPage('manageProfile'); 258 OptionsPage.showPageByName('manageProfile', true, {hash: '#edit'});
256 }, 259 },
257 260
258 /** 261 /**
262 * Hides all dialog sections.
263 * @param {Element=} opt_exceptDialog An optional dialog to show.
264 * @private
265 */
266 hideAllDialogSections_: function(opt_exceptDialog) {
267 ['manage-profile-overlay-create',
268 'manage-profile-overlay-manage',
269 'manage-profile-overlay-delete'].forEach(function(id) {
270 var section = getRequiredElement(id);
271 section.hidden = opt_exceptDialog != section;
272 });
273 },
274
275 /**
259 * Display the "Delete Profile" dialog. 276 * Display the "Delete Profile" dialog.
260 * @param {Object} profileInfo The profile object of the profile to delete. 277 * @param {Object} profileInfo The profile object of the profile to delete.
261 * @private 278 * @private
262 */ 279 */
263 showDeleteDialog_: function(profileInfo) { 280 showDeleteDialog_: function(profileInfo) {
264 ManageProfileOverlay.setProfileInfo(profileInfo, 'manage'); 281 ManageProfileOverlay.setProfileInfo(profileInfo, 'manage');
265 $('manage-profile-overlay-create').hidden = true; 282 this.hideAllDialogSections_($('manage-profile-overlay-delete'));
266 $('manage-profile-overlay-manage').hidden = true;
267 $('manage-profile-overlay-delete').hidden = false;
268 $('delete-profile-message').textContent = 283 $('delete-profile-message').textContent =
269 loadTimeData.getStringF('deleteProfileMessage', profileInfo.name); 284 loadTimeData.getStringF('deleteProfileMessage', profileInfo.name);
270 $('delete-profile-message').style.backgroundImage = 'url("' + 285 $('delete-profile-message').style.backgroundImage = 'url("' +
271 profileInfo.iconURL + '")'; 286 profileInfo.iconURL + '")';
272 287
273 // Because this dialog isn't useful when refreshing or as part of the 288 // Because this dialog isn't useful when refreshing or as part of the
274 // history, don't create a history entry for it when showing. 289 // history, don't create a history entry for it when showing.
275 OptionsPage.showPageByName('manageProfile', false); 290 OptionsPage.showPageByName('manageProfile', false);
276 }, 291 },
277 292
278 /** 293 /**
294 * Readies the manage profile overlay to show create section of the dialog.
295 * @private
296 */
297 prepareForCreateDialog_: function() {
298 chrome.send('createProfileInfo');
299 this.hideAllDialogSections_($('manage-profile-overlay-create'));
300 $('create-profile-instructions').textContent =
301 loadTimeData.getStringF('createProfileInstructions');
302 ManageProfileOverlay.getInstance().hideErrorBubble_('create');
303 $('create-profile-name').focus();
304 },
305
306 /**
279 * Display the "Create Profile" dialog. 307 * Display the "Create Profile" dialog.
280 * @param {Object} profileInfo The profile object of the profile to 308 * @param {Object} profileInfo The profile object of the profile to
281 * create. Upon creation, this object only needs a name and an avatar. 309 * create. Upon creation, this object only needs a name and an avatar.
282 * @private 310 * @private
283 */ 311 */
284 showCreateDialog_: function(profileInfo) { 312 showCreateDialog_: function() {
285 ManageProfileOverlay.setProfileInfo(profileInfo, 'create'); 313 this.prepareForCreateDialog_();
286 $('manage-profile-overlay-create').hidden = false; 314 OptionsPage.showPageByName('manageProfile', true, {hash: '#create'});
287 $('manage-profile-overlay-manage').hidden = true;
288 $('manage-profile-overlay-delete').hidden = true;
289 $('create-profile-instructions').textContent =
290 loadTimeData.getStringF('createProfileInstructions');
291 ManageProfileOverlay.getInstance().hideErrorBubble_('create');
292
293 OptionsPage.navigateToPage('manageProfile');
294 }, 315 },
295
296 }; 316 };
297 317
298 // Forward public APIs to private implementations. 318 // Forward public APIs to private implementations.
299 [ 319 [
300 'receiveDefaultProfileIcons', 320 'receiveDefaultProfileIcons',
301 'receiveProfileNames', 321 'receiveProfileNames',
302 'setProfileInfo', 322 'setProfileInfo',
303 'setProfileName', 323 'setProfileName',
304 'showManageDialog', 324 'showManageDialog',
305 'showDeleteDialog', 325 'showDeleteDialog',
306 'showCreateDialog', 326 'showCreateDialog',
307 ].forEach(function(name) { 327 ].forEach(function(name) {
308 ManageProfileOverlay[name] = function() { 328 ManageProfileOverlay[name] = function() {
309 var instance = ManageProfileOverlay.getInstance(); 329 var instance = ManageProfileOverlay.getInstance();
310 return instance[name + '_'].apply(instance, arguments); 330 return instance[name + '_'].apply(instance, arguments);
311 }; 331 };
312 }); 332 });
313 333
314 // Export 334 // Export
315 return { 335 return {
316 ManageProfileOverlay: ManageProfileOverlay 336 ManageProfileOverlay: ManageProfileOverlay
317 }; 337 };
318 }); 338 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698