| 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 }, | 296 }, |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * Updates the user pod element. | 299 * Updates the user pod element. |
| 300 */ | 300 */ |
| 301 update: function() { | 301 update: function() { |
| 302 this.imageElement.src = 'chrome://userimage/' + this.user.username + | 302 this.imageElement.src = 'chrome://userimage/' + this.user.username + |
| 303 '?id=' + UserPod.userImageSalt_[this.user.username]; | 303 '?id=' + UserPod.userImageSalt_[this.user.username]; |
| 304 | 304 |
| 305 this.nameElement.textContent = this.user_.displayName; | 305 this.nameElement.textContent = this.user_.displayName; |
| 306 this.actionBoxAreaElement.hidden = this.user_.publicAccount; | |
| 307 this.actionBoxMenuRemoveElement.hidden = !this.user_.canRemove; | |
| 308 this.signedInIndicatorElement.hidden = !this.user_.signedIn; | 306 this.signedInIndicatorElement.hidden = !this.user_.signedIn; |
| 309 | 307 |
| 310 var needSignin = this.needGaiaSignin; | 308 var needSignin = this.needGaiaSignin; |
| 311 this.passwordElement.hidden = needSignin; | 309 this.passwordElement.hidden = needSignin; |
| 310 this.signinButtonElement.hidden = !needSignin; |
| 311 |
| 312 this.updateActionBoxArea(); |
| 313 }, |
| 314 |
| 315 updateActionBoxArea: function() { |
| 316 this.actionBoxAreaElement.hidden = this.user_.publicAccount; |
| 317 this.actionBoxMenuRemoveElement.hidden = !this.user_.canRemove; |
| 318 |
| 312 this.actionBoxAreaElement.setAttribute( | 319 this.actionBoxAreaElement.setAttribute( |
| 313 'aria-label', loadTimeData.getStringF( | 320 'aria-label', loadTimeData.getStringF( |
| 314 'podMenuButtonAccessibleName', this.user_.emailAddress)); | 321 'podMenuButtonAccessibleName', this.user_.emailAddress)); |
| 315 this.actionBoxMenuRemoveElement.setAttribute( | 322 this.actionBoxMenuRemoveElement.setAttribute( |
| 316 'aria-label', loadTimeData.getString( | 323 'aria-label', loadTimeData.getString( |
| 317 'podMenuRemoveItemAccessibleName')); | 324 'podMenuRemoveItemAccessibleName')); |
| 318 this.actionBoxMenuTitleNameElement.textContent = this.user_.isOwner ? | 325 this.actionBoxMenuTitleNameElement.textContent = this.user_.isOwner ? |
| 319 loadTimeData.getStringF('ownerUserPattern', this.user_.displayName) : | 326 loadTimeData.getStringF('ownerUserPattern', this.user_.displayName) : |
| 320 this.user_.displayName; | 327 this.user_.displayName; |
| 321 this.actionBoxMenuTitleEmailElement.textContent = this.user_.emailAddress; | 328 this.actionBoxMenuTitleEmailElement.textContent = this.user_.emailAddress; |
| 322 this.actionBoxMenuTitleEmailElement.hidden = | 329 this.actionBoxMenuTitleEmailElement.hidden = |
| 323 this.user_.locallyManagedUser; | 330 this.user_.locallyManagedUser; |
| 324 | 331 |
| 325 this.actionBoxMenuCommandElement.textContent = | 332 this.actionBoxMenuCommandElement.textContent = |
| 326 loadTimeData.getString('removeUser'); | 333 loadTimeData.getString('removeUser'); |
| 327 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( | 334 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( |
| 328 'passwordFieldAccessibleName', this.user_.emailAddress)); | 335 'passwordFieldAccessibleName', this.user_.emailAddress)); |
| 329 this.signinButtonElement.hidden = !needSignin; | |
| 330 this.userTypeIconAreaElement.hidden = !this.user_.locallyManagedUser; | 336 this.userTypeIconAreaElement.hidden = !this.user_.locallyManagedUser; |
| 331 }, | 337 }, |
| 332 | 338 |
| 333 /** | 339 /** |
| 334 * The user that this pod represents. | 340 * The user that this pod represents. |
| 335 * @type {!Object} | 341 * @type {!Object} |
| 336 */ | 342 */ |
| 337 user_: undefined, | 343 user_: undefined, |
| 338 get user() { | 344 get user() { |
| 339 return this.user_; | 345 return this.user_; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 this.actionBoxMenuRemoveElement.tabIndex = -1; | 565 this.actionBoxMenuRemoveElement.tabIndex = -1; |
| 560 }, | 566 }, |
| 561 | 567 |
| 562 /** | 568 /** |
| 563 * Handles mousedown event on a user pod. | 569 * Handles mousedown event on a user pod. |
| 564 * @param {Event} e Mousedown event. | 570 * @param {Event} e Mousedown event. |
| 565 */ | 571 */ |
| 566 handleMouseDown_: function(e) { | 572 handleMouseDown_: function(e) { |
| 567 if (this.parentNode.disabled) | 573 if (this.parentNode.disabled) |
| 568 return; | 574 return; |
| 575 |
| 569 if (!this.signinButtonElement.hidden && !this.isActionBoxMenuActive) { | 576 if (!this.signinButtonElement.hidden && !this.isActionBoxMenuActive) { |
| 570 this.showSigninUI(); | 577 this.showSigninUI(); |
| 571 // Prevent default so that we don't trigger 'focus' event. | 578 // Prevent default so that we don't trigger 'focus' event. |
| 572 e.preventDefault(); | 579 e.preventDefault(); |
| 573 } | 580 } |
| 574 } | 581 } |
| 575 }; | 582 }; |
| 576 | 583 |
| 577 /** | 584 /** |
| 578 * Creates a public account user pod. | 585 * Creates a public account user pod. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 return; | 756 return; |
| 750 } | 757 } |
| 751 break; | 758 break; |
| 752 } | 759 } |
| 753 chrome.send('launchHelpApp', [HELP_TOPIC_PUBLIC_SESSION]); | 760 chrome.send('launchHelpApp', [HELP_TOPIC_PUBLIC_SESSION]); |
| 754 stopEventPropagation(event); | 761 stopEventPropagation(event); |
| 755 }, | 762 }, |
| 756 }; | 763 }; |
| 757 | 764 |
| 758 /** | 765 /** |
| 766 * Creates a user pod to be used only in desktop chrome. |
| 767 * @constructor |
| 768 * @extends {UserPod} |
| 769 */ |
| 770 var DesktopUserPod = cr.ui.define(function() { |
| 771 // Don't just instantiate a UserPod(), as this will call decorate() on the |
| 772 // parent object, and add duplicate event listeners. |
| 773 var node = $('user-pod-template').cloneNode(true); |
| 774 node.removeAttribute('id'); |
| 775 return node; |
| 776 }); |
| 777 |
| 778 DesktopUserPod.prototype = { |
| 779 __proto__: UserPod.prototype, |
| 780 |
| 781 /** @override */ |
| 782 decorate: function() { |
| 783 UserPod.prototype.decorate.call(this); |
| 784 }, |
| 785 |
| 786 /** @override */ |
| 787 focusInput: function() { |
| 788 var isLockedUser = this.user.needsSignin; |
| 789 this.signinButtonElement.hidden = isLockedUser; |
| 790 this.passwordElement.hidden = !isLockedUser; |
| 791 |
| 792 // Move tabIndex from the whole pod to the main input. |
| 793 this.tabIndex = -1; |
| 794 this.mainInput.tabIndex = UserPodTabOrder.POD_INPUT; |
| 795 this.mainInput.focus(); |
| 796 }, |
| 797 |
| 798 /** @override */ |
| 799 update: function() { |
| 800 this.imageElement.src = this.user.userImage; |
| 801 this.nameElement.textContent = this.user_.displayName; |
| 802 var isLockedUser = this.user.needsSignin; |
| 803 this.passwordElement.hidden = !isLockedUser; |
| 804 this.signinButtonElement.hidden = isLockedUser; |
| 805 |
| 806 UserPod.prototype.updateActionBoxArea.call(this); |
| 807 }, |
| 808 |
| 809 /** @override */ |
| 810 activate: function() { |
| 811 Oobe.launchUser(this.user.emailAddress, this.user.displayName); |
| 812 return true; |
| 813 }, |
| 814 |
| 815 /** @override */ |
| 816 handleMouseDown_: function(e) { |
| 817 if (this.parentNode.disabled) |
| 818 return; |
| 819 |
| 820 // Don't sign in until the user presses the button. Just activate the pod. |
| 821 Oobe.clearErrors(); |
| 822 this.parentNode.lastFocusedPod_ = |
| 823 this.parentNode.getPodWithUsername_(this.user.emailAddress); |
| 824 }, |
| 825 |
| 826 /** @override */ |
| 827 handleRemoveCommandClick_: function(e) { |
| 828 //TODO(noms): Add deletion confirmation overlay before attempting |
| 829 // to delete the user. |
| 830 UserPod.prototype.handleRemoveCommandClick_.call(this, e); |
| 831 }, |
| 832 }; |
| 833 |
| 834 /** |
| 759 * Creates a new pod row element. | 835 * Creates a new pod row element. |
| 760 * @constructor | 836 * @constructor |
| 761 * @extends {HTMLDivElement} | 837 * @extends {HTMLDivElement} |
| 762 */ | 838 */ |
| 763 var PodRow = cr.ui.define('podrow'); | 839 var PodRow = cr.ui.define('podrow'); |
| 764 | 840 |
| 765 PodRow.prototype = { | 841 PodRow.prototype = { |
| 766 __proto__: HTMLDivElement.prototype, | 842 __proto__: HTMLDivElement.prototype, |
| 767 | 843 |
| 768 // Whether this user pod row is shown for the first time. | 844 // Whether this user pod row is shown for the first time. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 control.disabled = value; | 930 control.disabled = value; |
| 855 } | 931 } |
| 856 }, | 932 }, |
| 857 | 933 |
| 858 /** | 934 /** |
| 859 * Creates a user pod from given email. | 935 * Creates a user pod from given email. |
| 860 * @param {string} email User's email. | 936 * @param {string} email User's email. |
| 861 */ | 937 */ |
| 862 createUserPod: function(user) { | 938 createUserPod: function(user) { |
| 863 var userPod; | 939 var userPod; |
| 864 if (user.publicAccount) | 940 if (user.isDesktopUser) |
| 941 userPod = new DesktopUserPod({user: user}); |
| 942 else if (user.publicAccount) |
| 865 userPod = new PublicAccountUserPod({user: user}); | 943 userPod = new PublicAccountUserPod({user: user}); |
| 866 else | 944 else |
| 867 userPod = new UserPod({user: user}); | 945 userPod = new UserPod({user: user}); |
| 868 | 946 |
| 869 userPod.hidden = false; | 947 userPod.hidden = false; |
| 870 return userPod; | 948 return userPod; |
| 871 }, | 949 }, |
| 872 | 950 |
| 873 /** | 951 /** |
| 874 * Add an existing user pod to this pod row. | 952 * Add an existing user pod to this pod row. |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 this.classList.remove('images-loading'); | 1481 this.classList.remove('images-loading'); |
| 1404 chrome.send('userImagesLoaded'); | 1482 chrome.send('userImagesLoaded'); |
| 1405 } | 1483 } |
| 1406 } | 1484 } |
| 1407 }; | 1485 }; |
| 1408 | 1486 |
| 1409 return { | 1487 return { |
| 1410 PodRow: PodRow | 1488 PodRow: PodRow |
| 1411 }; | 1489 }; |
| 1412 }); | 1490 }); |
| OLD | NEW |