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

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

Issue 15734006: Restructure user-creation flow and surface errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 7 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 30 matching lines...) Expand all
41 OptionsPage.prototype.initializePage.call(this); 41 OptionsPage.prototype.initializePage.call(this);
42 42
43 var self = this; 43 var self = this;
44 options.ProfilesIconGrid.decorate($('manage-profile-icon-grid')); 44 options.ProfilesIconGrid.decorate($('manage-profile-icon-grid'));
45 options.ProfilesIconGrid.decorate($('create-profile-icon-grid')); 45 options.ProfilesIconGrid.decorate($('create-profile-icon-grid'));
46 self.registerCommonEventHandlers_('create', 46 self.registerCommonEventHandlers_('create',
47 self.submitCreateProfile_.bind(self)); 47 self.submitCreateProfile_.bind(self));
48 self.registerCommonEventHandlers_('manage', 48 self.registerCommonEventHandlers_('manage',
49 self.submitManageChanges_.bind(self)); 49 self.submitManageChanges_.bind(self));
50 50
51 // Override the create-profile-ok handler, to avoid closing the overlay
52 // until we finish creating the profile.
Andrew T Wilson (Slow) 2013/05/27 12:02:43 Do we need to guard against multiple clicks by dis
Pam (message me for reviews) 2013/05/27 14:34:37 I'd been pondering that. I don't think there's act
53 $('create-profile-ok').onclick = function(event) {
54 ManageProfileOverlay.getInstance().hideErrorBubble_('create');
55 self.submitCreateProfile_();
56 };
57
51 if (loadTimeData.getBoolean('managedUsersEnabled')) { 58 if (loadTimeData.getBoolean('managedUsersEnabled')) {
52 $('create-profile-limited-container').hidden = false; 59 $('create-profile-limited-container').hidden = false;
53 } 60 }
54 $('manage-profile-cancel').onclick = 61 $('manage-profile-cancel').onclick =
55 $('delete-profile-cancel').onclick = 62 $('delete-profile-cancel').onclick =
56 $('create-profile-cancel').onclick = function(event) { 63 $('create-profile-cancel').onclick = function(event) {
57 OptionsPage.closeOverlay(); 64 OptionsPage.closeOverlay();
58 }; 65 };
59 $('delete-profile-ok').onclick = function(event) { 66 $('delete-profile-ok').onclick = function(event) {
60 OptionsPage.closeOverlay(); 67 OptionsPage.closeOverlay();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 receiveHasProfileShortcuts_: function(hasShortcuts) { 228 receiveHasProfileShortcuts_: function(hasShortcuts) {
222 $('add-shortcut-button').hidden = hasShortcuts; 229 $('add-shortcut-button').hidden = hasShortcuts;
223 $('remove-shortcut-button').hidden = !hasShortcuts; 230 $('remove-shortcut-button').hidden = !hasShortcuts;
224 }, 231 },
225 232
226 /** 233 /**
227 * Display the error bubble, with |errorText| in the bubble. 234 * Display the error bubble, with |errorText| in the bubble.
228 * @param {string} errorText The localized string id to display as an error. 235 * @param {string} errorText The localized string id to display as an error.
229 * @param {string} mode A label that specifies the type of dialog 236 * @param {string} mode A label that specifies the type of dialog
230 * box which is currently being viewed (i.e. 'create' or 237 * box which is currently being viewed (i.e. 'create' or
231 * 'manage'). 238 * 'manage').
Andrew T Wilson (Slow) 2013/05/27 12:02:43 document new parameter.
232 * @private 239 * @private
233 */ 240 */
234 showErrorBubble_: function(errorText, mode) { 241 showErrorBubble_: function(errorText, mode, disableOKButton) {
235 var nameErrorEl = $(mode + '-profile-error-bubble'); 242 var nameErrorEl = $(mode + '-profile-error-bubble');
236 nameErrorEl.hidden = false; 243 nameErrorEl.hidden = false;
237 nameErrorEl.textContent = loadTimeData.getString(errorText); 244 nameErrorEl.textContent = loadTimeData.getString(errorText);
238 245
239 $(mode + '-profile-ok').disabled = true; 246 if (disableOKButton)
247 $(mode + '-profile-ok').disabled = true;
240 }, 248 },
241 249
242 /** 250 /**
243 * Hide the error bubble. 251 * Hide the error bubble.
244 * @param {string} mode A label that specifies the type of dialog 252 * @param {string} mode A label that specifies the type of dialog
245 * box which is currently being viewed (i.e. 'create' or 253 * box which is currently being viewed (i.e. 'create' or
246 * 'manage'). 254 * 'manage').
247 * @private 255 * @private
248 */ 256 */
249 hideErrorBubble_: function(mode) { 257 hideErrorBubble_: function(mode) {
250 $(mode + '-profile-error-bubble').hidden = true; 258 $(mode + '-profile-error-bubble').hidden = true;
251 $(mode + '-profile-ok').disabled = false; 259 $(mode + '-profile-ok').disabled = false;
252 }, 260 },
253 261
254 /** 262 /**
255 * oninput callback for <input> field. 263 * oninput callback for <input> field.
256 * @param {Event} event The event object. 264 * @param {Event} event The event object.
257 * @param {string} mode A label that specifies the type of dialog 265 * @param {string} mode A label that specifies the type of dialog
258 * box which is currently being viewed (i.e. 'create' or 266 * box which is currently being viewed (i.e. 'create' or
259 * 'manage'). 267 * 'manage').
260 * @private 268 * @private
261 */ 269 */
262 onNameChanged_: function(event, mode) { 270 onNameChanged_: function(event, mode) {
263 var newName = event.target.value; 271 var newName = event.target.value;
264 var oldName = this.profileInfo_.name; 272 var oldName = this.profileInfo_.name;
265 273
266 if (newName == oldName) { 274 if (newName == oldName) {
267 this.hideErrorBubble_(mode); 275 this.hideErrorBubble_(mode);
268 } else if (this.profileNames_[newName] != undefined) { 276 } else if (this.profileNames_[newName] != undefined) {
269 this.showErrorBubble_('manageProfilesDuplicateNameError', mode); 277 this.showErrorBubble_('manageProfilesDuplicateNameError', mode, true);
270 } else { 278 } else {
271 this.hideErrorBubble_(mode); 279 this.hideErrorBubble_(mode);
272 280
273 var nameIsValid = $(mode + '-profile-name').validity.valid; 281 var nameIsValid = $(mode + '-profile-name').validity.valid;
274 $(mode + '-profile-ok').disabled = !nameIsValid; 282 $(mode + '-profile-ok').disabled = !nameIsValid;
275 } 283 }
276 }, 284 },
277 285
278 /** 286 /**
279 * Called when the user clicks "OK" or hits enter. Saves the newly changed 287 * Called when the user clicks "OK" or hits enter. Saves the newly changed
(...skipping 13 matching lines...) Expand all
293 * using the information in the dialog. 301 * using the information in the dialog.
294 * @private 302 * @private
295 */ 303 */
296 submitCreateProfile_: function() { 304 submitCreateProfile_: function() {
297 // Get the user's chosen name and icon, or default if they do not 305 // Get the user's chosen name and icon, or default if they do not
298 // wish to customize their profile. 306 // wish to customize their profile.
299 var name = $('create-profile-name').value; 307 var name = $('create-profile-name').value;
300 var iconUrl = $('create-profile-icon-grid').selectedItem; 308 var iconUrl = $('create-profile-icon-grid').selectedItem;
301 var createShortcut = $('create-shortcut').checked; 309 var createShortcut = $('create-shortcut').checked;
302 var isManaged = $('create-profile-limited').checked; 310 var isManaged = $('create-profile-limited').checked;
311
312 // 'createProfile' is handled by the BrowserOptionsHandler.
303 chrome.send('createProfile', 313 chrome.send('createProfile',
304 [name, iconUrl, createShortcut, isManaged]); 314 [name, iconUrl, createShortcut, isManaged]);
305 }, 315 },
306 316
307 /** 317 /**
308 * Called when the selected icon in the icon grid changes. 318 * Called when the selected icon in the icon grid changes.
309 * @param {string} mode A label that specifies the type of dialog 319 * @param {string} mode A label that specifies the type of dialog
310 * box which is currently being viewed (i.e. 'create' or 320 * box which is currently being viewed (i.e. 'create' or
311 * 'manage'). 321 * 'manage').
312 * @private 322 * @private
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 didShowPage: function() { 421 didShowPage: function() {
412 chrome.send('requestSignedInText'); 422 chrome.send('requestSignedInText');
413 chrome.send('requestDefaultProfileIcons'); 423 chrome.send('requestDefaultProfileIcons');
414 chrome.send('requestNewProfileDefaults'); 424 chrome.send('requestNewProfileDefaults');
415 425
416 $('manage-profile-overlay-create').hidden = false; 426 $('manage-profile-overlay-create').hidden = false;
417 $('manage-profile-overlay-manage').hidden = true; 427 $('manage-profile-overlay-manage').hidden = true;
418 $('manage-profile-overlay-delete').hidden = true; 428 $('manage-profile-overlay-delete').hidden = true;
419 $('create-profile-instructions').textContent = 429 $('create-profile-instructions').textContent =
420 loadTimeData.getStringF('createProfileInstructions'); 430 loadTimeData.getStringF('createProfileInstructions');
421 ManageProfileOverlay.getInstance().hideErrorBubble_('create'); 431 this.hideErrorBubble_();
422 432
423 var shortcutsEnabled = loadTimeData.getBoolean('profileShortcutsEnabled'); 433 var shortcutsEnabled = loadTimeData.getBoolean('profileShortcutsEnabled');
424 $('create-shortcut-container').hidden = !shortcutsEnabled; 434 $('create-shortcut-container').hidden = !shortcutsEnabled;
425 $('create-shortcut').checked = shortcutsEnabled; 435 $('create-shortcut').checked = shortcutsEnabled;
426 436
427 $('create-profile-name-label').hidden = true; 437 $('create-profile-name-label').hidden = true;
428 $('create-profile-name').hidden = true; 438 $('create-profile-name').hidden = true;
429 $('create-profile-ok').disabled = true; 439 $('create-profile-ok').disabled = true;
430 }, 440 },
431 441
442 /** @override */
443 showErrorBubble_: function(errorText) {
444 ManageProfileOverlay.getInstance().showErrorBubble_(errorText,
445 'create',
446 false);
447 },
448
449 /** @override */
450 hideErrorBubble_: function() {
451 ManageProfileOverlay.getInstance().hideErrorBubble_('create');
452 },
453
454 /**
455 * Shows an error message describing a local error (most likely a disk
456 * error) when creating a new profile. Called by BrowserOptions via the
457 * BrowserOptionsHandler.
458 * @private
459 */
460 onLocalError_: function() {
461 this.showErrorBubble_('createProfileLocalError');
462 },
463
464 /**
465 * For new limited users, shows a confirmation page after successfully
466 * creating a new profile; otherwise, the handler will open a new window.
467 * @private
468 */
469 onSuccess_: function(is_managed) {
Pam (message me for reviews) 2013/05/27 08:17:25 I will change this to isManaged before committing.
470 OptionsPage.closeOverlay();
471 if (is_managed) {
472 // TODO(pamg): Fill out this stub.
473 console.log('Success - show confirmation');
474 }
475 },
476
432 /** 477 /**
433 * Updates the signed-in or not-signed-in UI when in create mode. Called by 478 * Updates the signed-in or not-signed-in UI when in create mode. Called by
434 * the handler in response to the 'requestSignedInText' message. 479 * the handler in response to the 'requestSignedInText' message.
435 * @param {string} text The text to show for a signed-in user. An empty 480 * @param {string} text The text to show for a signed-in user. An empty
436 * string indicates that the user is not signed in. 481 * string indicates that the user is not signed in.
437 * @private 482 * @private
438 */ 483 */
439 updateSignedInStatus_: function(text) { 484 updateSignedInStatus_: function(text) {
440 var isSignedIn = text !== ''; 485 var isSignedIn = text !== '';
441 $('create-profile-limited-signed-in').hidden = !isSignedIn; 486 $('create-profile-limited-signed-in').hidden = !isSignedIn;
442 $('create-profile-limited-not-signed-in').hidden = isSignedIn; 487 $('create-profile-limited-not-signed-in').hidden = isSignedIn;
443 $('create-profile-limited').disabled = !isSignedIn; 488 $('create-profile-limited').disabled = !isSignedIn;
444 489
445 $('create-profile-limited-signed-in-label').textContent = text; 490 $('create-profile-limited-signed-in-label').textContent = text;
446 }, 491 },
447 }; 492 };
448 493
449 // Forward public APIs to private implementations. 494 // Forward public APIs to private implementations.
450 [ 495 [
496 'onLocalError',
497 'onSuccess',
451 'updateSignedInStatus', 498 'updateSignedInStatus',
452 ].forEach(function(name) { 499 ].forEach(function(name) {
453 CreateProfileOverlay[name] = function() { 500 CreateProfileOverlay[name] = function() {
454 var instance = CreateProfileOverlay.getInstance(); 501 var instance = CreateProfileOverlay.getInstance();
455 return instance[name + '_'].apply(instance, arguments); 502 return instance[name + '_'].apply(instance, arguments);
456 }; 503 };
457 }); 504 });
458 505
459 // Export 506 // Export
460 return { 507 return {
461 ManageProfileOverlay: ManageProfileOverlay, 508 ManageProfileOverlay: ManageProfileOverlay,
462 CreateProfileOverlay: CreateProfileOverlay, 509 CreateProfileOverlay: CreateProfileOverlay,
463 }; 510 };
464 }); 511 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698