| 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 */ | |
| 5 | 4 |
| 6 Polymer('offline-gaia', (function() { | 5 Polymer((function() { |
| 7 var DEFAULT_EMAIL_DOMAIN = '@gmail.com'; | 6 var DEFAULT_EMAIL_DOMAIN = '@gmail.com'; |
| 8 | 7 |
| 9 return { | 8 return { |
| 10 onTransitionEnd: function() { | 9 is: 'offline-gaia', |
| 10 |
| 11 properties: { |
| 12 disabled: { |
| 13 type: Boolean, |
| 14 value: false |
| 15 }, |
| 16 |
| 17 enterpriseInfo: String, |
| 18 |
| 19 emailDomain: String |
| 20 }, |
| 21 |
| 22 ready: function() { |
| 23 /** |
| 24 * Workaround for |
| 25 * https://github.com/PolymerElements/neon-animation/issues/32 |
| 26 * TODO(dzhioev): Remove when fixed in Polymer. |
| 27 */ |
| 28 var pages = this.$.animatedPages; |
| 29 delete pages._squelchNextFinishEvent; |
| 30 Object.defineProperty(pages, '_squelchNextFinishEvent', |
| 31 { get: function() { return false; } }); |
| 32 }, |
| 33 |
| 34 onAnimationFinish_: function() { |
| 35 this.$.backButton.hidden = this.isEmailSectionActive_(); |
| 11 this.focus(); | 36 this.focus(); |
| 12 }, | 37 }, |
| 13 | 38 |
| 14 focus: function() { | 39 focus: function() { |
| 15 if (this.$.animatedPages.selected == 'emailSection') | 40 if (this.isEmailSectionActive_()) |
| 16 this.$.emailInput.focus(); | 41 this.$.emailInput.focus(); |
| 17 else | 42 else |
| 18 this.$.passwordInput.focus(); | 43 this.$.passwordInput.focus(); |
| 19 }, | 44 }, |
| 20 | 45 |
| 21 onForgotPasswordClicked: function() { | 46 onForgotPasswordClicked_: function() { |
| 22 this.$.forgotPasswordDlg.toggle(); | 47 this.$.forgotPasswordDlg.fitInto = this; |
| 48 this.disabled = true; |
| 49 this.$.forgotPasswordDlg.open(); |
| 50 this.$.passwordCard.classList.add('full-disabled'); |
| 51 this.$.forgotPasswordDlg.focus(); |
| 23 }, | 52 }, |
| 24 | 53 |
| 25 onForgotPasswordKeyDown: function(e) { | 54 onDialogOverlayClosed_: function() { |
| 26 if (e.keyCode == 13 || e.keyCode == 32) | 55 this.disabled = false; |
| 27 return this.onForgotPasswordClicked(); | 56 this.$.passwordCard.classList.remove('full-disabled'); |
| 28 }, | |
| 29 | |
| 30 onKeyDownOnDialog: function(e) { | |
| 31 if (e.keyCode == 27) { | |
| 32 // Esc | |
| 33 this.$.forgotPasswordDlg.close(); | |
| 34 e.preventDefault(); | |
| 35 } | |
| 36 }, | 57 }, |
| 37 | 58 |
| 38 setEmail: function(email) { | 59 setEmail: function(email) { |
| 39 // Reorder elements for proper animation for rtl languages. | |
| 40 if (document.querySelector('html[dir=rtl]')) { | |
| 41 this.$.emailSection.parentNode.insertBefore(this.$.passwordSection, | |
| 42 this.$.emailSection); | |
| 43 } | |
| 44 if (email) { | 60 if (email) { |
| 45 if (this.emailDomain) | 61 if (this.emailDomain) |
| 46 email = email.replace(this.emailDomain, ''); | 62 email = email.replace(this.emailDomain, ''); |
| 47 this.switchToPasswordCard(email); | 63 this.switchToPasswordCard(email); |
| 48 this.$.passwordInput.isInvalid = true; | 64 this.$.passwordInput.isInvalid = true; |
| 49 } else { | 65 } else { |
| 50 this.$.emailInput.value = ''; | 66 this.$.emailInput.value = ''; |
| 51 this.switchToEmailCard(); | 67 this.switchToEmailCard(); |
| 52 } | 68 } |
| 53 }, | 69 }, |
| 54 | 70 |
| 55 onBack: function() { | 71 onBack_: function() { |
| 56 this.switchToEmailCard(); | 72 this.switchToEmailCard(); |
| 57 }, | 73 }, |
| 58 | 74 |
| 75 isRTL_: function() { |
| 76 return !!document.querySelector('html[dir=rtl]'); |
| 77 }, |
| 78 |
| 79 isEmailSectionActive_: function() { |
| 80 return this.$.animatedPages.selected == 'emailSection'; |
| 81 }, |
| 82 |
| 59 switchToEmailCard() { | 83 switchToEmailCard() { |
| 60 this.$.passwordInput.value = ''; | 84 this.$.passwordInput.value = ''; |
| 61 this.$.passwordInput.isInvalid = false; | 85 this.$.passwordInput.isInvalid = false; |
| 62 this.$.emailInput.isInvalid = false; | 86 this.$.emailInput.isInvalid = false; |
| 63 this.$.backButton.hidden = true; | 87 if (this.isEmailSectionActive_()) |
| 88 return; |
| 89 this.$.animatedPages.entryAnimation = |
| 90 'slide-from-' + (this.isRTL_() ? 'right' : 'left') + '-animation'; |
| 91 this.$.animatedPages.exitAnimation = |
| 92 'slide-' + (this.isRTL_() ? 'left' : 'right') + '-animation'; |
| 64 this.$.animatedPages.selected = 'emailSection'; | 93 this.$.animatedPages.selected = 'emailSection'; |
| 65 }, | 94 }, |
| 66 | 95 |
| 67 switchToPasswordCard(email) { | 96 switchToPasswordCard(email) { |
| 68 this.$.emailInput.value = email; | 97 this.$.emailInput.value = email; |
| 69 if (email.indexOf('@') === -1) { | 98 if (email.indexOf('@') === -1) { |
| 70 if (this.emailDomain) | 99 if (this.emailDomain) |
| 71 email = email + this.emailDomain; | 100 email = email + this.emailDomain; |
| 72 else | 101 else |
| 73 email = email + DEFAULT_EMAIL_DOMAIN; | 102 email = email + DEFAULT_EMAIL_DOMAIN; |
| 74 } | 103 } |
| 75 this.$.passwordHeader.email = email; | 104 this.$.passwordHeader.email = email; |
| 76 this.$.backButton.hidden = false; | 105 if (!this.isEmailSectionActive_()) |
| 106 return; |
| 107 this.$.animatedPages.entryAnimation = |
| 108 'slide-from-' + (this.isRTL_() ? 'left' : 'right') + '-animation'; |
| 109 this.$.animatedPages.exitAnimation = |
| 110 'slide-' + (this.isRTL_() ? 'right' : 'left') + '-animation'; |
| 77 this.$.animatedPages.selected = 'passwordSection'; | 111 this.$.animatedPages.selected = 'passwordSection'; |
| 78 }, | 112 }, |
| 79 | 113 |
| 80 onEmailSubmitted: function() { | 114 onEmailSubmitted_: function() { |
| 81 if (this.$.emailInput.checkValidity()) | 115 if (this.$.emailInput.checkValidity()) |
| 82 this.switchToPasswordCard(this.$.emailInput.value); | 116 this.switchToPasswordCard(this.$.emailInput.value); |
| 83 else | 117 else |
| 84 this.$.emailInput.focus(); | 118 this.$.emailInput.focus(); |
| 85 }, | 119 }, |
| 86 | 120 |
| 87 onPasswordSubmitted: function() { | 121 onPasswordSubmitted_: function() { |
| 88 if (!this.$.passwordInput.checkValidity()) | 122 if (!this.$.passwordInput.checkValidity()) |
| 89 return; | 123 return; |
| 90 var msg = { | 124 var msg = { |
| 91 'useOffline': true, | 125 'useOffline': true, |
| 92 'email': this.$.passwordHeader.email, | 126 'email': this.$.passwordHeader.email, |
| 93 'password': this.$.passwordInput.value | 127 'password': this.$.passwordInput.value |
| 94 }; | 128 }; |
| 95 this.$.passwordInput.value = ''; | 129 this.$.passwordInput.value = ''; |
| 96 this.fire('authCompleted', msg); | 130 this.fire('authCompleted', msg); |
| 97 } | 131 } |
| 98 }; | 132 }; |
| 99 })()); | 133 })()); |
| OLD | NEW |