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 28 matching lines...) Expand all Loading... |
39 /** @inheritDoc */ | 39 /** @inheritDoc */ |
40 decorate: function() { | 40 decorate: function() { |
41 // Make this focusable | 41 // Make this focusable |
42 if (!this.hasAttribute('tabindex')) | 42 if (!this.hasAttribute('tabindex')) |
43 this.tabIndex = 0; | 43 this.tabIndex = 0; |
44 | 44 |
45 this.addEventListener('mousedown', this.handleMouseDown_.bind(this)); | 45 this.addEventListener('mousedown', this.handleMouseDown_.bind(this)); |
46 | 46 |
47 this.enterButtonElement.addEventListener('click', | 47 this.enterButtonElement.addEventListener('click', |
48 this.activate.bind(this)); | 48 this.activate.bind(this)); |
| 49 this.removeUserButtonElement.addEventListener('mouseout', |
| 50 this.handleRemoveButtonMouseOut_.bind(this)); |
49 }, | 51 }, |
50 | 52 |
51 /** | 53 /** |
52 * Initializes the pod after its properties set and added to a pod row. | 54 * Initializes the pod after its properties set and added to a pod row. |
53 */ | 55 */ |
54 initialize: function() { | 56 initialize: function() { |
55 if (!this.isGuest) { | 57 if (!this.isGuest) { |
56 this.passwordElement.addEventListener('keydown', | 58 this.passwordElement.addEventListener('keydown', |
57 this.parentNode.handleKeyDown.bind(this.parentNode)); | 59 this.parentNode.handleKeyDown.bind(this.parentNode)); |
58 } | 60 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 */ | 138 */ |
137 get mainInput() { | 139 get mainInput() { |
138 if (this.isGuest) { | 140 if (this.isGuest) { |
139 return this.enterButtonElement; | 141 return this.enterButtonElement; |
140 } else { | 142 } else { |
141 return this.passwordElement; | 143 return this.passwordElement; |
142 } | 144 } |
143 }, | 145 }, |
144 | 146 |
145 /** | 147 /** |
| 148 * Whether remove button is active state. |
| 149 * @type {boolean} |
| 150 */ |
| 151 get activeRemoveButton() { |
| 152 return this.removeUserButtonElement.classList.contains('active'); |
| 153 }, |
| 154 set activeRemoveButton(active) { |
| 155 if (active == this.activeRemoveButton) |
| 156 return; |
| 157 |
| 158 if (active) { |
| 159 this.removeUserButtonElement.classList.add('active'); |
| 160 this.removeUserButtonElement.textContent = |
| 161 localStrings.getString('removeUser'); |
| 162 } else { |
| 163 this.removeUserButtonElement.classList.remove('active'); |
| 164 this.removeUserButtonElement.textContent = ''; |
| 165 } |
| 166 }, |
| 167 |
| 168 /** |
146 * Focuses on input element. | 169 * Focuses on input element. |
147 */ | 170 */ |
148 focusInput: function() { | 171 focusInput: function() { |
149 this.mainInput.focus(); | 172 this.mainInput.focus(); |
150 }, | 173 }, |
151 | 174 |
152 /** | 175 /** |
153 * Activates the pod. | 176 * Activates the pod. |
154 * @return {boolean} True if activated successfully. | 177 * @return {boolean} True if activated successfully. |
155 */ | 178 */ |
(...skipping 16 matching lines...) Expand all Loading... |
172 * @param {boolean} takeFocus True to take focus. | 195 * @param {boolean} takeFocus True to take focus. |
173 */ | 196 */ |
174 reset: function(takeFocus) { | 197 reset: function(takeFocus) { |
175 this.passwordElement.value = ''; | 198 this.passwordElement.value = ''; |
176 | 199 |
177 if (takeFocus) | 200 if (takeFocus) |
178 this.mainInput.focus(); | 201 this.mainInput.focus(); |
179 }, | 202 }, |
180 | 203 |
181 /** | 204 /** |
| 205 * Handles mouseout on remove button button. |
| 206 */ |
| 207 handleRemoveButtonMouseOut_: function(e) { |
| 208 this.activeRemoveButton = false; |
| 209 }, |
| 210 |
| 211 /** |
| 212 * Handles mousedown on remove user button. |
| 213 */ |
| 214 handleRemoevButtonMouseDown_: function(e) { |
| 215 if (this.activeRemoveButton) |
| 216 chrome.send('removeUser', [this.user.emailAddress]); |
| 217 else |
| 218 this.activeRemoveButton = true; |
| 219 }, |
| 220 |
| 221 /** |
182 * Handles mousedown event. | 222 * Handles mousedown event. |
183 */ | 223 */ |
184 handleMouseDown_: function(e) { | 224 handleMouseDown_: function(e) { |
185 if (e.target == this.removeUserButtonElement) { | 225 if (e.target == this.removeUserButtonElement) { |
186 chrome.send('removeUser', [this.user.emailAddress]); | 226 this.handleRemoevButtonMouseDown_(e); |
187 | 227 |
188 // Prevent default so that we don't trigger 'focus' event. | 228 // Prevent default so that we don't trigger 'focus' event. |
189 e.preventDefault(); | 229 e.preventDefault(); |
190 } | 230 } |
191 } | 231 } |
192 }; | 232 }; |
193 | 233 |
194 | 234 |
195 /** | 235 /** |
196 * Creates a new pod row element. | 236 * Creates a new pod row element. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 return; | 371 return; |
332 | 372 |
333 if (pod) { | 373 if (pod) { |
334 if (pod.isGuest || | 374 if (pod.isGuest || |
335 localStrings.getString('authType') != 'ext' || | 375 localStrings.getString('authType') != 'ext' || |
336 pod.user.oauthTokenStatus == OAUTH_TOKEN_STATUS_VALID) { | 376 pod.user.oauthTokenStatus == OAUTH_TOKEN_STATUS_VALID) { |
337 // Focus current pod if it is guest pod, or | 377 // Focus current pod if it is guest pod, or |
338 // we are not using gaia ext for signin or | 378 // we are not using gaia ext for signin or |
339 // the user has a valid oauth token. | 379 // the user has a valid oauth token. |
340 for (var i = 0; i < this.pods.length; ++i) { | 380 for (var i = 0; i < this.pods.length; ++i) { |
| 381 this.pods[i].activeRemoveButton = false; |
341 if (this.pods[i] == pod) { | 382 if (this.pods[i] == pod) { |
342 pod.classList.remove("faded"); | 383 pod.classList.remove("faded"); |
343 pod.classList.add("focused"); | 384 pod.classList.add("focused"); |
344 } else { | 385 } else { |
345 this.pods[i].classList.remove('focused'); | 386 this.pods[i].classList.remove('focused'); |
346 this.pods[i].classList.add('faded'); | 387 this.pods[i].classList.add('faded'); |
347 } | 388 } |
348 } | 389 } |
349 pod.focusInput(); | 390 pod.focusInput(); |
350 | 391 |
351 this.focusedPod_ = pod; | 392 this.focusedPod_ = pod; |
352 this.scrollPodIntoView(pod); | 393 this.scrollPodIntoView(pod); |
353 } else { | 394 } else { |
354 // Otherwise, switch to Gaia signin. | 395 // Otherwise, switch to Gaia signin. |
355 Oobe.showSigninUI(pod.user.emailAddress); | 396 Oobe.showSigninUI(pod.user.emailAddress); |
356 this.focusPod(); // Clears current focus. | 397 this.focusPod(); // Clears current focus. |
357 } | 398 } |
358 } else { | 399 } else { |
359 for (var i = 0; i < this.pods.length; ++i) { | 400 for (var i = 0; i < this.pods.length; ++i) { |
360 this.pods[i].classList.remove('focused'); | 401 this.pods[i].classList.remove('focused'); |
361 this.pods[i].classList.remove('faded'); | 402 this.pods[i].classList.remove('faded'); |
| 403 this.pods[i].activeRemoveButton = false; |
362 } | 404 } |
363 this.focusedPod_ = undefined; | 405 this.focusedPod_ = undefined; |
364 } | 406 } |
365 }, | 407 }, |
366 | 408 |
367 /** | 409 /** |
368 * Returns the currently activated pod. | 410 * Returns the currently activated pod. |
369 */ | 411 */ |
370 get activated() { | 412 get activated() { |
371 return this.activatedPod_; | 413 return this.activatedPod_; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 524 } |
483 break; | 525 break; |
484 } | 526 } |
485 } | 527 } |
486 }; | 528 }; |
487 | 529 |
488 return { | 530 return { |
489 PodRow: PodRow | 531 PodRow: PodRow |
490 }; | 532 }; |
491 }); | 533 }); |
OLD | NEW |