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

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

Issue 532023003: [Profiles] Trim profile names in chrome://settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Page = cr.ui.pageManager.Page; 6 var Page = cr.ui.pageManager.Page;
7 var PageManager = cr.ui.pageManager.PageManager; 7 var PageManager = cr.ui.pageManager.PageManager;
8 var ArrayDataModel = cr.ui.ArrayDataModel; 8 var ArrayDataModel = cr.ui.ArrayDataModel;
9 9
10 /** 10 /**
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 387 }
388 var self = this; 388 var self = this;
389 function getImportHandler(supervisedUser, nameIsUnique) { 389 function getImportHandler(supervisedUser, nameIsUnique) {
390 return function() { 390 return function() {
391 if (supervisedUser.needAvatar || !nameIsUnique) { 391 if (supervisedUser.needAvatar || !nameIsUnique) {
392 PageManager.showPageByName('supervisedUserImport'); 392 PageManager.showPageByName('supervisedUserImport');
393 } else { 393 } else {
394 self.hideErrorBubble_('create'); 394 self.hideErrorBubble_('create');
395 CreateProfileOverlay.updateCreateInProgress(true); 395 CreateProfileOverlay.updateCreateInProgress(true);
396 chrome.send('createProfile', 396 chrome.send('createProfile',
397 [supervisedUser.name, supervisedUser.iconURL, false, true, 397 [supervisedUser.name.trim(), supervisedUser.iconURL,
398 supervisedUser.id]); 398 false, true, supervisedUser.id]);
399 } 399 }
400 } 400 }
401 }; 401 };
402 $('supervised-user-import-existing').onclick = 402 $('supervised-user-import-existing').onclick =
403 getImportHandler(supervisedUsers[i], nameIsUnique); 403 getImportHandler(supervisedUsers[i], nameIsUnique);
404 $('create-profile-ok').disabled = true; 404 $('create-profile-ok').disabled = true;
405 return; 405 return;
406 } 406 }
407 } 407 }
408 }, 408 },
409 409
410 /** 410 /**
411 * Called in case the request for the list of supervised users fails because 411 * Called in case the request for the list of supervised users fails because
412 * of a signin error. 412 * of a signin error.
413 * @private 413 * @private
414 */ 414 */
415 onSigninError_: function() { 415 onSigninError_: function() {
416 this.updateSignedInStatus_(this.signedInEmail_, true); 416 this.updateSignedInStatus_(this.signedInEmail_, true);
417 }, 417 },
418 418
419 /** 419 /**
420 * Called to update the state of the ok button depending if the name is 420 * Called to update the state of the ok button depending if the name is
421 * already used or not. 421 * already used or not.
422 * @param {string} mode A label that specifies the type of dialog box which 422 * @param {string} mode A label that specifies the type of dialog box which
423 * is currently being viewed (i.e. 'create' or 'manage'). 423 * is currently being viewed (i.e. 'create' or 'manage').
424 * @private 424 * @private
425 */ 425 */
426 updateOkButton_: function(mode) { 426 updateOkButton_: function(mode) {
427 var nameElement = $(mode + '-profile-name');
Dan Beam 2014/09/04 23:06:07 nit: move a line lower (right above first use)
427 var oldName = this.profileInfo_.name; 428 var oldName = this.profileInfo_.name;
428 var newName = $(mode + '-profile-name').value; 429 var newName = nameElement.value;
429 var nameIsDuplicate = this.existingProfileNames_[newName] != undefined; 430 var nameIsDuplicate = this.existingProfileNames_[newName] != undefined;
430 if (mode == 'manage' && oldName == newName) 431 if (mode == 'manage' && oldName == newName)
431 nameIsDuplicate = false; 432 nameIsDuplicate = false;
433
432 if (nameIsDuplicate) { 434 if (nameIsDuplicate) {
433 var errorHtml = 435 var errorHtml =
434 loadTimeData.getString('manageProfilesDuplicateNameError'); 436 loadTimeData.getString('manageProfilesDuplicateNameError');
435 this.showErrorBubble_(errorHtml, mode, true); 437 this.showErrorBubble_(errorHtml, mode, true);
436 } else { 438 } else {
437 this.hideErrorBubble_(mode); 439 this.hideErrorBubble_(mode);
438 440
439 var nameIsValid = $(mode + '-profile-name').validity.valid; 441 // A name containing all spaces is not valid.
442 nameElement.setCustomValidity(newName.trim() == '' ? ' ' : '');
443
444 var nameIsValid = nameElement.validity.valid;
440 $(mode + '-profile-ok').disabled = !nameIsValid; 445 $(mode + '-profile-ok').disabled = !nameIsValid;
441 } 446 }
442 }, 447 },
443 448
444 /** 449 /**
445 * Called when the user clicks "OK" or hits enter. Saves the newly changed 450 * Called when the user clicks "OK" or hits enter. Saves the newly changed
446 * profile info. 451 * profile info.
447 * @private 452 * @private
448 */ 453 */
449 submitManageChanges_: function() { 454 submitManageChanges_: function() {
450 var name = $('manage-profile-name').value; 455 var name = $('manage-profile-name').value.trim();
451 var iconURL = $('manage-profile-icon-grid').selectedItem; 456 var iconURL = $('manage-profile-icon-grid').selectedItem;
452 457
453 chrome.send('setProfileIconAndName', 458 chrome.send('setProfileIconAndName',
454 [this.profileInfo_.filePath, iconURL, name]); 459 [this.profileInfo_.filePath, iconURL, name]);
455 if (name != this.profileInfo_.name) 460 if (name != this.profileInfo_.name)
456 options.SupervisedUserListData.resetPromise(); 461 options.SupervisedUserListData.resetPromise();
457 }, 462 },
458 463
459 /** 464 /**
460 * Called when the user clicks "OK" or hits enter. Creates the profile 465 * Called when the user clicks "OK" or hits enter. Creates the profile
(...skipping 12 matching lines...) Expand all
473 // Get the user's chosen name and icon, or default if they do not 478 // Get the user's chosen name and icon, or default if they do not
474 // wish to customize their profile. 479 // wish to customize their profile.
475 var name = $('create-profile-name').value; 480 var name = $('create-profile-name').value;
476 var iconUrl = $('create-profile-icon-grid').selectedItem; 481 var iconUrl = $('create-profile-icon-grid').selectedItem;
477 var createShortcut = $('create-shortcut').checked; 482 var createShortcut = $('create-shortcut').checked;
478 var isSupervised = $('create-profile-supervised').checked; 483 var isSupervised = $('create-profile-supervised').checked;
479 var existingSupervisedUserId = ''; 484 var existingSupervisedUserId = '';
480 485
481 // 'createProfile' is handled by the CreateProfileHandler. 486 // 'createProfile' is handled by the CreateProfileHandler.
482 chrome.send('createProfile', 487 chrome.send('createProfile',
483 [name, iconUrl, createShortcut, 488 [name.trim(), iconUrl, createShortcut,
484 isSupervised, existingSupervisedUserId]); 489 isSupervised, existingSupervisedUserId]);
485 }, 490 },
486 491
487 /** 492 /**
488 * Called when the selected icon in the icon grid changes. 493 * Called when the selected icon in the icon grid changes.
489 * @param {string} mode A label that specifies the type of dialog box which 494 * @param {string} mode A label that specifies the type of dialog box which
490 * is currently being viewed (i.e. 'create' or 'manage'). 495 * is currently being viewed (i.e. 'create' or 'manage').
491 * @private 496 * @private
492 */ 497 */
493 onIconGridSelectionChanged_: function(mode) { 498 onIconGridSelectionChanged_: function(mode) {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 return instance[name + '_'].apply(instance, arguments); 867 return instance[name + '_'].apply(instance, arguments);
863 }; 868 };
864 }); 869 });
865 870
866 // Export 871 // Export
867 return { 872 return {
868 ManageProfileOverlay: ManageProfileOverlay, 873 ManageProfileOverlay: ManageProfileOverlay,
869 CreateProfileOverlay: CreateProfileOverlay, 874 CreateProfileOverlay: CreateProfileOverlay,
870 }; 875 };
871 }); 876 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698