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

Side by Side Diff: chrome/browser/resources/chromeos/login/user_pod_row.js

Issue 16104008: First try at a user management screen for the desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix linux CrOS browser test Created 7 years, 5 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
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 /** 5 /**
6 * @fileoverview User pod row implementation. 6 * @fileoverview User pod row implementation.
7 */ 7 */
8 8
9 cr.define('login', function() { 9 cr.define('login', function() {
10 /** 10 /**
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 this.handleActionAreaButtonClick_.bind(this)); 147 this.handleActionAreaButtonClick_.bind(this));
148 this.actionBoxAreaElement.addEventListener('keydown', 148 this.actionBoxAreaElement.addEventListener('keydown',
149 this.handleActionAreaButtonKeyDown_.bind(this)); 149 this.handleActionAreaButtonKeyDown_.bind(this));
150 150
151 this.actionBoxMenuRemoveElement.addEventListener('click', 151 this.actionBoxMenuRemoveElement.addEventListener('click',
152 this.handleRemoveCommandClick_.bind(this)); 152 this.handleRemoveCommandClick_.bind(this));
153 this.actionBoxMenuRemoveElement.addEventListener('keydown', 153 this.actionBoxMenuRemoveElement.addEventListener('keydown',
154 this.handleRemoveCommandKeyDown_.bind(this)); 154 this.handleRemoveCommandKeyDown_.bind(this));
155 this.actionBoxMenuRemoveElement.addEventListener('blur', 155 this.actionBoxMenuRemoveElement.addEventListener('blur',
156 this.handleRemoveCommandBlur_.bind(this)); 156 this.handleRemoveCommandBlur_.bind(this));
157 this.actionBoxRemoveManagedUserWarningButtonElement.addEventListener(
158 'click',
159 this.handleRemoveUserConfirmationClick_.bind(this));
160 157
158 if (this.actionBoxRemoveManagedUserWarningButtonElement) {
159 this.actionBoxRemoveManagedUserWarningButtonElement.addEventListener(
160 'click',
161 this.handleRemoveUserConfirmationClick_.bind(this));
162 }
161 }, 163 },
162 164
163 /** 165 /**
164 * Initializes the pod after its properties set and added to a pod row. 166 * Initializes the pod after its properties set and added to a pod row.
165 */ 167 */
166 initialize: function() { 168 initialize: function() {
167 this.passwordElement.addEventListener('keydown', 169 this.passwordElement.addEventListener('keydown',
168 this.parentNode.handleKeyDown.bind(this.parentNode)); 170 this.parentNode.handleKeyDown.bind(this.parentNode));
169 this.passwordElement.addEventListener('keypress', 171 this.passwordElement.addEventListener('keypress',
170 this.handlePasswordKeyPress_.bind(this)); 172 this.handlePasswordKeyPress_.bind(this));
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 }, 327 },
326 328
327 /** 329 /**
328 * Updates the user pod element. 330 * Updates the user pod element.
329 */ 331 */
330 update: function() { 332 update: function() {
331 this.imageElement.src = 'chrome://userimage/' + this.user.username + 333 this.imageElement.src = 'chrome://userimage/' + this.user.username +
332 '?id=' + UserPod.userImageSalt_[this.user.username]; 334 '?id=' + UserPod.userImageSalt_[this.user.username];
333 335
334 this.nameElement.textContent = this.user_.displayName; 336 this.nameElement.textContent = this.user_.displayName;
335 this.actionBoxAreaElement.hidden = this.user_.publicAccount;
336 this.actionBoxMenuRemoveElement.hidden = !this.user_.canRemove;
337 this.signedInIndicatorElement.hidden = !this.user_.signedIn; 337 this.signedInIndicatorElement.hidden = !this.user_.signedIn;
338 338
339 var needSignin = this.needGaiaSignin; 339 var needSignin = this.needGaiaSignin;
340 this.passwordElement.hidden = needSignin; 340 this.passwordElement.hidden = needSignin;
341 this.signinButtonElement.hidden = !needSignin;
342
343 this.updateActionBoxArea();
344 },
345
346 updateActionBoxArea: function() {
347 this.actionBoxAreaElement.hidden = this.user_.publicAccount;
348 this.actionBoxMenuRemoveElement.hidden = !this.user_.canRemove;
349
341 this.actionBoxAreaElement.setAttribute( 350 this.actionBoxAreaElement.setAttribute(
342 'aria-label', loadTimeData.getStringF( 351 'aria-label', loadTimeData.getStringF(
343 'podMenuButtonAccessibleName', this.user_.emailAddress)); 352 'podMenuButtonAccessibleName', this.user_.emailAddress));
344 this.actionBoxMenuRemoveElement.setAttribute( 353 this.actionBoxMenuRemoveElement.setAttribute(
345 'aria-label', loadTimeData.getString( 354 'aria-label', loadTimeData.getString(
346 'podMenuRemoveItemAccessibleName')); 355 'podMenuRemoveItemAccessibleName'));
347 this.actionBoxMenuTitleNameElement.textContent = this.user_.isOwner ? 356 this.actionBoxMenuTitleNameElement.textContent = this.user_.isOwner ?
348 loadTimeData.getStringF('ownerUserPattern', this.user_.displayName) : 357 loadTimeData.getStringF('ownerUserPattern', this.user_.displayName) :
349 this.user_.displayName; 358 this.user_.displayName;
350 this.actionBoxMenuTitleEmailElement.textContent = this.user_.emailAddress; 359 this.actionBoxMenuTitleEmailElement.textContent = this.user_.emailAddress;
351 this.actionBoxMenuTitleEmailElement.hidden = 360 this.actionBoxMenuTitleEmailElement.hidden =
352 this.user_.locallyManagedUser; 361 this.user_.locallyManagedUser;
353 362
354 this.actionBoxMenuCommandElement.textContent = 363 this.actionBoxMenuCommandElement.textContent =
355 loadTimeData.getString('removeUser'); 364 loadTimeData.getString('removeUser');
356 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( 365 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF(
357 'passwordFieldAccessibleName', this.user_.emailAddress)); 366 'passwordFieldAccessibleName', this.user_.emailAddress));
358 this.signinButtonElement.hidden = !needSignin;
359 this.userTypeIconAreaElement.hidden = !this.user_.locallyManagedUser; 367 this.userTypeIconAreaElement.hidden = !this.user_.locallyManagedUser;
360 }, 368 },
361 369
362 /** 370 /**
363 * The user that this pod represents. 371 * The user that this pod represents.
364 * @type {!Object} 372 * @type {!Object}
365 */ 373 */
366 user_: undefined, 374 user_: undefined,
367 get user() { 375 get user() {
368 return this.user_; 376 return this.user_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 */ 409 */
402 get isActionBoxMenuActive() { 410 get isActionBoxMenuActive() {
403 return this.actionBoxAreaElement.classList.contains('active'); 411 return this.actionBoxAreaElement.classList.contains('active');
404 }, 412 },
405 set isActionBoxMenuActive(active) { 413 set isActionBoxMenuActive(active) {
406 if (active == this.isActionBoxMenuActive) 414 if (active == this.isActionBoxMenuActive)
407 return; 415 return;
408 416
409 if (active) { 417 if (active) {
410 this.actionBoxMenuRemoveElement.hidden = !this.user_.canRemove; 418 this.actionBoxMenuRemoveElement.hidden = !this.user_.canRemove;
411 this.actionBoxRemoveManagedUserWarningElement.hidden = true; 419 if (this.actionBoxRemoveManagedUserWarningElement)
420 this.actionBoxRemoveManagedUserWarningElement.hidden = true;
412 421
413 // Clear focus first if another pod is focused. 422 // Clear focus first if another pod is focused.
414 if (!this.parentNode.isFocused(this)) { 423 if (!this.parentNode.isFocused(this)) {
415 this.parentNode.focusPod(undefined, true); 424 this.parentNode.focusPod(undefined, true);
416 this.actionBoxAreaElement.focus(); 425 this.actionBoxAreaElement.focus();
417 } 426 }
418 this.actionBoxAreaElement.classList.add('active'); 427 this.actionBoxAreaElement.classList.add('active');
419 } else { 428 } else {
420 this.actionBoxAreaElement.classList.remove('active'); 429 this.actionBoxAreaElement.classList.remove('active');
421 } 430 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 this.actionBoxMenuRemoveElement.tabIndex = -1; 621 this.actionBoxMenuRemoveElement.tabIndex = -1;
613 }, 622 },
614 623
615 /** 624 /**
616 * Handles mousedown event on a user pod. 625 * Handles mousedown event on a user pod.
617 * @param {Event} e Mousedown event. 626 * @param {Event} e Mousedown event.
618 */ 627 */
619 handleMouseDown_: function(e) { 628 handleMouseDown_: function(e) {
620 if (this.parentNode.disabled) 629 if (this.parentNode.disabled)
621 return; 630 return;
631
622 if (!this.signinButtonElement.hidden && !this.isActionBoxMenuActive) { 632 if (!this.signinButtonElement.hidden && !this.isActionBoxMenuActive) {
623 this.showSigninUI(); 633 this.showSigninUI();
624 // Prevent default so that we don't trigger 'focus' event. 634 // Prevent default so that we don't trigger 'focus' event.
625 e.preventDefault(); 635 e.preventDefault();
626 } 636 }
627 } 637 }
628 }; 638 };
629 639
630 /** 640 /**
631 * Creates a public account user pod. 641 * Creates a public account user pod.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 return; 812 return;
803 } 813 }
804 break; 814 break;
805 } 815 }
806 chrome.send('launchHelpApp', [HELP_TOPIC_PUBLIC_SESSION]); 816 chrome.send('launchHelpApp', [HELP_TOPIC_PUBLIC_SESSION]);
807 stopEventPropagation(event); 817 stopEventPropagation(event);
808 }, 818 },
809 }; 819 };
810 820
811 /** 821 /**
822 * Creates a user pod to be used only in desktop chrome.
823 * @constructor
824 * @extends {UserPod}
825 */
826 var DesktopUserPod = cr.ui.define(function() {
827 // Don't just instantiate a UserPod(), as this will call decorate() on the
828 // parent object, and add duplicate event listeners.
829 var node = $('user-pod-template').cloneNode(true);
830 node.removeAttribute('id');
831 return node;
832 });
833
834 DesktopUserPod.prototype = {
835 __proto__: UserPod.prototype,
836
837 /** @override */
838 decorate: function() {
839 UserPod.prototype.decorate.call(this);
840 },
841
842 /** @override */
843 focusInput: function() {
844 var isLockedUser = this.user.needsSignin;
845 this.signinButtonElement.hidden = isLockedUser;
846 this.passwordElement.hidden = !isLockedUser;
847
848 // Move tabIndex from the whole pod to the main input.
849 this.tabIndex = -1;
850 this.mainInput.tabIndex = UserPodTabOrder.POD_INPUT;
851 this.mainInput.focus();
852 },
853
854 /** @override */
855 update: function() {
856 // TODO(noms): Use the actual profile avatar for local profiles once the
857 // new, non-pixellated avatars are available.
858 this.imageElement.src = this.user.emailAddress == '' ?
859 'chrome://theme/IDR_USER_MANAGER_DEFAULT_AVATAR' :
860 this.user.userImage;
861 this.nameElement.textContent = this.user_.displayName;
862 var isLockedUser = this.user.needsSignin;
863 this.passwordElement.hidden = !isLockedUser;
864 this.signinButtonElement.hidden = isLockedUser;
865
866 UserPod.prototype.updateActionBoxArea.call(this);
867 },
868
869 /** @override */
870 activate: function() {
871 Oobe.launchUser(this.user.emailAddress, this.user.displayName);
872 return true;
873 },
874
875 /** @override */
876 handleMouseDown_: function(e) {
877 if (this.parentNode.disabled)
878 return;
879
880 // Don't sign in until the user presses the button. Just activate the pod.
881 Oobe.clearErrors();
882 this.parentNode.lastFocusedPod_ =
883 this.parentNode.getPodWithUsername_(this.user.emailAddress);
884 },
885
886 /** @override */
887 handleRemoveCommandClick_: function(e) {
888 //TODO(noms): Add deletion confirmation overlay before attempting
889 // to delete the user.
890 UserPod.prototype.handleRemoveCommandClick_.call(this, e);
891 },
892 };
893
894 /**
812 * Creates a new pod row element. 895 * Creates a new pod row element.
813 * @constructor 896 * @constructor
814 * @extends {HTMLDivElement} 897 * @extends {HTMLDivElement}
815 */ 898 */
816 var PodRow = cr.ui.define('podrow'); 899 var PodRow = cr.ui.define('podrow');
817 900
818 PodRow.prototype = { 901 PodRow.prototype = {
819 __proto__: HTMLDivElement.prototype, 902 __proto__: HTMLDivElement.prototype,
820 903
821 // Whether this user pod row is shown for the first time. 904 // Whether this user pod row is shown for the first time.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 control.disabled = value; 990 control.disabled = value;
908 } 991 }
909 }, 992 },
910 993
911 /** 994 /**
912 * Creates a user pod from given email. 995 * Creates a user pod from given email.
913 * @param {string} email User's email. 996 * @param {string} email User's email.
914 */ 997 */
915 createUserPod: function(user) { 998 createUserPod: function(user) {
916 var userPod; 999 var userPod;
917 if (user.publicAccount) 1000 if (user.isDesktopUser)
1001 userPod = new DesktopUserPod({user: user});
1002 else if (user.publicAccount)
918 userPod = new PublicAccountUserPod({user: user}); 1003 userPod = new PublicAccountUserPod({user: user});
919 else 1004 else
920 userPod = new UserPod({user: user}); 1005 userPod = new UserPod({user: user});
921 1006
922 userPod.hidden = false; 1007 userPod.hidden = false;
923 return userPod; 1008 return userPod;
924 }, 1009 },
925 1010
926 /** 1011 /**
927 * Add an existing user pod to this pod row. 1012 * Add an existing user pod to this pod row.
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 this.classList.remove('images-loading'); 1541 this.classList.remove('images-loading');
1457 chrome.send('userImagesLoaded'); 1542 chrome.send('userImagesLoaded');
1458 } 1543 }
1459 } 1544 }
1460 }; 1545 };
1461 1546
1462 return { 1547 return {
1463 PodRow: PodRow 1548 PodRow: PodRow
1464 }; 1549 };
1465 }); 1550 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698