summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/LoginForm.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/LoginForm.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/LoginForm.js356
1 files changed, 356 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/LoginForm.js b/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/LoginForm.js
new file mode 100644
index 0000000..eafcdbc
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/LoginForm.js
@@ -0,0 +1,356 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz Community Edition.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please
8refer to http://www.clipperz.com.
9
10* Clipperz Community Edition is free software: you can redistribute
11 it and/or modify it under the terms of the GNU Affero General Public
12 License as published by the Free Software Foundation, either version
13 3 of the License, or (at your option) any later version.
14
15* Clipperz Community Edition is distributed in the hope that it will
16 be useful, but WITHOUT ANY WARRANTY; without even the implied
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details.
19
20* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see
22 <http://www.gnu.org/licenses/>.
23
24*/
25
26Clipperz.Base.module('Clipperz.PM.UI.Mobile.Components');
27
28Clipperz.PM.UI.Mobile.Components.LoginForm = function(args) {
29 args = args || {};
30
31 this._pin = '';
32
33 this._message = null;
34 this._steps = 0;
35 this._actualSteps = 0;
36
37 this._callback = null;
38 this._errorCallback = null;
39
40 this._mode = 'CREDENTIALS';
41
42 Clipperz.PM.UI.Mobile.Components.LoginForm.superclass.constructor.apply(this, arguments);
43
44 return this;
45}
46
47//=============================================================================
48
49Clipperz.Base.extend(Clipperz.PM.UI.Mobile.Components.LoginForm, Clipperz.PM.UI.Common.Components.BaseComponent, {
50
51 //-------------------------------------------------------------------------
52
53 'toString': function () {
54 return "Clipperz.PM.UI.Mobile.Components.LoginForm component";
55 },
56
57 //-------------------------------------------------------------------------
58
59 'callback': function () {
60 return this._callback;
61 },
62
63 'errorCallback': function () {
64 return this._errorCallback;
65 },
66
67 //-------------------------------------------------------------------------
68
69 'mode': function () {
70 return this._mode;
71 },
72
73 'setMode': function (aValue) {
74 this._mode = aValue;
75 },
76
77 //..........................................................................
78
79 'pin': function () {
80 return this._pin;
81 },
82
83 'setPin': function (aValue) {
84 this._pin = aValue;
85 },
86
87 //..........................................................................
88
89 'username': function () {
90 return this._username;
91 },
92
93 'setUsername': function (aValue) {
94 this._username = aValue;
95 },
96
97 //..........................................................................
98
99 'passphrase': function () {
100 return this._passphrase;
101 },
102
103 'setPassphrase': function (aValue) {
104 this._passphrase = aValue;
105 },
106
107 //-------------------------------------------------------------------------
108
109 'message': function () {
110 return this._message;
111 },
112
113 '_setMessage': function (aValue) {
114 this._message = aValue;
115
116 if (aValue == null) {
117 MochiKit.Style.hideElement(this.getElement('credentialsMessage'));
118 } else {
119 this.getElement('message').innerHTML = aValue;
120 MochiKit.Style.showElement(this.getElement('credentialsMessage'));
121 }
122 },
123
124 'setMessage': function (aValue) {
125 this._setMessage(aValue);
126 MochiKit.DOM.removeElementClass(this.getElement('credentialsMessage'), 'error');
127 },
128
129 'setErrorMessage': function (aValue) {
130 this._setMessage(aValue);
131 MochiKit.DOM.addElementClass(this.getElement('credentialsMessage'), 'error');
132 },
133
134 //-------------------------------------------------------------------------
135
136 'setCallbacks': function (args) {
137 this._callback = args['callback'];
138 this._errorCallback = args['errorCallback'];
139 },
140
141 'showErrors': function (args) {
142//console.log("LoginForm.showErrors", args);
143 if (args['previousFailedAttempt'] == 'LOGIN') {
144 this.setErrorMessage("Wrong credentials");
145 } else if (args['previousFailedAttempt'] == 'PIN') {
146 if (args['failedAttempts'] == -1) {
147 this.setErrorMessage("Wrong PIN - Resetted");
148 } else {
149 this.setErrorMessage("Wrong PIN");
150 }
151 } else {
152 this.setMessage(null);
153 }
154 },
155
156 'updateWithArgs': function (args) {
157 this.renderIfNeeded();
158 this.setCallbacks(args);
159 this.showErrors(args);
160 this.updateRendering();
161 },
162
163 'showPinLogin': function (args) {
164 this.setPin('');
165 this.setMode('PIN');
166 this.updateWithArgs(args);
167
168 // $(this.getAnchor('PIN')).focus();
169 this.getElement('PIN').focus();
170 },
171
172 'showCredentialsLogin': function (args) {
173 this.setMode('CREDENTIALS');
174 this.updateWithArgs(args);
175
176 if (this.getElement('usernameField').value.length == 0) {
177 // $(this.getAnchor('usernameField')).focus();
178 this.getElement('usernameField').focus();
179 } else {
180 // $(this.getAnchor('passphraseField')).focus();
181 this.getElement('passphraseField').focus();
182 this.getElement('passphraseField').select();
183 }
184 },
185
186 //-------------------------------------------------------------------------
187
188 'renderIfNeeded': function () {
189 if (this.isFullyRendered() == false) {
190 this.render();
191 };
192 this.updateRendering();
193 },
194
195 'updateRendering': function () {
196 MochiKit.Style.showElement(this.getElement('credentialsBody'));
197 MochiKit.Style.hideElement(this.getElement('validating'));
198
199 // this.hideAllPanes();
200 MochiKit.Base.map(function (aNode) { MochiKit.Style.hideElement(aNode); }, MochiKit.Selector.findDocElements('div.credentialsBody > div'));
201 if (this.mode() == 'CREDENTIALS') {
202 selectedPanel = this.getElement('credentials')
203 } else if (this.mode() == 'PIN') {
204 selectedPanel = this.getElement('pin')
205 // this.updatePinDisplay();
206 } else {
207 throw 'Unhandled login form mode';
208 }
209 MochiKit.Style.showElement(selectedPanel);
210
211 MochiKit.Style.hideElement(this.getElement('validating'));
212 },
213
214 'renderSelf': function() {
215 var selectedPanel;
216 this.append(this.element(), {tag:'div', id:'login', children:[
217 {tag:'div', cls:'toolbar', children:[
218 {tag:'h1', html:"clipperz"}
219 ]},
220 {tag:'div', cls:'scroll', children:[
221 //==================================================================
222 {tag:'div', cls:'credentialsMessage', id:this.getId('credentialsMessage'), children:[
223 {tag:'h1', cls:'message', id:this.getId('message'), html:"Message"}
224 ]},
225 //==================================================================
226 {tag:'div', cls:'credentialsBody', id:this.getId('credentialsBody'), children:[
227 //--------------------------------------------------------------
228 {tag:'div', cls:'pin', id:this.getId('pin'), children:[
229 {tag:'form', cls:'scroll', id:this.getId('pinForm'), children:[
230 {tag:'ul', cls:'edit rounded', children:[
231 {tag:'li', children:[{tag:'input', type:'number', name:'PIN', placeholder:"PIN", id:this.getId('PIN') }]},
232 ]},
233 {tag:'a', href:'#', cls:'greenButton', id:this.getId('pinSubmitButton'), html:"Login"}
234 ]}
235 ]},
236 //--------------------------------------------------------------
237 {tag:'div', cls:'credentials', id:this.getId('credentials'), children:[
238 {tag:'form', cls:'scroll', id:this.getId('credentialsForm'), children:[
239 {tag:'ul', cls:'edit rounded', children:[
240 {tag:'li', children:[{tag:'input', type:'email', name:'name', /*value:'joe',*/ placeholder:"username", id:this.getId('usernameField') }]},
241 {tag:'li', children:[{tag:'input', type:'password', name:'passphrase', /*value:'clipperz',*/placeholder:"passphrase", id:this.getId('passphraseField') }]}
242 ]},
243 {tag:'a', href:'#', cls:'greenButton', id:this.getId('credentialsSubmitButton'), html:"Login"}
244 // {tag:'input', type:'submit', cls:'greenButton', id:this.getId('credentialsSubmitButton'), value:"Login"}
245
246 ]}
247 ]},
248 //--------------------------------------------------------------
249 ]},
250 //==================================================================
251 {tag:'div', cls:'validating', id:this.getId('validating'), children:[
252 {tag:'div', cls:'loading', children:[
253 {tag:'div', cls:'spinner', children:[
254 {tag:'div', cls:'bar01'},
255 {tag:'div', cls:'bar02'},
256 {tag:'div', cls:'bar03'},
257 {tag:'div', cls:'bar04'},
258 {tag:'div', cls:'bar05'},
259 {tag:'div', cls:'bar06'},
260 {tag:'div', cls:'bar07'},
261 {tag:'div', cls:'bar08'},
262 {tag:'div', cls:'bar09'},
263 {tag:'div', cls:'bar10'},
264 {tag:'div', cls:'bar11'},
265 {tag:'div', cls:'bar12'}
266 ]}
267 ]},
268 {tag:'div', id:this.getId('loadingMessage')},
269 {tag:'a', href:'#', cls:'grayButton', id:this.getId('loginCancelButton'), html:"Cancel"}
270 ]}
271 //==================================================================
272 ]}
273 ]});
274
275 MochiKit.Signal.connect(this.getElement('credentialsForm'), 'onsubmit', this, 'submitCredentialsHandler');
276 MochiKit.Signal.connect(this.getElement('credentialsSubmitButton'), 'onclick', this, 'submitCredentialsHandler');
277
278 MochiKit.Signal.connect(this.getElement('pinForm'), 'onsubmit', this, 'submitPinHandler');
279 MochiKit.Signal.connect(this.getElement('pinSubmitButton'), 'onclick', this, 'submitPinHandler');
280
281 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'initProgress', this, 'initProgressHandle');
282 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'updateProgress',this, 'updateProgressHandle');
283 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'advanceProgress',this, 'advanceProgressHandle');
284 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'progressDone', this, 'progressDoneHandle');
285 },
286
287 //-------------------------------------------------------------------------
288
289 'submitPinHandler': function (anEvent) {
290 varpin;
291
292 this.setMessage(null);
293 pin = this.getElement('PIN').value;
294 // $(this.getAnchor('PIN')).blur();
295 this.getElement('PIN').blur();
296
297 credentials = Clipperz.PM.PIN.credentialsWithPIN(pin);
298 this.loginWithCredentials(credentials);
299 },
300
301 'submitCredentialsHandler': function (anEvent) {
302//console.log("submitCredentialsHandler");
303 varcredentials;
304
305 this.setMessage(null);
306
307 credentials = {};
308 credentials['username'] = this.getElement('usernameField').value;
309 credentials['passphrase'] = this.getElement('passphraseField').value;
310 // $(this.getAnchor('passphraseField')).blur();
311 this.getElement('passphraseField').blur();
312
313 this.loginWithCredentials(credentials);
314 },
315
316 //-------------------------------------------------------------------------
317
318 'loginWithCredentials': function (someCredentials) {
319 varargs;
320
321 args = {};
322 args['credentials'] = someCredentials;
323 args['errorCallback'] = this.errorCallback();
324
325 MochiKit.Style.hideElement(this.getElement('credentialsBody'));
326 MochiKit.Style.showElement(this.getElement('validating'));
327
328 MochiKit.Async.callLater(0.1, this.callback(), args);
329 },
330
331 //-------------------------------------------------------------------------
332
333 'initProgressHandle': function (anEvent) {
334//console.log("** initProgressHandle", anEvent);
335 this._steps = anEvent['steps'];
336 this._actualSteps = 0;
337 },
338
339 'updateProgressHandle': function (anEvent) {
340//console.log("** updateProgressHandle", anEvent);
341 this._steps += anEvent['extraSteps'];
342 },
343
344 'advanceProgressHandle': function (anEvent) {
345//console.log("** advanceProgressHandle", anEvent);
346 this._actualSteps ++;
347//console.log("STEPS: " + this._actualSteps + "/" + this._steps);
348 },
349
350 'progressDoneHandle': function (anEvent) {
351//console.log("** progressDoneHandle", anEvent);
352 },
353
354 //-------------------------------------------------------------------------
355 __syntaxFix__: "syntax fix"
356});