author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/NewUserWizardController.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/NewUserWizardController.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/NewUserWizardController.js | 469 |
1 files changed, 469 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/NewUserWizardController.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/NewUserWizardController.js new file mode 100644 index 0000000..28d9d20 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/NewUserWizardController.js | |||
@@ -0,0 +1,469 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers'); | ||
30 | |||
31 | Clipperz.PM.UI.Web.Controllers.NewUserWizardController = function(args) { | ||
32 | this._newUserCreationComponent = args.newUserCreationComponent|| Clipperz.Base.exception.raise('MandatoryParameter'); | ||
33 | |||
34 | MochiKit.Signal.connect(this._newUserCreationComponent, 'changedValue',this, 'handleChangedValue'); | ||
35 | MochiKit.Signal.connect(this._newUserCreationComponent, 'moveForward',this, 'handleMoveForward'); | ||
36 | MochiKit.Signal.connect(this._newUserCreationComponent, 'keyPressed',this, 'handleNewUserCreationComponentKeyPressed'); | ||
37 | |||
38 | this._rulerComponent = null; | ||
39 | |||
40 | this._steps = null; | ||
41 | this._currentStepIndex = 0; | ||
42 | this._isNextEnabled = false; | ||
43 | |||
44 | this._userCreationState = 'IDLE'; //'IN PROGRESS', 'DONE', 'FAILED' | ||
45 | this._user = null; | ||
46 | return this; | ||
47 | } | ||
48 | |||
49 | MochiKit.Base.update(Clipperz.PM.UI.Web.Controllers.NewUserWizardController.prototype, { | ||
50 | |||
51 | 'toString': function() { | ||
52 | return "Clipperz.PM.UI.Web.Controllers.NewUserWizardController"; | ||
53 | }, | ||
54 | |||
55 | //------------------------------------------------------------------------- | ||
56 | |||
57 | 'newUserCreationComponent': function () { | ||
58 | return this._newUserCreationComponent; | ||
59 | }, | ||
60 | |||
61 | //============================================================================= | ||
62 | |||
63 | 'user': function () { | ||
64 | return this._user; | ||
65 | }, | ||
66 | |||
67 | 'setUser': function (aValue) { | ||
68 | this._user = aValue; | ||
69 | }, | ||
70 | |||
71 | //----------------------------------------------------------------------------- | ||
72 | |||
73 | 'userCreationState': function () { | ||
74 | return this._userCreationState; | ||
75 | }, | ||
76 | |||
77 | 'setUserCreationState': function (aValue) { | ||
78 | //console.log("+++ NewUserWizardController.setUserCreationState", aValue); | ||
79 | this._userCreationState = aValue; | ||
80 | this.checkState(); | ||
81 | }, | ||
82 | |||
83 | //============================================================================= | ||
84 | |||
85 | 'resetCurrentStepIndex': function () { | ||
86 | this._currentStepIndex = 0; | ||
87 | this.rulerComponent().resetStatus({animateTransition:true}); | ||
88 | }, | ||
89 | |||
90 | //----------------------------------------------------------------------------- | ||
91 | |||
92 | 'enableNext': function (aValue) { | ||
93 | this.rulerComponent().enableNext(aValue); | ||
94 | this._isNextEnabled = aValue; | ||
95 | }, | ||
96 | |||
97 | 'isNextEnabled': function () { | ||
98 | return this._isNextEnabled; | ||
99 | }, | ||
100 | |||
101 | //----------------------------------------------------------------------------- | ||
102 | |||
103 | 'enablePrevious': function (aValue) { | ||
104 | this.rulerComponent().enablePrevious(aValue); | ||
105 | }, | ||
106 | |||
107 | //============================================================================= | ||
108 | |||
109 | 'rulerComponent': function () { | ||
110 | if (this._rulerComponent == null) { | ||
111 | this._rulerComponent = new Clipperz.PM.UI.Web.Components.RulerComponent({ | ||
112 | translationContext:'Wizards.NewUserWizard' | ||
113 | }); | ||
114 | this._rulerComponent.render(); | ||
115 | |||
116 | MochiKit.Signal.connect(this._rulerComponent, 'exit', this, 'handleExit'); | ||
117 | MochiKit.Signal.connect(this._rulerComponent, 'done', this, 'done'); | ||
118 | MochiKit.Signal.connect(this._rulerComponent, 'moveForward',this, 'handleMoveForward'); | ||
119 | MochiKit.Signal.connect(this._rulerComponent, 'moveBackward',this, 'handleMoveBackward'); | ||
120 | MochiKit.Signal.connect(this._rulerComponent, 'cursorMoved',this, 'handleCursorMoved'); | ||
121 | } | ||
122 | |||
123 | return this._rulerComponent; | ||
124 | }, | ||
125 | |||
126 | 'resetRuler': function () { | ||
127 | // if (this._rulerComponent != null) { | ||
128 | // this._rulerComponent.clear(); | ||
129 | // } | ||
130 | // this._rulerComponent = null; | ||
131 | }, | ||
132 | |||
133 | //----------------------------------------------------------------------------- | ||
134 | |||
135 | 'showRuler': function (someSteps) { | ||
136 | var rulerElement; | ||
137 | |||
138 | this.setSteps(someSteps); | ||
139 | |||
140 | rulerElement = this.rulerComponent().element(); | ||
141 | this.newUserCreationComponent().disableAllPanels(); | ||
142 | |||
143 | MochiKit.Style.showElement(rulerElement); | ||
144 | MochiKit.Style.setElementPosition(rulerElement, {x:-1000, y:this.newUserCreationComponent().bottomMargin()}); | ||
145 | new MochiKit.Visual.Move(rulerElement, { | ||
146 | x:0, y:this.newUserCreationComponent().bottomMargin(), | ||
147 | mode:'absolute', | ||
148 | duration:0.5, | ||
149 | // afterFinish:MochiKit.Base.method(this, 'handleCursorMoved') | ||
150 | afterFinish:MochiKit.Base.method(this, 'handleRulerShowed') | ||
151 | }); | ||
152 | }, | ||
153 | |||
154 | //----------------------------------------------------------------------------- | ||
155 | |||
156 | 'handleRulerShowed':function () { | ||
157 | return Clipperz.Async.callbacks("NewUserWizardController.handlerRulerShowed", [ | ||
158 | MochiKit.Base.method(this.newUserCreationComponent(), 'waitUntilFullyRendered'), | ||
159 | MochiKit.Base.method(this, 'handleCursorMoved') | ||
160 | ], {trace:false}); | ||
161 | }, | ||
162 | |||
163 | //----------------------------------------------------------------------------- | ||
164 | |||
165 | 'hideRuler': function () { | ||
166 | new MochiKit.Visual.Move(this.rulerComponent().element(), {x:-1000, mode:'relative', duration:0.5}); | ||
167 | }, | ||
168 | |||
169 | 'doneWithRuler': function () { | ||
170 | var rulerComponentElement; | ||
171 | |||
172 | rulerComponentElement = this.rulerComponent().element(); | ||
173 | new MochiKit.Visual.Move(this.rulerComponent().element(), { | ||
174 | x:1000, | ||
175 | mode:'relative', | ||
176 | duration:1, | ||
177 | // afterFinish:MochiKit.Base.partial(MochiKit.Style.hideElement, rulerComponentElement) | ||
178 | afterFinish:function () { MochiKit.Style.hideElement(rulerComponentElement); } | ||
179 | }); | ||
180 | }, | ||
181 | |||
182 | //============================================================================= | ||
183 | |||
184 | 'createNewUserRulerSteps': function () { | ||
185 | return [ 'CREDENTIALS', 'CHECK_CREDENTIALS', 'TERMS_OF_SERVICE', 'CREATE_USER'/*, 'LOGIN' */]; | ||
186 | }, | ||
187 | |||
188 | //------------------------------------------------------------------------- | ||
189 | |||
190 | 'run': function () { | ||
191 | return Clipperz.Async.callbacks("NewUserWizardController.run", [ | ||
192 | MochiKit.Base.method(this, 'createNewUserRulerSteps'), | ||
193 | MochiKit.Base.method(this, 'showRuler') | ||
194 | ], {trace:false}); | ||
195 | }, | ||
196 | |||
197 | //----------------------------------------------------------------------------- | ||
198 | |||
199 | 'checkState': function () { | ||
200 | var enablePrevious; | ||
201 | var enableNext; | ||
202 | |||
203 | enablePrevious = true; | ||
204 | enableNext = false; | ||
205 | |||
206 | this.newUserCreationComponent().disableAllPanels(); | ||
207 | |||
208 | switch(this.currentStep()) { | ||
209 | case 'CREDENTIALS': | ||
210 | this.newUserCreationComponent().enableCredentialsPanel(); | ||
211 | |||
212 | enableNext = ( | ||
213 | (this.newUserCreationComponent().username() != '') | ||
214 | && | ||
215 | (this.newUserCreationComponent().passphrase() != '') | ||
216 | ); | ||
217 | // enablePrevious = false; | ||
218 | break; | ||
219 | case 'CHECK_CREDENTIALS': | ||
220 | this.newUserCreationComponent().enableCheckCredentialsPanel(); | ||
221 | |||
222 | enableNext = (this.newUserCreationComponent().passphrase() == this.newUserCreationComponent().rePassphrase()); | ||
223 | // enablePrevious = true; | ||
224 | break | ||
225 | case 'TERMS_OF_SERVICE': | ||
226 | this.newUserCreationComponent().enableTermsOfServicePanel(); | ||
227 | |||
228 | //console.log("awareOfUnrecoverablePassphrase", this.newUserCreationComponent().awareOfUnrecoverablePassphrase()); | ||
229 | //console.log("readTermsOfService", this.newUserCreationComponent().readTermsOfService()); | ||
230 | enableNext = ( | ||
231 | (this.newUserCreationComponent().awareOfUnrecoverablePassphrase() == 'on') | ||
232 | && | ||
233 | (this.newUserCreationComponent().readTermsOfService() == 'on') | ||
234 | ) | ||
235 | break; | ||
236 | case 'CREATE_USER': | ||
237 | //console.log(">>> CREATE_USER", this.userCreationState()); | ||
238 | this.newUserCreationComponent().enableCreateUserPanel(); | ||
239 | |||
240 | switch (this.userCreationState()) { | ||
241 | case 'IDLE': | ||
242 | this.setUserCreationState('IN PROGRESS'); | ||
243 | this.preformActualUserRegistration(); | ||
244 | |||
245 | enablePrevious = false; | ||
246 | enableNext = false; | ||
247 | break; | ||
248 | case 'IN PROGRESS': | ||
249 | enablePrevious = false; | ||
250 | enableNext = false; | ||
251 | break; | ||
252 | case 'DONE': | ||
253 | enablePrevious = false; | ||
254 | enableNext = true; | ||
255 | break; | ||
256 | case 'FAILED': | ||
257 | enablePrevious = true; | ||
258 | enableNext = false; | ||
259 | break; | ||
260 | }; | ||
261 | break; | ||
262 | // case 'LOGIN': | ||
263 | // this.newUserCreationComponent().enableLoginPanel(); | ||
264 | // break; | ||
265 | } | ||
266 | |||
267 | if (this.currentStepIndex() > 0) { | ||
268 | this.enablePrevious(enablePrevious); | ||
269 | } else { | ||
270 | this.enablePrevious(false); | ||
271 | } | ||
272 | this.enableNext(enableNext); | ||
273 | }, | ||
274 | |||
275 | //----------------------------------------------------------------------------- | ||
276 | |||
277 | 'setFocus': function () { | ||
278 | switch(this.currentStep()) { | ||
279 | case 'CREDENTIALS': | ||
280 | this.newUserCreationComponent().focusOnUsernameElement(); | ||
281 | break; | ||
282 | case 'CHECK_CREDENTIALS': | ||
283 | this.newUserCreationComponent().focusOnRePassphraseElement(); | ||
284 | break | ||
285 | case 'TERMS_OF_SERVICE': | ||
286 | break; | ||
287 | case 'CREATE_USER': | ||
288 | break; | ||
289 | // case 'LOGIN': | ||
290 | // break; | ||
291 | } | ||
292 | }, | ||
293 | |||
294 | //============================================================================= | ||
295 | |||
296 | 'steps': function () { | ||
297 | return this._steps; | ||
298 | }, | ||
299 | |||
300 | 'setSteps': function (aValue) { | ||
301 | this._steps = aValue; | ||
302 | |||
303 | this.rulerComponent().setSteps(aValue); | ||
304 | this.resetCurrentStepIndex(); | ||
305 | }, | ||
306 | |||
307 | 'currentStepIndex': function () { | ||
308 | return this._currentStepIndex; | ||
309 | }, | ||
310 | |||
311 | 'currentStep': function () { | ||
312 | return this.steps()[this.currentStepIndex()]; | ||
313 | }, | ||
314 | |||
315 | //============================================================================= | ||
316 | |||
317 | 'handleExit': function () { | ||
318 | return Clipperz.Async.callbacks("NewUserWizardController.handleExit", [ | ||
319 | // MochiKit.Base.method(this.newUserCreationComponent(), 'resetContent'), | ||
320 | Clipperz.Async.forkAndJoin("NewUserWizardController.handleExit - fork and join", [ | ||
321 | MochiKit.Base.method(this, 'hideRuler'), | ||
322 | MochiKit.Base.method(this.newUserCreationComponent(), 'deferredHideModal') | ||
323 | ], {trace:false}), | ||
324 | MochiKit.Base.method(this, 'resetRuler'), | ||
325 | // MochiKit.Base.method(this.newUserCreationComponent(), 'reset'), | ||
326 | MochiKit.Base.partial(MochiKit.Signal.signal, this, 'exit') | ||
327 | ], {trace:false}) | ||
328 | }, | ||
329 | |||
330 | 'done': function () { | ||
331 | this.doneWithRuler(); | ||
332 | MochiKit.Signal.signal(this, 'done', {'user': this.user()}); | ||
333 | }, | ||
334 | |||
335 | //============================================================================= | ||
336 | |||
337 | 'handleMoveBackward': function () { | ||
338 | if (this._currentStepIndex > 0) { | ||
339 | varafterMoveAction; | ||
340 | |||
341 | afterMoveAction = MochiKit.Base.noop; | ||
342 | |||
343 | //console.log("<-- backward", this.currentStep()); | ||
344 | switch(this.currentStep()) { | ||
345 | case 'CREDENTIALS': | ||
346 | case 'CHECK_CREDENTIALS': | ||
347 | case 'TERMS_OF_SERVICE': | ||
348 | this._currentStepIndex --; | ||
349 | this.rulerComponent().moveBackward(afterMoveAction); | ||
350 | break; | ||
351 | case 'CREATE_USER': | ||
352 | this.setUser(null); | ||
353 | this.newUserCreationComponent().hideAllProgeressStates(); | ||
354 | this.resetCurrentStepIndex(); | ||
355 | this.setUserCreationState('IDLE'); | ||
356 | break; | ||
357 | // case 'LOGIN': | ||
358 | // break; | ||
359 | }; | ||
360 | |||
361 | } | ||
362 | |||
363 | if (this._currentStepIndex == 0) { | ||
364 | this.enablePrevious(false); | ||
365 | } | ||
366 | }, | ||
367 | |||
368 | 'handleMoveForward': function () { | ||
369 | if (this.isNextEnabled()) { | ||
370 | varafterMoveAction; | ||
371 | |||
372 | this._currentStepIndex ++; | ||
373 | afterMoveAction = MochiKit.Base.noop; | ||
374 | |||
375 | switch(this.currentStep()) { | ||
376 | case 'CREDENTIALS': | ||
377 | break; | ||
378 | case 'CHECK_CREDENTIALS': | ||
379 | break | ||
380 | case 'TERMS_OF_SERVICE': | ||
381 | break; | ||
382 | case 'CREATE_USER': | ||
383 | break; | ||
384 | // case 'LOGIN': | ||
385 | // break; | ||
386 | }; | ||
387 | |||
388 | this.rulerComponent().moveForward(afterMoveAction); | ||
389 | }; | ||
390 | }, | ||
391 | |||
392 | 'handleCursorMoved': function () { | ||
393 | // this.checkState(); | ||
394 | // this.setFocus(); | ||
395 | |||
396 | return Clipperz.Async.callbacks("NewUserWizardController.handleCursorMoved", [ | ||
397 | MochiKit.Base.method(this.newUserCreationComponent(), 'waitUntilFullyRendered'), | ||
398 | MochiKit.Base.method(this, 'checkState'), | ||
399 | MochiKit.Base.method(this, 'setFocus') | ||
400 | ], {trace:false}); | ||
401 | }, | ||
402 | |||
403 | //------------------------------------------------------------------------- | ||
404 | |||
405 | 'handleChangedValue': function (anEvent) { | ||
406 | this.checkState(); | ||
407 | }, | ||
408 | |||
409 | //------------------------------------------------------------------------- | ||
410 | |||
411 | 'handleNewUserCreationComponentKeyPressed': function (anEvent) { | ||
412 | //console.log(">>> handleNewUserCreationComponentKeyPressed", anEvent.key().string); | ||
413 | if (anEvent.key().string == 'KEY_ENTER') { | ||
414 | if (anEvent.target().nodeName != 'TEXTAREA') { | ||
415 | anEvent.preventDefault(); | ||
416 | this.handleMoveForward(); | ||
417 | } | ||
418 | } else if (anEvent.key().string == 'KEY_TAB') { | ||
419 | if (anEvent.target() == this.newUserCreationComponent().usernameElement()) { | ||
420 | } else { | ||
421 | this.handleMoveForward(); | ||
422 | if ((anEvent.target().nodeName == 'INPUT') || (anEvent.target().nodeName == 'TEXTAREA')) { | ||
423 | anEvent.preventDefault(); | ||
424 | } | ||
425 | } | ||
426 | } else if ((anEvent.key().string == 'KEY_ARROW_RIGHT') && (anEvent.modifier().meta == true)) { | ||
427 | this.handleMoveForward(); | ||
428 | } else if ((anEvent.key().string == 'KEY_ARROW_LEFT') && (anEvent.modifier().meta == true)) { | ||
429 | this.handleMoveBackward(); | ||
430 | } else if (anEvent.key().string == 'KEY_ESCAPE') { | ||
431 | anEvent.stop(); | ||
432 | this.handleExit(); | ||
433 | } else { | ||
434 | MochiKit.Async.callLater(0.1, MochiKit.Base.method(this, 'checkState')); | ||
435 | } | ||
436 | }, | ||
437 | |||
438 | //============================================================================= | ||
439 | |||
440 | 'preformActualUserRegistration': function () { | ||
441 | vardeferredResult; | ||
442 | |||
443 | deferredResult = new Clipperz.Async.Deferred("NewUSerWizardController.preformActualUserRegistration", {trace:false}); | ||
444 | deferredResult.addMethod(this.newUserCreationComponent(), 'showProgressOnUserCreation'); | ||
445 | deferredResult.addMethod(Clipperz.PM.RunTime.mainController, 'setPassphraseDelegate', MochiKit.Base.method(this.newUserCreationComponent(), 'passphrase')); | ||
446 | deferredResult.addCallback(Clipperz.PM.DataModel.User.registerNewAccount, | ||
447 | this.newUserCreationComponent().username(), | ||
448 | MochiKit.Base.method(Clipperz.PM.RunTime.mainController, 'getPassphrase') | ||
449 | ); | ||
450 | deferredResult.addMethod(this, 'setUser'); | ||
451 | deferredResult.addMethod(this.newUserCreationComponent(), 'showUserCreationDone'); | ||
452 | deferredResult.addMethod(this, 'setUserCreationState', 'DONE'); | ||
453 | |||
454 | // deferredResult.addErrback(MochiKit.Base.method(this.newUserCreationComponent(), 'showUserCreationFailed')); | ||
455 | // deferredResult.addErrback(MochiKit.Base.method(this, 'setUser', null)); | ||
456 | // deferredResult.addErrback(MochiKit.Base.method(this, 'setUserCreationState', 'FAILED')); | ||
457 | deferredResult.addErrback(MochiKit.Base.bind(function (aValue) { | ||
458 | this.newUserCreationComponent().showUserCreationFailed(); | ||
459 | this.setUser(null); | ||
460 | this.setUserCreationState('FAILED'); | ||
461 | }, this)); | ||
462 | deferredResult.callback(); | ||
463 | |||
464 | return deferredResult; | ||
465 | }, | ||
466 | |||
467 | //============================================================================= | ||
468 | __syntaxFix__: "syntax fix" | ||
469 | }); | ||