Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / login / offline_gaia.js
blob25a258defd66778bc906b413b825dd978163b56c
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
3 // found in the LICENSE file.
5 Polymer((function() {
6 var DEFAULT_EMAIL_DOMAIN = '@gmail.com';
8 return {
9 is: 'offline-gaia',
11 properties: {
12 disabled: {
13 type: Boolean,
14 value: false
17 enterpriseInfo: String,
19 emailDomain: String
22 ready: function() {
23 /**
24 * Workaround for
25 * https://github.com/PolymerElements/neon-animation/issues/32
26 * TODO(dzhioev): Remove when fixed in Polymer.
28 var pages = this.$.animatedPages;
29 delete pages._squelchNextFinishEvent;
30 Object.defineProperty(pages, '_squelchNextFinishEvent',
31 { get: function() { return false; } });
34 onAnimationFinish_: function() {
35 this.$.backButton.hidden = this.isEmailSectionActive_();
36 this.focus();
39 focus: function() {
40 if (this.isEmailSectionActive_())
41 this.$.emailInput.focus();
42 else
43 this.$.passwordInput.focus();
46 onForgotPasswordClicked_: function() {
47 this.$.forgotPasswordDlg.fitInto = this;
48 this.disabled = true;
49 this.$.forgotPasswordDlg.open();
50 this.$.passwordCard.classList.add('full-disabled');
51 this.$.forgotPasswordDlg.focus();
54 onDialogOverlayClosed_: function() {
55 this.disabled = false;
56 this.$.passwordCard.classList.remove('full-disabled');
59 setEmail: function(email) {
60 if (email) {
61 if (this.emailDomain)
62 email = email.replace(this.emailDomain, '');
63 this.switchToPasswordCard(email);
64 this.$.passwordInput.isInvalid = true;
65 } else {
66 this.$.emailInput.value = '';
67 this.switchToEmailCard();
71 onBack_: function() {
72 this.$.backButton.hidden = true;
73 this.switchToEmailCard();
76 isRTL_: function() {
77 return !!document.querySelector('html[dir=rtl]');
80 isEmailSectionActive_: function() {
81 return this.$.animatedPages.selected == 'emailSection';
84 switchToEmailCard() {
85 this.$.passwordInput.value = '';
86 this.$.passwordInput.isInvalid = false;
87 this.$.emailInput.isInvalid = false;
88 if (this.isEmailSectionActive_())
89 return;
90 this.$.animatedPages.entryAnimation =
91 'slide-from-' + (this.isRTL_() ? 'right' : 'left') + '-animation';
92 this.$.animatedPages.exitAnimation =
93 'slide-' + (this.isRTL_() ? 'left' : 'right') + '-animation';
94 this.$.animatedPages.selected = 'emailSection';
97 switchToPasswordCard(email) {
98 this.$.emailInput.value = email;
99 if (email.indexOf('@') === -1) {
100 if (this.emailDomain)
101 email = email + this.emailDomain;
102 else
103 email = email + DEFAULT_EMAIL_DOMAIN;
105 this.$.passwordHeader.email = email;
106 if (!this.isEmailSectionActive_())
107 return;
108 this.$.animatedPages.entryAnimation =
109 'slide-from-' + (this.isRTL_() ? 'left' : 'right') + '-animation';
110 this.$.animatedPages.exitAnimation =
111 'slide-' + (this.isRTL_() ? 'right' : 'left') + '-animation';
112 this.$.animatedPages.selected = 'passwordSection';
115 onEmailSubmitted_: function() {
116 if (this.$.emailInput.checkValidity())
117 this.switchToPasswordCard(this.$.emailInput.value);
118 else
119 this.$.emailInput.focus();
122 onPasswordSubmitted_: function() {
123 if (!this.$.passwordInput.checkValidity())
124 return;
125 var msg = {
126 'useOffline': true,
127 'email': this.$.passwordHeader.email,
128 'password': this.$.passwordInput.value
130 this.$.passwordInput.value = '';
131 this.fire('authCompleted', msg);
134 })());