| OLD | NEW |
| 1 /* Copyright 2015 The Chromium Authors. All rights reserved. | 1 /* Copyright 2015 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 Polymer('offline-gaia', (function() { | 6 Polymer('offline-gaia', (function() { |
| 7 var DEFAULT_EMAIL_DOMAIN = '@gmail.com'; | 7 var DEFAULT_EMAIL_DOMAIN = '@gmail.com'; |
| 8 | 8 |
| 9 return { | 9 return { |
| 10 onTransitionEnd: function() { | 10 onTransitionEnd: function() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 }, | 28 }, |
| 29 | 29 |
| 30 onKeyDownOnDialog: function(e) { | 30 onKeyDownOnDialog: function(e) { |
| 31 if (e.keyCode == 27) { | 31 if (e.keyCode == 27) { |
| 32 // Esc | 32 // Esc |
| 33 this.$.forgotPasswordDlg.close(); | 33 this.$.forgotPasswordDlg.close(); |
| 34 e.preventDefault(); | 34 e.preventDefault(); |
| 35 } | 35 } |
| 36 }, | 36 }, |
| 37 | 37 |
| 38 ready: function() { | |
| 39 var emailInput = this.$.emailInput; | |
| 40 var passwordInput = this.$.passwordInput; | |
| 41 emailInput.addEventListener('buttonClick', function() { | |
| 42 if (emailInput.checkValidity()) { | |
| 43 this.switchToPasswordCard(emailInput.inputValue); | |
| 44 } else { | |
| 45 emailInput.focus(); | |
| 46 } | |
| 47 }.bind(this)); | |
| 48 | |
| 49 passwordInput.addEventListener('buttonClick', function() { | |
| 50 if (this.$.passwordInput.checkValidity()) { | |
| 51 var msg = { | |
| 52 'useOffline': true, | |
| 53 'email': this.$.passwordHeader.email, | |
| 54 'password': this.$.passwordInput.inputValue | |
| 55 }; | |
| 56 this.$.passwordInput.inputValue = ''; | |
| 57 this.fire('authCompleted', msg); | |
| 58 } | |
| 59 }.bind(this)); | |
| 60 | |
| 61 }, | |
| 62 | |
| 63 setEmail: function(email) { | 38 setEmail: function(email) { |
| 64 // Reorder elements for proper animation for rtl languages. | 39 // Reorder elements for proper animation for rtl languages. |
| 65 if (document.querySelector('html[dir=rtl]')) { | 40 if (document.querySelector('html[dir=rtl]')) { |
| 66 this.$.emailSection.parentNode.insertBefore(this.$.passwordSection, | 41 this.$.emailSection.parentNode.insertBefore(this.$.passwordSection, |
| 67 this.$.emailSection); | 42 this.$.emailSection); |
| 68 } | 43 } |
| 69 if (email) { | 44 if (email) { |
| 70 if (this.emailDomain) | 45 if (this.emailDomain) |
| 71 email = email.replace(this.emailDomain, ''); | 46 email = email.replace(this.emailDomain, ''); |
| 72 this.switchToPasswordCard(email); | 47 this.switchToPasswordCard(email); |
| 73 this.$.passwordInput.setValid(false); | 48 this.$.passwordInput.isInvalid = true; |
| 74 } else { | 49 } else { |
| 75 this.$.emailInput.inputValue = ''; | 50 this.$.emailInput.value = ''; |
| 76 this.switchToEmailCard(); | 51 this.switchToEmailCard(); |
| 77 } | 52 } |
| 78 }, | 53 }, |
| 79 | 54 |
| 80 onBack: function() { | 55 onBack: function() { |
| 81 this.switchToEmailCard(); | 56 this.switchToEmailCard(); |
| 82 }, | 57 }, |
| 83 | 58 |
| 84 switchToEmailCard() { | 59 switchToEmailCard() { |
| 85 this.$.passwordInput.inputValue = ''; | 60 this.$.passwordInput.value = ''; |
| 86 this.$.passwordInput.setValid(true); | 61 this.$.passwordInput.isInvalid = false; |
| 87 this.$.emailInput.setValid(true); | 62 this.$.emailInput.isInvalid = false; |
| 88 this.$.backButton.hidden = true; | 63 this.$.backButton.hidden = true; |
| 89 this.$.animatedPages.selected = 'emailSection'; | 64 this.$.animatedPages.selected = 'emailSection'; |
| 90 }, | 65 }, |
| 91 | 66 |
| 92 switchToPasswordCard(email) { | 67 switchToPasswordCard(email) { |
| 93 this.$.emailInput.inputValue = email; | 68 this.$.emailInput.value = email; |
| 94 if (email.indexOf('@') === -1) { | 69 if (email.indexOf('@') === -1) { |
| 95 if (this.emailDomain) | 70 if (this.emailDomain) |
| 96 email = email + this.emailDomain; | 71 email = email + this.emailDomain; |
| 97 else | 72 else |
| 98 email = email + DEFAULT_EMAIL_DOMAIN; | 73 email = email + DEFAULT_EMAIL_DOMAIN; |
| 99 } | 74 } |
| 100 this.$.passwordHeader.email = email; | 75 this.$.passwordHeader.email = email; |
| 101 this.$.backButton.hidden = false; | 76 this.$.backButton.hidden = false; |
| 102 this.$.animatedPages.selected = 'passwordSection'; | 77 this.$.animatedPages.selected = 'passwordSection'; |
| 78 }, |
| 79 |
| 80 onEmailSubmitted: function() { |
| 81 if (this.$.emailInput.checkValidity()) |
| 82 this.switchToPasswordCard(this.$.emailInput.value); |
| 83 else |
| 84 this.$.emailInput.focus(); |
| 85 }, |
| 86 |
| 87 onPasswordSubmitted: function() { |
| 88 if (!this.$.passwordInput.checkValidity()) |
| 89 return; |
| 90 var msg = { |
| 91 'useOffline': true, |
| 92 'email': this.$.passwordHeader.email, |
| 93 'password': this.$.passwordInput.value |
| 94 }; |
| 95 this.$.passwordInput.value = ''; |
| 96 this.fire('authCompleted', msg); |
| 103 } | 97 } |
| 104 }; | 98 }; |
| 105 })()); | 99 })()); |
| OLD | NEW |