summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/DirectLoginWizardController.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/DirectLoginWizardController.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/DirectLoginWizardController.js611
1 files changed, 611 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/DirectLoginWizardController.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/DirectLoginWizardController.js
new file mode 100644
index 0000000..38fdc08
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/DirectLoginWizardController.js
@@ -0,0 +1,611 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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
29Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers');
30
31Clipperz.PM.UI.Web.Controllers.DirectLoginWizardController = function(args) {
32 this._directLoginEditingComponent = args.directLoginEditingComponent|| Clipperz.Base.exception.raise('MandatoryParameter');
33 this._cardLabel = args.cardLabel || Clipperz.Base.exception.raise('MandatoryParameter');
34
35 MochiKit.Signal.connect(this._directLoginEditingComponent, 'changedValue',this, 'handleChangedValue');
36 MochiKit.Signal.connect(this._directLoginEditingComponent, 'moveForward',this, 'handleMoveForward');
37 MochiKit.Signal.connect(this._directLoginEditingComponent, 'keyPressed',this, 'handleDirectLoginEditingComponentKeyPressed');
38
39 this._directLogin = null;
40 this._directLoginHasJustBeenAdded = false;
41
42 this._rulerComponent = null;
43
44 this._steps = null;
45 this._currentStepIndex = 0;
46 this._isNextEnabled = false;
47
48 this._recordFields = null;
49 this._originalBindings = null;
50
51 this._bindingComponents = [];
52 this._formValueComponents = [];
53
54 return this;
55}
56
57MochiKit.Base.update(Clipperz.PM.UI.Web.Controllers.DirectLoginWizardController.prototype, {
58
59 'toString': function() {
60 return "Clipperz.PM.UI.Web.Controllers.DirectLoginWizardController";
61 },
62
63 //-------------------------------------------------------------------------
64
65 'directLogin': function () {
66 return this._directLogin;
67 },
68
69 //-------------------------------------------------------------------------
70
71 'directLoginHasJustBeenAdded': function () {
72 return this._directLoginHasJustBeenAdded;
73 },
74
75 'setDirectLoginHasJustBeenAdded': function (aValue) {
76 this._directLoginHasJustBeenAdded = aValue;
77 },
78
79 //-------------------------------------------------------------------------
80
81 'directLoginEditingComponent': function () {
82 return this._directLoginEditingComponent;
83 },
84
85 //=============================================================================
86
87 'cardLabel': function () {
88 return this._cardLabel;
89 },
90
91 //=============================================================================
92
93 'resetCurrentStepIndex': function () {
94 this._currentStepIndex = 0;
95 this.rulerComponent().resetStatus();
96 },
97
98 //-----------------------------------------------------------------------------
99
100 'enableNext': function (aValue) {
101 this.rulerComponent().enableNext(aValue);
102 this._isNextEnabled = aValue;
103 },
104
105 'isNextEnabled': function () {
106 return this._isNextEnabled;
107 },
108
109 //-----------------------------------------------------------------------------
110
111 'enablePrevious': function (aValue) {
112 this.rulerComponent().enablePrevious(aValue);
113 },
114
115 //=============================================================================
116
117 'bindingComponents': function () {
118 return this._bindingComponents;
119 },
120
121 'resetBindingComponents': function () {
122 this.directLoginEditingComponent().clearAllBindingsComponents();
123 this._bindingComponents = [];
124 },
125
126 //=============================================================================
127
128 'formValueComponents': function () {
129 return this._formValueComponents;
130 },
131
132 'resetFormValueComponents': function () {
133 this.directLoginEditingComponent().clearAllFormValueComponents();
134 this._formValueComponents = [];
135 },
136
137 //=============================================================================
138
139 'recordFields': function () {
140 return this._recordFields;
141 },
142
143 'setRecordFields': function (aValue) {
144 this._recordFields = aValue;
145 },
146
147 'recordFieldWithReference': function (aReference) {
148 var matchingValues;
149 var result;
150
151 matchingValues = MochiKit.Base.filter(function (aField) { return aField['reference'] == aReference; }, this.recordFields());
152
153 if (matchingValues.length == 0) {
154 result = null;
155 } else {
156 result = matchingValues[0];
157 }
158
159 return result;
160 },
161
162 //-----------------------------------------------------------------------------
163
164 'originalBindings': function () {
165 return this._originalBindings;
166 },
167
168 'setOriginalBindings': function (aValue) {
169//console.log("BINDINGS", aValue);
170 this._originalBindings = aValue;
171 },
172
173 //=============================================================================
174
175 'rulerComponent': function () {
176 if (this._rulerComponent == null) {
177 this._rulerComponent = new Clipperz.PM.UI.Web.Components.RulerComponent({
178 translationContext:'Wizards.DirectLoginWizard'
179 });
180 this._rulerComponent.render();
181
182 MochiKit.Signal.connect(this._rulerComponent, 'exit', this, 'handleExit');
183 MochiKit.Signal.connect(this._rulerComponent, 'done', this, 'done');
184 MochiKit.Signal.connect(this._rulerComponent, 'moveForward',this, 'handleMoveForward');
185 MochiKit.Signal.connect(this._rulerComponent, 'moveBackward',this, 'handleMoveBackward');
186 MochiKit.Signal.connect(this._rulerComponent, 'cursorMoved',this, 'handleCursorMoved');
187 }
188
189 return this._rulerComponent;
190 },
191
192 //-----------------------------------------------------------------------------
193
194 'showRuler': function (someSteps) {
195 var rulerElement;
196
197 this.setSteps(someSteps);
198
199 rulerElement = this.rulerComponent().element();
200 this.directLoginEditingComponent().disableAllPanels();
201
202 MochiKit.Style.showElement(rulerElement);
203 MochiKit.Style.setElementPosition(rulerElement, {x:-1000, y:this.directLoginEditingComponent().bottomMargin()});
204 new MochiKit.Visual.Move(rulerElement, {
205 x:0, y:this.directLoginEditingComponent().bottomMargin(),
206 mode:'absolute',
207 duration:1,
208 afterFinish:MochiKit.Base.method(this, 'handleCursorMoved')
209 });
210 },
211
212 'fixRulerRendering': function (aValue) {
213 this.rulerComponent().setDisplayMode(aValue);
214 },
215
216 //-----------------------------------------------------------------------------
217
218 'hideRuler': function () {
219 new MochiKit.Visual.Move(this.rulerComponent().element(), {x:-1000, mode:'relative', duration:1});
220 },
221
222 'doneWithRuler': function () {
223 var rulerComponentElement;
224
225 rulerComponentElement = this.rulerComponent().element();
226 new MochiKit.Visual.Move(this.rulerComponent().element(), {
227 x:1000,
228 mode:'relative',
229 duration:1,
230 // afterFinish:MochiKit.Base.partial(MochiKit.Style.hideElement, rulerComponentElement)
231 afterFinish:function () { MochiKit.Style.hideElement(rulerComponentElement); }
232 });
233 },
234
235 //=============================================================================
236
237 'addNewDirectLoginRulerSteps': function () {
238 return MochiKit.Base.concat([ 'LABEL'], this.editDirectLoginRulerSteps());
239
240 },
241
242 'editDirectLoginRulerSteps': function () {
243 return [ /*'TYPE',*/ 'CONFIGURATION', 'BINDINGS','FAVICON', 'DONE'];
244 },
245
246 //-------------------------------------------------------------------------
247
248 'runWithDirectLogin': function (aDirectLogin, hasJustBeenAdded) {
249 this._directLogin = aDirectLogin;
250 this.setDirectLoginHasJustBeenAdded(hasJustBeenAdded);
251
252 return Clipperz.Async.callbacks("DirectLoginWizardController.runWithDirectLogin", [
253 MochiKit.Base.method(aDirectLogin, 'label'),
254 MochiKit.Base.method(this.directLoginEditingComponent(), 'setLabel'),
255
256 MochiKit.Base.method(aDirectLogin, 'favicon'),
257 MochiKit.Base.method(this.directLoginEditingComponent(), 'setDirectLoginFavicon'),
258
259 MochiKit.Base.method(aDirectLogin, 'bookmarkletConfiguration'),
260 MochiKit.Base.method(this.directLoginEditingComponent(), 'setBookmarkletConfiguration'),
261
262 MochiKit.Base.method(aDirectLogin, 'bindings'),
263 MochiKit.Base.method(this, 'setOriginalBindings'),
264
265 MochiKit.Base.method(aDirectLogin, 'record'),
266 MochiKit.Base.methodcaller('fields'),
267 MochiKit.Base.values,
268 MochiKit.Base.partial(MochiKit.Base.map, Clipperz.Async.collectResults("Record.directLoginReferences - collectResults", {
269 'reference': MochiKit.Base.methodcaller('reference'),
270 'label': MochiKit.Base.methodcaller('label'),
271 'isHidden': MochiKit.Base.methodcaller('isHidden'),
272 'value': MochiKit.Base.methodcaller('value')
273 }, {trace:false})),
274 Clipperz.Async.collectAll,
275
276 MochiKit.Base.method(this, 'setRecordFields'),
277
278 MochiKit.Base.partial(MochiKit.Async.succeed, hasJustBeenAdded),
279 Clipperz.Async.deferredIf("Direct login has just been added", [
280 MochiKit.Base.method(this, 'addNewDirectLoginRulerSteps')
281 ], [
282 MochiKit.Base.method(this, 'editDirectLoginRulerSteps')
283 ]),
284 MochiKit.Base.method(this, 'showRuler')
285 ], {trace:false});
286 },
287
288 //-----------------------------------------------------------------------------
289
290 'checkState': function () {
291 var enablePrevious;
292 var enableNext;
293
294 enablePrevious = true;
295 enableNext = false;
296
297 this.directLoginEditingComponent().disableAllPanels();
298
299 switch(this.currentStep()) {
300 case 'LABEL':
301 this.directLoginEditingComponent().enableLabelField();
302
303 enableNext = (this.directLoginEditingComponent().label() != '');
304 enablePrevious = false;
305 break;
306 case 'TYPE':
307 this.directLoginEditingComponent().enableTypeField();
308
309 enableNext = true;
310 enablePrevious = true;
311 break
312 case 'CONFIGURATION':
313 this.directLoginEditingComponent().enableConfigurationField();
314
315 enableNext = (this.directLoginEditingComponent().bookmarkletConfiguration() != '');
316
317 if (enableNext == true) {
318 try {
319 Clipperz.PM.DataModel.DirectLogin.checkBookmarkletConfiguration(this.directLoginEditingComponent().bookmarkletConfiguration());
320 this.directLoginEditingComponent().removeHighlightConfigurationSyntaxError();
321 } catch (e) {
322 this.directLoginEditingComponent().highlightConfigurationSyntaxError();
323 enableNext = false;
324 }
325 }
326 break;
327 case 'BINDINGS':
328 enableNext = MochiKit.Iter.every(this.bindingComponents(), function (aBindingComponent) { return aBindingComponent.selectedValue() != null; })
329 this.directLoginEditingComponent().enableBindingFields();
330 break;
331 case 'FAVICON':
332 enableNext = true;
333 this.directLoginEditingComponent().enableFaviconField();
334 break;
335 case 'DONE':
336 enableNext = true;
337 this.directLoginEditingComponent().enableDonePanel();
338 break;
339 }
340
341 if (this.currentStepIndex() > 0) {
342 this.enablePrevious(enablePrevious);
343 } else {
344 this.enablePrevious(false);
345 }
346 this.enableNext(enableNext);
347 },
348
349 //-----------------------------------------------------------------------------
350
351 'setFocus': function () {
352 switch(this.currentStep()) {
353 case 'LABEL':
354 this.directLoginEditingComponent().focusOnLabelElement();
355 break;
356 case 'TYPE':
357 break;
358 case 'CONFIGURATION':
359 this.directLoginEditingComponent().focusOnBookmarkletConfigurationElement();
360 break;
361 case 'BINDINGS':
362 // this.directLoginEditingComponent().getElement('???').focus();
363 break;
364 case 'FAVICON':
365 this.directLoginEditingComponent().focusOnFaviconElement();
366 break;
367 case 'DONE':
368 break;
369 }
370 },
371
372 //=============================================================================
373
374 'steps': function () {
375 return this._steps;
376 },
377
378 'setSteps': function (aValue) {
379 this._steps = aValue;
380
381 this.rulerComponent().setSteps(aValue);
382 this.resetCurrentStepIndex();
383 },
384
385 'currentStepIndex': function () {
386 return this._currentStepIndex;
387 },
388
389 'currentStep': function () {
390 return this.steps()[this.currentStepIndex()];
391 },
392
393 //=============================================================================
394
395 'handleExit': function () {
396 MochiKit.Signal.signal(this, 'exit');
397 },
398
399 'done': function () {
400 this.doneWithRuler();
401
402 Clipperz.Async.callbacks("DirectLoginWizardController.done", [
403 MochiKit.Base.method(this.directLoginEditingComponent(), 'label'),
404 MochiKit.Base.method(this.directLogin(), 'setLabel'),
405
406 MochiKit.Base.method(this.directLoginEditingComponent(), 'bookmarkletConfiguration'),
407 MochiKit.Base.method(this.directLogin(), 'setBookmarkletConfiguration'),
408
409 //Bindings
410 MochiKit.Base.method(this.directLoginEditingComponent(), 'bindingComponents'),
411 // MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.bind(function (aBindingComponent) {
412 Clipperz.Async.forEach(MochiKit.Base.bind(function (aBindingComponent) {
413//console.log("aBindingComponent", aBindingComponent);
414 // this.directLogin().
415 return Clipperz.Async.callbacks("DirectLoginWizardController.done - update directLogin bindings", [
416 MochiKit.Base.method(this.directLogin(), 'bindings'),
417 MochiKit.Base.itemgetter(aBindingComponent.formFieldName()),
418 MochiKit.Base.methodcaller('setFieldKey', aBindingComponent.selectedValue())
419 ], {trace:false});
420 }, this)),
421
422 MochiKit.Base.method(this.directLoginEditingComponent(), 'favicon'),
423 MochiKit.Base.method(this.directLogin(), 'setFavicon'),
424
425 MochiKit.Base.partial(MochiKit.Signal.signal, this, 'done', {
426 'directLogin': this.directLogin(),
427 'hasJustBeenAdded':this.directLoginHasJustBeenAdded()
428 })
429 ], {trace:false});
430 },
431
432 //=============================================================================
433
434 'handleMoveBackward': function () {
435 if (this._currentStepIndex > 0) {
436 varafterMoveAction;
437
438 this._currentStepIndex --;
439 afterMoveAction = MochiKit.Base.noop;
440
441 switch(this.currentStep()) {
442 case 'LABEL':
443 break;
444 case 'TYPE':
445 break;
446 case 'CONFIGURATION':
447 break;
448 case 'BINDINGS':
449 break;
450 case 'FAVICON':
451 break;
452 case 'DONE':
453 break;
454 };
455
456 this.rulerComponent().moveBackward(afterMoveAction);
457 }
458
459 if (this._currentStepIndex == 0) {
460 this.enablePrevious(false);
461 }
462 },
463
464 'handleMoveForward': function () {
465 if (this.isNextEnabled()) {
466 varafterMoveAction;
467
468 this._currentStepIndex ++;
469 afterMoveAction = MochiKit.Base.noop;
470
471 switch(this.currentStep()) {
472 case 'LABEL':
473 break;
474 case 'TYPE':
475 break;
476 case 'CONFIGURATION':
477 break;
478 case 'BINDINGS':
479 this.resetBindingComponents();
480 this.resetFormValueComponents();
481
482 afterMoveAction = MochiKit.Base.partial(Clipperz.Async.callbacks, "DirectLoginWizardController.handleMoveForward - BINDINGS", [
483 MochiKit.Base.method(this.directLogin(), 'setBookmarkletConfiguration', this.directLoginEditingComponent().bookmarkletConfiguration()),
484
485 MochiKit.Base.method(this.directLogin(), 'favicon'),
486 MochiKit.Base.method(this.directLoginEditingComponent(), 'setDirectLoginFavicon'),
487
488 MochiKit.Base.method(this.directLogin(), 'bindings'),
489 MochiKit.Base.values,
490 Clipperz.Async.forEach(MochiKit.Base.bind(function (aBinding) {
491 var bindingComponent;
492
493 bindingComponent = new Clipperz.PM.UI.Web.Components.DirectLoginEditingBindingComponent({
494 formFieldName: aBinding.key(),
495 fields: this.recordFields(),
496 selectedFieldKey: aBinding.fieldKey()
497 });
498
499 this.bindingComponents().push(bindingComponent);
500
501 MochiKit.Signal.connect(bindingComponent, 'bindChange', this, 'handleBindChange', bindingComponent);
502 this.directLoginEditingComponent().addBindingComponent(bindingComponent);
503
504 }, this)),
505
506 MochiKit.Base.method(this.directLogin(), 'formValues'),
507 MochiKit.Base.values,
508 Clipperz.Async.forEach(MochiKit.Base.bind(function (aFormValue) {
509 var formValueComponent;
510
511 formValueComponent = new Clipperz.PM.UI.Web.Components.DirectLoginEditingFormValueComponent({
512 'formFieldName': aFormValue.key(),
513 'fieldOptions': aFormValue.fieldOptions(),
514 'initialValue': aFormValue.value()
515 });
516
517 this.formValueComponents().push(formValueComponent);
518
519 MochiKit.Signal.connect(formValueComponent, 'formValueChange', this, 'handleFormValueChange', formValueComponent);
520 this.directLoginEditingComponent().addFormValueComponent(formValueComponent);
521 }, this))
522
523 ], {trace:false});
524
525 break;
526 case 'FAVICON':
527 break;
528 case 'DONE':
529 this.directLoginEditingComponent().setDoneDescriptionWithKeys({
530 '__cardName__': this.cardLabel(),
531 '__directLoginName__': this.directLoginEditingComponent().label()
532 });
533 break;
534 };
535
536 this.rulerComponent().moveForward(afterMoveAction);
537 };
538 },
539
540 'handleCursorMoved': function () {
541 this.checkState();
542 this.setFocus();
543 },
544
545 //-------------------------------------------------------------------------
546
547 'handleChangedValue': function (anEvent) {
548 this.checkState();
549 },
550
551 //.........................................................................
552
553 'handleBindChange': function (aDirectLoginEditingBindingComponent) {
554 varselectedField;
555
556 selectedField = this.recordFieldWithReference(aDirectLoginEditingBindingComponent.selectedValue());
557
558 return Clipperz.Async.callbacks("DirectLoginWizardController.handleBindChange", [
559 MochiKit.Base.method(this.directLogin(), 'bindings'),
560 MochiKit.Base.itemgetter(aDirectLoginEditingBindingComponent.formFieldName()),
561 MochiKit.Base.methodcaller('setFieldKey', selectedField['reference']),
562 function () {
563 if (selectedField != null) {
564 aDirectLoginEditingBindingComponent.setFieldValue(selectedField['value']);
565 aDirectLoginEditingBindingComponent.setIsHidden(selectedField['isHidden']);
566 } else {
567 aDirectLoginEditingBindingComponent.setFieldValue('');
568 aDirectLoginEditingBindingComponent.setIsHidden(false);
569 }
570 },
571 MochiKit.Base.method(this, 'checkState')
572 ], {trace:false});
573 },
574
575 //.........................................................................
576
577 'handleFormValueChange': function (someOptions) {
578 return Clipperz.Async.callbacks("DirectLoginWizardController.handleFormValueChange", [
579 MochiKit.Base.method(this.directLogin(), 'formValues'),
580 MochiKit.Base.itemgetter(someOptions['fieldName']),
581 MochiKit.Base.methodcaller('setValue', someOptions['selectedValue']),
582 MochiKit.Base.method(this, 'checkState')
583 ], {trace:false});
584 },
585
586 //-------------------------------------------------------------------------
587
588 'handleDirectLoginEditingComponentKeyPressed': function (anEvent) {
589 if (anEvent.key().string == 'KEY_ENTER') {
590 if (anEvent.target().nodeName != 'TEXTAREA') {
591 anEvent.preventDefault();
592 this.handleMoveForward();
593 }
594 } else if (anEvent.key().string == 'KEY_TAB') {
595 this.handleMoveForward();
596 if ((anEvent.target().nodeName == 'INPUT') || (anEvent.target().nodeName == 'TEXTAREA')) {
597 anEvent.preventDefault();
598 }
599 } else if ((anEvent.key().string == 'KEY_ARROW_RIGHT') && (anEvent.modifier().meta == true)) {
600 this.handleMoveForward();
601 } else if ((anEvent.key().string == 'KEY_ARROW_LEFT') && (anEvent.modifier().meta == true)) {
602 this.handleMoveBackward();
603 } else if (anEvent.key().string == 'KEY_ESCAPE') {
604 anEvent.stop();
605 this.handleExit();
606 }
607 },
608
609 //=============================================================================
610 __syntaxFix__: "syntax fix"
611});