| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Pod width. 170px Pod + 10px padding + 10px margin on both sides. | 10 // Pod width. 170px Pod + 10px padding + 10px margin on both sides. |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 */ | 214 */ |
| 215 user_: undefined, | 215 user_: undefined, |
| 216 get user() { | 216 get user() { |
| 217 return this.user_; | 217 return this.user_; |
| 218 }, | 218 }, |
| 219 set user(userDict) { | 219 set user(userDict) { |
| 220 this.user_ = userDict; | 220 this.user_ = userDict; |
| 221 | 221 |
| 222 this.updateUserImage(); | 222 this.updateUserImage(); |
| 223 | 223 |
| 224 this.nameElement.textContent = userDict.name; | 224 this.nameElement.textContent = userDict.displayName; |
| 225 this.removeUserButtonElement.hidden = !userDict.canRemove; | 225 this.removeUserButtonElement.hidden = !userDict.canRemove; |
| 226 this.signedInIndicatorElement.hidden = !userDict.signedIn; | 226 this.signedInIndicatorElement.hidden = !userDict.signedIn; |
| 227 | 227 |
| 228 if (this.isGuest) { | 228 if (this.isGuest) { |
| 229 this.imageElement.title = userDict.name; | 229 this.imageElement.title = userDict.displayName; |
| 230 this.enterButtonElement.hidden = false; | 230 this.enterButtonElement.hidden = false; |
| 231 this.passwordElement.hidden = true; | 231 this.passwordElement.hidden = true; |
| 232 this.signinButtonElement.hidden = true; | 232 this.signinButtonElement.hidden = true; |
| 233 } else { | 233 } else { |
| 234 var needSignin = this.needGaiaSignin; | 234 var needSignin = this.needGaiaSignin; |
| 235 this.imageElement.title = userDict.emailAddress; | 235 this.imageElement.title = userDict.nameTooltip || ''; |
| 236 this.enterButtonElement.hidden = true; | 236 this.enterButtonElement.hidden = true; |
| 237 this.passwordElement.hidden = needSignin; | 237 this.passwordElement.hidden = needSignin; |
| 238 this.removeUserButtonElement.setAttribute( | 238 this.removeUserButtonElement.setAttribute( |
| 239 'aria-label', localStrings.getStringF('removeButtonAccessibleName', | 239 'aria-label', localStrings.getStringF('removeButtonAccessibleName', |
| 240 userDict.emailAddress)); | 240 userDict.emailAddress)); |
| 241 this.passwordElement.setAttribute('aria-label', | 241 this.passwordElement.setAttribute('aria-label', |
| 242 localStrings.getStringF( | 242 localStrings.getStringF( |
| 243 'passwordFieldAccessibleName', | 243 'passwordFieldAccessibleName', |
| 244 userDict.emailAddress)); | 244 userDict.emailAddress)); |
| 245 this.signinButtonElement.hidden = !needSignin; | 245 this.signinButtonElement.hidden = !needSignin; |
| 246 } | 246 } |
| 247 }, | 247 }, |
| 248 | 248 |
| 249 /** | 249 /** |
| 250 * Whether we are a guest pod or not. | 250 * Whether we are a guest pod or not. |
| 251 * @type {boolean} | 251 * @type {boolean} |
| 252 */ | 252 */ |
| 253 get isGuest() { | 253 get isGuest() { |
| 254 return !this.user.emailAddress; | 254 return !this.user.username; |
| 255 }, | 255 }, |
| 256 | 256 |
| 257 /** | 257 /** |
| 258 * Whether Gaia signin is required for a non-guest user. | 258 * Whether Gaia signin is required for a non-guest user. |
| 259 */ | 259 */ |
| 260 get needGaiaSignin() { | 260 get needGaiaSignin() { |
| 261 // Gaia signin is performed if we are using gaia extenstion for signin, | 261 // Gaia signin is performed if we are using gaia extenstion for signin, |
| 262 // the user has an invalid oauth token and device is online and the | 262 // the user has an invalid oauth token and device is online and the |
| 263 // user is not currently signed in (i.e. not the lock screen). | 263 // user is not currently signed in (i.e. not the lock screen). |
| 264 return localStrings.getString('authType') == 'ext' && | 264 return localStrings.getString('authType') == 'ext' && |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 set passwordEmpty(empty) { | 308 set passwordEmpty(empty) { |
| 309 this.passwordElement.classList[empty ? 'add' : 'remove']('empty'); | 309 this.passwordElement.classList[empty ? 'add' : 'remove']('empty'); |
| 310 }, | 310 }, |
| 311 | 311 |
| 312 /** | 312 /** |
| 313 * Updates the image element of the user. | 313 * Updates the image element of the user. |
| 314 */ | 314 */ |
| 315 updateUserImage: function() { | 315 updateUserImage: function() { |
| 316 this.imageElement.src = this.isGuest ? | 316 this.imageElement.src = this.isGuest ? |
| 317 'chrome://theme/IDR_LOGIN_GUEST' : | 317 'chrome://theme/IDR_LOGIN_GUEST' : |
| 318 'chrome://userimage/' + this.user.emailAddress + | 318 'chrome://userimage/' + this.user.username + |
| 319 '?id=' + (new Date()).getTime(); | 319 '?id=' + (new Date()).getTime(); |
| 320 }, | 320 }, |
| 321 | 321 |
| 322 /** | 322 /** |
| 323 * Focuses on input element. | 323 * Focuses on input element. |
| 324 */ | 324 */ |
| 325 focusInput: function() { | 325 focusInput: function() { |
| 326 if (!this.isGuest) { | 326 if (!this.isGuest) { |
| 327 var needSignin = this.needGaiaSignin; | 327 var needSignin = this.needGaiaSignin; |
| 328 this.signinButtonElement.hidden = !needSignin; | 328 this.signinButtonElement.hidden = !needSignin; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 342 if (this.isGuest) { | 342 if (this.isGuest) { |
| 343 chrome.send('launchIncognito'); | 343 chrome.send('launchIncognito'); |
| 344 } else if (!this.signinButtonElement.hidden) { | 344 } else if (!this.signinButtonElement.hidden) { |
| 345 // Switch to Gaia signin. | 345 // Switch to Gaia signin. |
| 346 if (!this.needGaiaSignin) { | 346 if (!this.needGaiaSignin) { |
| 347 // Network may go offline in time period between the pod is focused | 347 // Network may go offline in time period between the pod is focused |
| 348 // and the button is pressed, in which case fallback to offline login. | 348 // and the button is pressed, in which case fallback to offline login. |
| 349 this.focusInput(); | 349 this.focusInput(); |
| 350 return false; | 350 return false; |
| 351 } | 351 } |
| 352 this.parentNode.showSigninUI(this.user.emailAddress); | 352 this.showSigninUI(); |
| 353 } else if (!this.passwordElement.value) { | 353 } else if (!this.passwordElement.value) { |
| 354 return false; | 354 return false; |
| 355 } else { | 355 } else { |
| 356 chrome.send('authenticateUser', | 356 chrome.send('authenticateUser', |
| 357 [this.user.emailAddress, this.passwordElement.value]); | 357 [this.user.username, this.passwordElement.value]); |
| 358 } | 358 } |
| 359 | 359 |
| 360 return true; | 360 return true; |
| 361 }, | 361 }, |
| 362 | 362 |
| 363 /** | 363 /** |
| 364 * Shows signin UI for this user. |
| 365 */ |
| 366 showSigninUI: function() { |
| 367 this.parentNode.showSigninUI(this.user.emailAddress); |
| 368 }, |
| 369 |
| 370 /** |
| 364 * Resets the input field and updates the tab order of pod controls. | 371 * Resets the input field and updates the tab order of pod controls. |
| 365 * @param {boolean} takeFocus If true, input field takes focus. | 372 * @param {boolean} takeFocus If true, input field takes focus. |
| 366 */ | 373 */ |
| 367 reset: function(takeFocus) { | 374 reset: function(takeFocus) { |
| 368 this.passwordElement.value = ''; | 375 this.passwordElement.value = ''; |
| 369 if (takeFocus) | 376 if (takeFocus) |
| 370 this.focusInput(); // This will set a custom tab order. | 377 this.focusInput(); // This will set a custom tab order. |
| 371 else | 378 else |
| 372 this.resetTabOrder(); | 379 this.resetTabOrder(); |
| 373 }, | 380 }, |
| 374 | 381 |
| 375 /** | 382 /** |
| 376 * Handles mouseout and blur on remove button. | 383 * Handles mouseout and blur on remove button. |
| 377 * @param {Event} e Mouseout or blur event. | 384 * @param {Event} e Mouseout or blur event. |
| 378 */ | 385 */ |
| 379 handleRemoveButtonMouseOutOrBlur_: function(e) { | 386 handleRemoveButtonMouseOutOrBlur_: function(e) { |
| 380 this.activeRemoveButton = false; | 387 this.activeRemoveButton = false; |
| 381 }, | 388 }, |
| 382 | 389 |
| 383 /** | 390 /** |
| 384 * Handles a click event on remove user button. | 391 * Handles a click event on remove user button. |
| 385 * @param {Event} e Click event. | 392 * @param {Event} e Click event. |
| 386 */ | 393 */ |
| 387 handleRemoveButtonClick_: function(e) { | 394 handleRemoveButtonClick_: function(e) { |
| 388 if (this.parentNode.disabled) | 395 if (this.parentNode.disabled) |
| 389 return; | 396 return; |
| 390 if (this.activeRemoveButton) | 397 if (this.activeRemoveButton) |
| 391 chrome.send('removeUser', [this.user.emailAddress]); | 398 chrome.send('removeUser', [this.user.username]); |
| 392 else | 399 else |
| 393 this.activeRemoveButton = true; | 400 this.activeRemoveButton = true; |
| 394 }, | 401 }, |
| 395 | 402 |
| 396 /** | 403 /** |
| 397 * Handles mousedown event on a user pod. | 404 * Handles mousedown event on a user pod. |
| 398 * @param {Event} e Mouseout event. | 405 * @param {Event} e Mouseout event. |
| 399 */ | 406 */ |
| 400 handleMouseDown_: function(e) { | 407 handleMouseDown_: function(e) { |
| 401 if (this.parentNode.disabled) | 408 if (this.parentNode.disabled) |
| 402 return; | 409 return; |
| 403 if (!this.signinButtonElement.hidden) { | 410 if (!this.signinButtonElement.hidden) { |
| 404 this.parentNode.showSigninUI(this.user.emailAddress); | 411 this.showSigninUI(); |
| 405 // Prevent default so that we don't trigger 'focus' event. | 412 // Prevent default so that we don't trigger 'focus' event. |
| 406 e.preventDefault(); | 413 e.preventDefault(); |
| 407 } | 414 } |
| 408 } | 415 } |
| 409 }; | 416 }; |
| 410 | 417 |
| 411 | 418 |
| 412 /** | 419 /** |
| 413 * Creates a new pod row element. | 420 * Creates a new pod row element. |
| 414 * @constructor | 421 * @constructor |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 * Shows signin UI. | 645 * Shows signin UI. |
| 639 * @param {string} email Email for signin UI. | 646 * @param {string} email Email for signin UI. |
| 640 */ | 647 */ |
| 641 showSigninUI: function(email) { | 648 showSigninUI: function(email) { |
| 642 this.disabled = true; | 649 this.disabled = true; |
| 643 Oobe.showSigninUI(email); | 650 Oobe.showSigninUI(email); |
| 644 }, | 651 }, |
| 645 | 652 |
| 646 /** | 653 /** |
| 647 * Updates current image of a user. | 654 * Updates current image of a user. |
| 648 * @param {string} email Email of the user for which to update the image. | 655 * @param {string} username User for which to update the image. |
| 649 * @public | 656 * @public |
| 650 */ | 657 */ |
| 651 updateUserImage: function(email) { | 658 updateUserImage: function(username) { |
| 652 for (var i = 0, pod; pod = this.pods[i]; ++i) { | 659 for (var i = 0, pod; pod = this.pods[i]; ++i) { |
| 653 if (pod.user.emailAddress == email) { | 660 if (pod.user.username == username) { |
| 654 pod.updateUserImage(); | 661 pod.updateUserImage(); |
| 655 return; | 662 return; |
| 656 } | 663 } |
| 657 } | 664 } |
| 658 }, | 665 }, |
| 659 | 666 |
| 660 /** | 667 /** |
| 661 * Handler of click event. | 668 * Handler of click event. |
| 662 * @param {Event} e Click Event object. | 669 * @param {Event} e Click Event object. |
| 663 * @private | 670 * @private |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 event, this.listeners_[event][0], this.listeners_[event][1]); | 765 event, this.listeners_[event][0], this.listeners_[event][1]); |
| 759 } | 766 } |
| 760 $('login-header-bar').buttonsTabIndex = 0; | 767 $('login-header-bar').buttonsTabIndex = 0; |
| 761 } | 768 } |
| 762 }; | 769 }; |
| 763 | 770 |
| 764 return { | 771 return { |
| 765 PodRow: PodRow | 772 PodRow: PodRow |
| 766 }; | 773 }; |
| 767 }); | 774 }); |
| OLD | NEW |