| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 this.imageElement.src = this.user.userImage; |
| 857 this.nameElement.textContent = this.user_.displayName; |
| 858 var isLockedUser = this.user.needsSignin; |
| 859 this.passwordElement.hidden = !isLockedUser; |
| 860 this.signinButtonElement.hidden = isLockedUser; |
| 861 |
| 862 UserPod.prototype.updateActionBoxArea.call(this); |
| 863 }, |
| 864 |
| 865 /** @override */ |
| 866 activate: function() { |
| 867 Oobe.launchUser(this.user.emailAddress, this.user.displayName); |
| 868 return true; |
| 869 }, |
| 870 |
| 871 /** @override */ |
| 872 handleMouseDown_: function(e) { |
| 873 if (this.parentNode.disabled) |
| 874 return; |
| 875 |
| 876 // Don't sign in until the user presses the button. Just activate the pod. |
| 877 Oobe.clearErrors(); |
| 878 this.parentNode.lastFocusedPod_ = |
| 879 this.parentNode.getPodWithUsername_(this.user.emailAddress); |
| 880 }, |
| 881 |
| 882 /** @override */ |
| 883 handleRemoveCommandClick_: function(e) { |
| 884 //TODO(noms): Add deletion confirmation overlay before attempting |
| 885 // to delete the user. |
| 886 UserPod.prototype.handleRemoveCommandClick_.call(this, e); |
| 887 }, |
| 888 }; |
| 889 |
| 890 /** |
| 812 * Creates a new pod row element. | 891 * Creates a new pod row element. |
| 813 * @constructor | 892 * @constructor |
| 814 * @extends {HTMLDivElement} | 893 * @extends {HTMLDivElement} |
| 815 */ | 894 */ |
| 816 var PodRow = cr.ui.define('podrow'); | 895 var PodRow = cr.ui.define('podrow'); |
| 817 | 896 |
| 818 PodRow.prototype = { | 897 PodRow.prototype = { |
| 819 __proto__: HTMLDivElement.prototype, | 898 __proto__: HTMLDivElement.prototype, |
| 820 | 899 |
| 821 // Whether this user pod row is shown for the first time. | 900 // Whether this user pod row is shown for the first time. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 control.disabled = value; | 986 control.disabled = value; |
| 908 } | 987 } |
| 909 }, | 988 }, |
| 910 | 989 |
| 911 /** | 990 /** |
| 912 * Creates a user pod from given email. | 991 * Creates a user pod from given email. |
| 913 * @param {string} email User's email. | 992 * @param {string} email User's email. |
| 914 */ | 993 */ |
| 915 createUserPod: function(user) { | 994 createUserPod: function(user) { |
| 916 var userPod; | 995 var userPod; |
| 917 if (user.publicAccount) | 996 if (user.isDesktopUser) |
| 997 userPod = new DesktopUserPod({user: user}); |
| 998 else if (user.publicAccount) |
| 918 userPod = new PublicAccountUserPod({user: user}); | 999 userPod = new PublicAccountUserPod({user: user}); |
| 919 else | 1000 else |
| 920 userPod = new UserPod({user: user}); | 1001 userPod = new UserPod({user: user}); |
| 921 | 1002 |
| 922 userPod.hidden = false; | 1003 userPod.hidden = false; |
| 923 return userPod; | 1004 return userPod; |
| 924 }, | 1005 }, |
| 925 | 1006 |
| 926 /** | 1007 /** |
| 927 * Add an existing user pod to this pod row. | 1008 * Add an existing user pod to this pod row. |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 this.classList.remove('images-loading'); | 1537 this.classList.remove('images-loading'); |
| 1457 chrome.send('userImagesLoaded'); | 1538 chrome.send('userImagesLoaded'); |
| 1458 } | 1539 } |
| 1459 } | 1540 } |
| 1460 }; | 1541 }; |
| 1461 | 1542 |
| 1462 return { | 1543 return { |
| 1463 PodRow: PodRow | 1544 PodRow: PodRow |
| 1464 }; | 1545 }; |
| 1465 }); | 1546 }); |
| OLD | NEW |