| 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 Oobe signin screen implementation. | 6 * @fileoverview Oobe signin screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('login', function() { | 9 cr.define('login', function() { |
| 10 /** | 10 /** |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 var screen = $('signin'); | 25 var screen = $('signin'); |
| 26 SigninScreen.decorate(screen); | 26 SigninScreen.decorate(screen); |
| 27 Oobe.getInstance().registerScreen(screen); | 27 Oobe.getInstance().registerScreen(screen); |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 SigninScreen.prototype = { | 30 SigninScreen.prototype = { |
| 31 __proto__: HTMLDivElement.prototype, | 31 __proto__: HTMLDivElement.prototype, |
| 32 | 32 |
| 33 /** @inheritDoc */ | 33 /** @inheritDoc */ |
| 34 decorate: function() { | 34 decorate: function() { |
| 35 $('email').addEventListener('keydown', this.handleKeyDown_.bind(this)); |
| 36 $('password').addEventListener('keydown', this.handleKeyDown_.bind(this)); |
| 35 }, | 37 }, |
| 36 | 38 |
| 37 /** | 39 /** |
| 38 * Header text of the screen. | 40 * Header text of the screen. |
| 39 * @type {string} | 41 * @type {string} |
| 40 */ | 42 */ |
| 41 get header() { | 43 get header() { |
| 42 return localStrings.getString('signinScreenTitle'); | 44 return localStrings.getString('signinScreenTitle'); |
| 43 }, | 45 }, |
| 44 | 46 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 * Clears input fields and switches to input mode. | 88 * Clears input fields and switches to input mode. |
| 87 */ | 89 */ |
| 88 reset: function() { | 90 reset: function() { |
| 89 $('email').value = ''; | 91 $('email').value = ''; |
| 90 $('password').value = ''; | 92 $('password').value = ''; |
| 91 $('email').focus(); | 93 $('email').focus(); |
| 92 this.state = SigninScreen.STATE_INPUT; | 94 this.state = SigninScreen.STATE_INPUT; |
| 93 }, | 95 }, |
| 94 | 96 |
| 95 /** | 97 /** |
| 98 * Validates input fields. |
| 99 */ |
| 100 checkInput: function() { |
| 101 // Validate input. |
| 102 if (!$('email').value) { |
| 103 $('email').focus(); |
| 104 return false; |
| 105 } |
| 106 |
| 107 if (!$('password').value) { |
| 108 $('password').focus(); |
| 109 return false; |
| 110 } |
| 111 |
| 112 return true; |
| 113 }, |
| 114 |
| 115 /** |
| 96 * Handles sign in button click. | 116 * Handles sign in button click. |
| 97 * @private | 117 * @private |
| 98 */ | 118 */ |
| 99 handleSigninClick_: function(e) { | 119 handleSigninClick_: function(e) { |
| 120 if (!this.checkInput()) |
| 121 return; |
| 122 |
| 100 this.state = SigninScreen.STATE_AUTHENTICATING; | 123 this.state = SigninScreen.STATE_AUTHENTICATING; |
| 101 | 124 |
| 102 chrome.send('authenticateUser', | 125 chrome.send('authenticateUser', |
| 103 [$('email').value, $('password').value]); | 126 [$('email').value, $('password').value]); |
| 127 }, |
| 128 |
| 129 /** |
| 130 * Handles keyboard event. |
| 131 * @private |
| 132 */ |
| 133 handleKeyDown_: function(e) { |
| 134 // Handle 'Enter' key for 'email' and 'password' field. |
| 135 if (e.keyIdentifier == 'Enter') { |
| 136 if (e.target.id == 'email') { |
| 137 if (e.target.value) |
| 138 $('password').focus(); |
| 139 } else if (e.target.id == 'password') { |
| 140 this.handleSigninClick_(); |
| 141 } |
| 142 } |
| 104 } | 143 } |
| 105 }; | 144 }; |
| 106 | 145 |
| 107 /** | 146 /** |
| 108 * Expose 'reset' method that resets sign-in screen. | 147 * Expose 'reset' method that resets sign-in screen. |
| 109 * @public | 148 * @public |
| 110 */ | 149 */ |
| 111 SigninScreen.reset = function() { | 150 SigninScreen.reset = function() { |
| 112 $('signin').reset(); | 151 $('signin').reset(); |
| 113 }; | 152 }; |
| 114 | 153 |
| 115 return { | 154 return { |
| 116 SigninScreen: SigninScreen | 155 SigninScreen: SigninScreen |
| 117 }; | 156 }; |
| 118 }); | 157 }); |
| OLD | NEW |