Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js index 8f8696d..507ee31 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js | |||
@@ -1,70 +1,68 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | Clipperz.Base.module('Clipperz.PM.DataModel'); | 24 | Clipperz.Base.module('Clipperz.PM.DataModel'); |
27 | 25 | ||
28 | Clipperz.PM.DataModel.DirectLogin = function(args) { | 26 | Clipperz.PM.DataModel.DirectLogin = function(args) { |
29 | args = args || {}; | 27 | args = args || {}; |
30 | 28 | ||
31 | Clipperz.PM.DataModel.DirectLogin.superclass.constructor.apply(this, arguments); | 29 | Clipperz.PM.DataModel.DirectLogin.superclass.constructor.apply(this, arguments); |
32 | 30 | ||
33 | this._reference =args.reference | 31 | this._reference =args.reference |
34 | ||Clipperz.PM.Crypto.randomKey(); | 32 | ||Clipperz.PM.Crypto.randomKey(); |
35 | this._record =args.record | 33 | this._record =args.record |
36 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | 34 | ||Clipperz.Base.exception.raise('MandatoryParameter'); |
37 | 35 | ||
38 | this._retrieveIndexDataFunction = args.retrieveIndexDataFunction | 36 | this._retrieveIndexDataFunction = args.retrieveIndexDataFunction |
39 | ||this.record().retrieveDirectLoginIndexDataFunction() | 37 | ||this.record().retrieveDirectLoginIndexDataFunction() |
40 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | 38 | ||Clipperz.Base.exception.raise('MandatoryParameter'); |
41 | this._setIndexDataFunction = args.setIndexDataFunction | 39 | this._setIndexDataFunction = args.setIndexDataFunction |
42 | ||this.record().setDirectLoginIndexDataFunction() | 40 | ||this.record().setDirectLoginIndexDataFunction() |
43 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | 41 | ||Clipperz.Base.exception.raise('MandatoryParameter'); |
44 | this._removeIndexDataFunction =args.removeIndexDataFunction | 42 | this._removeIndexDataFunction =args.removeIndexDataFunction |
45 | ||this.record().removeDirectLoginIndexDataFunction() | 43 | ||this.record().removeDirectLoginIndexDataFunction() |
46 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | 44 | ||Clipperz.Base.exception.raise('MandatoryParameter'); |
47 | 45 | ||
48 | this._inputs = null; | 46 | this._inputs = null; |
49 | this._bindings = null; | 47 | this._bindings = null; |
50 | this._formValues = null; | 48 | this._formValues = null; |
51 | 49 | ||
52 | // this._inputsDeferredLock = new MochiKit.Async.DeferredLock(); | 50 | // this._inputsDeferredLock = new MochiKit.Async.DeferredLock(); |
53 | // this._bindingsDeferredLock = new MochiKit.Async.DeferredLock(); | 51 | // this._bindingsDeferredLock = new MochiKit.Async.DeferredLock(); |
54 | // this._formValuesDeferredLock = new MochiKit.Async.DeferredLock(); | 52 | // this._formValuesDeferredLock = new MochiKit.Async.DeferredLock(); |
55 | 53 | ||
56 | this._transientState = null; | 54 | this._transientState = null; |
57 | 55 | ||
58 | this._isBrandNew = MochiKit.Base.isUndefinedOrNull(args.reference); | 56 | this._isBrandNew = MochiKit.Base.isUndefinedOrNull(args.reference); |
59 | 57 | ||
60 | this.record().addDirectLogin(this); | 58 | this.record().addDirectLogin(this); |
61 | 59 | ||
62 | return this; | 60 | return this; |
63 | } | 61 | } |
64 | 62 | ||
65 | Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, { | 63 | Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, { |
66 | 64 | ||
67 | 'toString': function() { | 65 | 'toString': function() { |
68 | return "DirectLogin (" + this.reference() + ")"; | 66 | return "DirectLogin (" + this.reference() + ")"; |
69 | }, | 67 | }, |
70 | 68 | ||
@@ -284,97 +282,97 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, { | |||
284 | varresult; | 282 | varresult; |
285 | var type; | 283 | var type; |
286 | 284 | ||
287 | type = anInput['type'] || 'text'; | 285 | type = anInput['type'] || 'text'; |
288 | result = type.toLowerCase() == 'radio'; | 286 | result = type.toLowerCase() == 'radio'; |
289 | 287 | ||
290 | return result; | 288 | return result; |
291 | }, inputs); | 289 | }, inputs); |
292 | 290 | ||
293 | if (radios.length > 0) { | 291 | if (radios.length > 0) { |
294 | var updatedRadios; | 292 | var updatedRadios; |
295 | 293 | ||
296 | updatedRadios = {}; | 294 | updatedRadios = {}; |
297 | MochiKit.Iter.forEach(radios, MochiKit.Base.bind(function(aRadio) { | 295 | MochiKit.Iter.forEach(radios, MochiKit.Base.bind(function(aRadio) { |
298 | varradioConfiguration; | 296 | varradioConfiguration; |
299 | 297 | ||
300 | radioConfiguration = updatedRadios[aRadio['name']]; | 298 | radioConfiguration = updatedRadios[aRadio['name']]; |
301 | if (radioConfiguration == null) { | 299 | if (radioConfiguration == null) { |
302 | radioConfiguration = {type:'radio', name:aRadio['name'], options:[]}; | 300 | radioConfiguration = {type:'radio', name:aRadio['name'], options:[]}; |
303 | updatedRadios[aRadio['name']] = radioConfiguration; | 301 | updatedRadios[aRadio['name']] = radioConfiguration; |
304 | } | 302 | } |
305 | 303 | ||
306 | //TODO: remove the value: field and replace it with element.dom.value = <some value> | 304 | //TODO: remove the value: field and replace it with element.dom.value = <some value> |
307 | radioConfiguration.options.push({value:aRadio['value'], checked:aRadio['checked']}); | 305 | radioConfiguration.options.push({value:aRadio['value'], checked:aRadio['checked']}); |
308 | 306 | ||
309 | //TODO: shoud remove the 'formValues' call, as it is now deferred | 307 | //TODO: shoud remove the 'formValues' call, as it is now deferred |
310 | // if ((aRadio['checked'] == true) && (this.formValues()[aRadio['name']] == null)) { | 308 | // if ((aRadio['checked'] == true) && (this.formValues()[aRadio['name']] == null)) { |
311 | // this.formValues()[aRadio['name']] = aRadio['value']; | 309 | // this.formValues()[aRadio['name']] = aRadio['value']; |
312 | // } | 310 | // } |
313 | }, this)) | 311 | }, this)) |
314 | 312 | ||
315 | updatedInputs = MochiKit.Base.concat(updatedInputs, MochiKit.Base.values(updatedRadios)); | 313 | updatedInputs = MochiKit.Base.concat(updatedInputs, MochiKit.Base.values(updatedRadios)); |
316 | } | 314 | } |
317 | 315 | ||
318 | delete result.inputs; | 316 | delete result.inputs; |
319 | result.inputs = updatedInputs; | 317 | result.inputs = updatedInputs; |
320 | 318 | ||
321 | return result; | 319 | return result; |
322 | }, | 320 | }, |
323 | 321 | ||
324 | '_fixConfiguration': function (aConfiguration) { | 322 | '_fixConfiguration': function (aConfiguration) { |
325 | var fixedConfiguration; | 323 | var fixedConfiguration; |
326 | // var inputs; | 324 | // var inputs; |
327 | // var bindings; | 325 | // var bindings; |
328 | // var i,c; | 326 | // var i,c; |
329 | 327 | ||
330 | fixedConfiguration = Clipperz.Base.deepClone(aConfiguration); | 328 | fixedConfiguration = Clipperz.Base.deepClone(aConfiguration); |
331 | 329 | ||
332 | //console.log("PROCESS CONFIGURATION", aConfiguration); | 330 | //Clipperz.log("PROCESS CONFIGURATION", aConfiguration); |
333 | switch (aConfiguration['bookmarkletVersion']) { | 331 | switch (aConfiguration['bookmarkletVersion']) { |
334 | case '0.1': | 332 | case '0.1': |
335 | fixedConfiguration['formData'] = this.fixFormDataFromBookmarkletVersion_0_1(aConfiguration['formData']); | 333 | fixedConfiguration['formData'] = this.fixFormDataFromBookmarkletVersion_0_1(aConfiguration['formData']); |
336 | break; | 334 | break; |
337 | case '0.2': | 335 | case '0.2': |
338 | fixedConfiguration['formData'] = aConfiguration['formData']; | 336 | fixedConfiguration['formData'] = aConfiguration['formData']; |
339 | break; | 337 | break; |
340 | } | 338 | } |
341 | 339 | ||
342 | / * | 340 | / * |
343 | aConfiguration['_inputs'] = []; | 341 | aConfiguration['_inputs'] = []; |
344 | c = formData['inputs'].length; | 342 | c = formData['inputs'].length; |
345 | for (i=0; i<c; i++) { | 343 | for (i=0; i<c; i++) { |
346 | aConfiguration['_inputs'].push(new Clipperz.PM.DataModel.DirectLoginInput(formData['inputs'][i])); | 344 | aConfiguration['_inputs'].push(new Clipperz.PM.DataModel.DirectLoginInput(formData['inputs'][i])); |
347 | } | 345 | } |
348 | * / | 346 | * / |
349 | / * | 347 | / * |
350 | aConfiguration['_bindings'] = {}; | 348 | aConfiguration['_bindings'] = {}; |
351 | if (aConfiguration['legacyBindingData'] == null) { | 349 | if (aConfiguration['legacyBindingData'] == null) { |
352 | if (aConfiguration['bindingData'] != null) { | 350 | if (aConfiguration['bindingData'] != null) { |
353 | var bindingKey; | 351 | var bindingKey; |
354 | 352 | ||
355 | for (bindingKey in aConfiguration['bindingData']) { | 353 | for (bindingKey in aConfiguration['bindingData']) { |
356 | var newBinding; | 354 | var newBinding; |
357 | 355 | ||
358 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldKey:aConfiguration['bindingData'][bindingKey]}); | 356 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldKey:aConfiguration['bindingData'][bindingKey]}); |
359 | aConfiguration['_bindings'][newBinding.key()] = newBinding; | 357 | aConfiguration['_bindings'][newBinding.key()] = newBinding; |
360 | } | 358 | } |
361 | } else { | 359 | } else { |
362 | var editableFields; | 360 | var editableFields; |
363 | 361 | ||
364 | editableFields = MochiKit.Base.filter(function(aField) { | 362 | editableFields = MochiKit.Base.filter(function(aField) { |
365 | var result; | 363 | var result; |
366 | var type; | 364 | var type; |
367 | 365 | ||
368 | type = aField['type'].toLowerCase(); | 366 | type = aField['type'].toLowerCase(); |
369 | result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select')); | 367 | result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select')); |
370 | 368 | ||
371 | return result; | 369 | return result; |
372 | }, aConfiguration['_inputs']); | 370 | }, aConfiguration['_inputs']); |
373 | 371 | ||
374 | MochiKit.Iter.forEach(editableFields, MochiKit.Base.bind(function(anEditableField) { | 372 | MochiKit.Iter.forEach(editableFields, MochiKit.Base.bind(function(anEditableField) { |
375 | var newBinding; | 373 | var newBinding; |
376 | 374 | ||
377 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(anEditableField['name']); | 375 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(anEditableField['name']); |
378 | aConfiguration['_bindings'][newBinding.key()] = newBinding; | 376 | aConfiguration['_bindings'][newBinding.key()] = newBinding; |
379 | }, this)); | 377 | }, this)); |
380 | } | 378 | } |
@@ -436,166 +434,161 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, { | |||
436 | //------------------------------------------------------------------------- | 434 | //------------------------------------------------------------------------- |
437 | 435 | ||
438 | 'resetObjectDataStore': function () { | 436 | 'resetObjectDataStore': function () { |
439 | this._objectDataStore.removeAllData(); | 437 | this._objectDataStore.removeAllData(); |
440 | this._objectDataStore = null; | 438 | this._objectDataStore = null; |
441 | }, | 439 | }, |
442 | */ | 440 | */ |
443 | //========================================================================= | 441 | //========================================================================= |
444 | 442 | ||
445 | 'bookmarkletConfiguration': function () { | 443 | 'bookmarkletConfiguration': function () { |
446 | return Clipperz.Async.callbacks("DirectLogin.bookmarkletConfiguration", [ | 444 | return Clipperz.Async.callbacks("DirectLogin.bookmarkletConfiguration", [ |
447 | Clipperz.Async.collectResults("DirectLogin.bookmarkletConfiguration <inner results>", { | 445 | Clipperz.Async.collectResults("DirectLogin.bookmarkletConfiguration <inner results>", { |
448 | 'label': MochiKit.Base.method(this, 'label'), | 446 | 'label': MochiKit.Base.method(this, 'label'), |
449 | 'configuration': MochiKit.Base.method(this, 'getValue', '') | 447 | 'configuration': MochiKit.Base.method(this, 'getValue', '') |
450 | }, {trace:false}), | 448 | }, {trace:false}), |
451 | function (someValues) { | 449 | function (someValues) { |
452 | var result; | 450 | var result; |
453 | 451 | ||
454 | if (someValues['configuration'] != null) { | 452 | if (someValues['configuration'] != null) { |
455 | varconfiguration; | 453 | varconfiguration; |
456 | 454 | ||
457 | configuration = { | 455 | configuration = { |
458 | 'page': { | 456 | 'page': { |
459 | 'title': someValues['label'] | 457 | 'title': someValues['label'] |
460 | //'favicon' | 458 | //'favicon' |
461 | // 'url' | 459 | // 'url' |
462 | }, | 460 | }, |
463 | 'form': someValues['configuration']['formData'], | 461 | 'form': someValues['configuration']['formData'], |
464 | 'version':someValues['configuration']['bookmarkletVersion'] | 462 | 'version':someValues['configuration']['bookmarkletVersion'] |
465 | } | 463 | } |
466 | 464 | ||
467 | result = Clipperz.Base.formatJSON(configuration); | 465 | result = Clipperz.Base.formatJSON(configuration); |
468 | } else { | 466 | } else { |
469 | result = ''; | 467 | result = ''; |
470 | } | 468 | } |
471 | 469 | ||
472 | return result; | 470 | return result; |
473 | } | 471 | } |
474 | ], {trace:false}); | 472 | ], {trace:false}); |
475 | 473 | ||
476 | }, | 474 | }, |
477 | 475 | ||
478 | //------------------------------------------------------------------------- | 476 | //------------------------------------------------------------------------- |
479 | 477 | ||
480 | 'setBookmarkletConfiguration': function (aValue) { | 478 | 'setBookmarkletConfiguration': function (aValue) { |
481 | var bookmarkletConfiguration; | 479 | var bookmarkletConfiguration; |
482 | 480 | ||
483 | bookmarkletConfiguration = Clipperz.PM.DataModel.DirectLogin.checkBookmarkletConfiguration(aValue); | 481 | bookmarkletConfiguration = Clipperz.PM.DataModel.DirectLogin.checkBookmarkletConfiguration(aValue); |
484 | //console.log("BOOKMARKLET CONFIGURATION", bookmarkletConfiguration); | 482 | |
485 | return Clipperz.Async.callbacks("DirectLogin.setBookmarkletConfiguration", [ | 483 | return Clipperz.Async.callbacks("DirectLogin.setBookmarkletConfiguration", [ |
486 | MochiKit.Base.method(this, 'setValue', 'formData', bookmarkletConfiguration['form']), | 484 | MochiKit.Base.method(this, 'setValue', 'formData', bookmarkletConfiguration['form']), |
487 | //function (aValue) { console.log("SET VALUE - formData", aValue); return aValue; }, | ||
488 | MochiKit.Base.method(this, 'setValue', 'bookmarkletVersion', bookmarkletConfiguration['version']), | 485 | MochiKit.Base.method(this, 'setValue', 'bookmarkletVersion', bookmarkletConfiguration['version']), |
489 | 486 | ||
490 | MochiKit.Base.method(this, 'favicon'), | 487 | MochiKit.Base.method(this, 'favicon'), |
491 | Clipperz.Async.deferredIf("the favicon is not set", [ | 488 | Clipperz.Async.deferredIf("the favicon is not set", [ |
492 | ], [ | 489 | ], [ |
493 | MochiKit.Base.method(this, 'faviconUrlWithBookmarkletConfiguration', bookmarkletConfiguration), | 490 | MochiKit.Base.method(this, 'faviconUrlWithBookmarkletConfiguration', bookmarkletConfiguration), |
494 | MochiKit.Base.method(this, 'setFavicon') | 491 | MochiKit.Base.method(this, 'setFavicon') |
495 | ]), | 492 | ]), |
496 | 493 | ||
497 | MochiKit.Base.method(this, 'updateInputsAfterChangingBookmarkletConfiguration'), | 494 | MochiKit.Base.method(this, 'updateInputsAfterChangingBookmarkletConfiguration'), |
498 | MochiKit.Base.method(this, 'updateFormValuesAfterChangingBookmarkletConfiguration'), | 495 | MochiKit.Base.method(this, 'updateFormValuesAfterChangingBookmarkletConfiguration'), |
499 | MochiKit.Base.method(this, 'updateBindingsAfterChangingBookmarkletConfiguration'), | 496 | MochiKit.Base.method(this, 'updateBindingsAfterChangingBookmarkletConfiguration'), |
500 | 497 | ||
501 | MochiKit.Base.noop | 498 | MochiKit.Base.noop |
502 | ], {trace:false}); | 499 | ], {trace:false}); |
503 | }, | 500 | }, |
504 | 501 | ||
505 | //========================================================================= | 502 | //========================================================================= |
506 | 503 | ||
507 | 'formAttributes': function () { | 504 | 'formAttributes': function () { |
508 | return this.getValue('formData.attributes'); | 505 | return this.getValue('formData.attributes'); |
509 | }, | 506 | }, |
510 | 507 | ||
511 | //========================================================================= | 508 | //========================================================================= |
512 | 509 | ||
513 | 'inputs': function () { | 510 | 'inputs': function () { |
514 | return Clipperz.Async.callbacks("DirectLogin.inputs", [ | 511 | return Clipperz.Async.callbacks("DirectLogin.inputs", [ |
515 | Clipperz.Async.deferredIf("this._inputs is defined", [ | 512 | Clipperz.Async.deferredIf("this._inputs is defined", [ |
516 | ], [ | 513 | ], [ |
517 | MochiKit.Base.method(this, 'updateInputsAfterChangingBookmarkletConfiguration') | 514 | MochiKit.Base.method(this, 'updateInputsAfterChangingBookmarkletConfiguration') |
518 | ]) | 515 | ]) |
519 | ], {trace:false}, this._inputs); | 516 | ], {trace:false}, this._inputs); |
520 | }, | 517 | }, |
521 | 518 | ||
522 | 'setInputWithFormDataConfiguration': function (aFormDataConfiguration) { | 519 | 'setInputWithFormDataConfiguration': function (aFormDataConfiguration) { |
523 | this._inputs = {}; | 520 | this._inputs = {}; |
524 | 521 | ||
525 | if (aFormDataConfiguration != null) { | 522 | if (aFormDataConfiguration != null) { |
526 | MochiKit.Iter.forEach(aFormDataConfiguration['inputs'], MochiKit.Base.bind(function (anInputData) { | 523 | MochiKit.Iter.forEach(aFormDataConfiguration['inputs'], MochiKit.Base.bind(function (anInputData) { |
527 | var newInput; | 524 | var newInput; |
528 | 525 | ||
529 | newInput = new Clipperz.PM.DataModel.DirectLoginInput(anInputData); | 526 | newInput = new Clipperz.PM.DataModel.DirectLoginInput(anInputData); |
530 | this._inputs[newInput.name()] = newInput; | 527 | this._inputs[newInput.name()] = newInput; |
531 | }, this)); | 528 | }, this)); |
532 | } | 529 | } |
533 | 530 | ||
534 | return this._inputs; | 531 | return this._inputs; |
535 | }, | 532 | }, |
536 | 533 | ||
537 | 'updateInputsAfterChangingBookmarkletConfiguration': function () { | 534 | 'updateInputsAfterChangingBookmarkletConfiguration': function () { |
538 | return Clipperz.Async.callbacks("DirectLogin.updateInputsAfterChangingBookmarkletConfiguration", [ | 535 | return Clipperz.Async.callbacks("DirectLogin.updateInputsAfterChangingBookmarkletConfiguration", [ |
539 | // MochiKit.Base.method(this, 'getValue', ''), | ||
540 | //function (aValue) { console.log("VALUE", aValue); return aValue }, | ||
541 | MochiKit.Base.method(this, 'getValue', 'formData'), | 536 | MochiKit.Base.method(this, 'getValue', 'formData'), |
542 | //function (aValue) { console.log("FORM DATA", aValue); return aValue }, | ||
543 | MochiKit.Base.method(this, 'setInputWithFormDataConfiguration') | 537 | MochiKit.Base.method(this, 'setInputWithFormDataConfiguration') |
544 | ], {trace:false}); | 538 | ], {trace:false}); |
545 | }, | 539 | }, |
546 | 540 | ||
547 | //========================================================================= | 541 | //========================================================================= |
548 | 542 | ||
549 | 'inputValues': function () { | 543 | 'inputValues': function () { |
550 | return Clipperz.Async.callbacks("DirectLogin.inputValues", [ | 544 | return Clipperz.Async.callbacks("DirectLogin.inputValues", [ |
551 | MochiKit.Base.method(this, 'inputs'), | 545 | MochiKit.Base.method(this, 'inputs'), |
552 | MochiKit.Base.values, | 546 | MochiKit.Base.values, |
553 | //function (aValue) { console.log("INPUTS", aValue); return aValue; }, | ||
554 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.partial(MochiKit.Base.method(this, 'inputValue'))), | 547 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.partial(MochiKit.Base.method(this, 'inputValue'))), |
555 | Clipperz.Async.collectAll, | 548 | Clipperz.Async.collectAll, |
556 | Clipperz.Base.mergeItems | 549 | Clipperz.Base.mergeItems |
557 | ], {trace:false}); | 550 | ], {trace:false}); |
558 | }, | 551 | }, |
559 | 552 | ||
560 | 'inputValue': function (anInput) { | 553 | 'inputValue': function (anInput) { |
561 | vardeferredResult; | 554 | vardeferredResult; |
562 | 555 | ||
563 | deferredResult = new Clipperz.Async.Deferred("DirectLogin.inputValue", {trace:false}); | 556 | deferredResult = new Clipperz.Async.Deferred("DirectLogin.inputValue", {trace:false}); |
564 | 557 | ||
565 | if (anInput.needsFormValue()) { | 558 | if (anInput.needsFormValue()) { |
566 | deferredResult.addMethod(this, 'formValues'); | 559 | deferredResult.addMethod(this, 'formValues'); |
567 | deferredResult.addCallback(MochiKit.Base.itemgetter(anInput.name())); | 560 | deferredResult.addCallback(MochiKit.Base.itemgetter(anInput.name())); |
568 | deferredResult.addMethodcaller('value'); | 561 | deferredResult.addMethodcaller('value'); |
569 | } else if (anInput.needsBinding()) { | 562 | } else if (anInput.needsBinding()) { |
570 | deferredResult.addMethod(this, 'bindings'); | 563 | deferredResult.addMethod(this, 'bindings'); |
571 | deferredResult.addCallback(MochiKit.Base.itemgetter(anInput.name())); | 564 | deferredResult.addCallback(MochiKit.Base.itemgetter(anInput.name())); |
572 | deferredResult.addMethodcaller('field'); | 565 | deferredResult.addMethodcaller('field'); |
573 | deferredResult.addMethodcaller('value'); | 566 | deferredResult.addMethodcaller('value'); |
574 | } else { | 567 | } else { |
575 | deferredResult.addCallback(MochiKit.Async.succeed, anInput.value()); | 568 | deferredResult.addCallback(MochiKit.Async.succeed, anInput.value()); |
576 | } | 569 | } |
577 | deferredResult.addCallback(function (anActualValue) { | 570 | deferredResult.addCallback(function (anActualValue) { |
578 | return [anInput.name(), anActualValue]; | 571 | return [anInput.name(), anActualValue]; |
579 | }); | 572 | }); |
580 | 573 | ||
581 | deferredResult.callback(); | 574 | deferredResult.callback(); |
582 | 575 | ||
583 | return deferredResult; | 576 | return deferredResult; |
584 | }, | 577 | }, |
585 | 578 | ||
586 | //========================================================================= | 579 | //========================================================================= |
587 | 580 | ||
588 | 'bindings': function () { | 581 | 'bindings': function () { |
589 | return Clipperz.Async.callbacks("DirectLogin.bindings", [ | 582 | return Clipperz.Async.callbacks("DirectLogin.bindings", [ |
590 | Clipperz.Async.deferredIf("this._bindings is defined", [ | 583 | Clipperz.Async.deferredIf("this._bindings is defined", [ |
591 | ], [ | 584 | ], [ |
592 | MochiKit.Base.method(this, 'updateBindingsAfterChangingBookmarkletConfiguration'), | 585 | MochiKit.Base.method(this, 'updateBindingsAfterChangingBookmarkletConfiguration'), |
593 | MochiKit.Base.bind(function () { return this._bindings;}, this) | 586 | MochiKit.Base.bind(function () { return this._bindings;}, this) |
594 | ]) | 587 | ]) |
595 | ], {trace:false}, this._bindings); | 588 | ], {trace:false}, this._bindings); |
596 | }, | 589 | }, |
597 | 590 | ||
598 | 'bindFormFieldWithLabelToRecordFieldWithLabel': function (aFormFieldLabel, aRecordFieldLabel) { | 591 | 'bindFormFieldWithLabelToRecordFieldWithLabel': function (aFormFieldLabel, aRecordFieldLabel) { |
599 | return Clipperz.Async.callbacks("DirectLogin.bindFormFieldWithLabelToCardFieldWithLabel", [ | 592 | return Clipperz.Async.callbacks("DirectLogin.bindFormFieldWithLabelToCardFieldWithLabel", [ |
600 | Clipperz.Async.collectResults("DirectLogin.bindFormFieldWithLabelToCardFieldWithLabel - collect results", { | 593 | Clipperz.Async.collectResults("DirectLogin.bindFormFieldWithLabelToCardFieldWithLabel - collect results", { |
601 | 'binding': [ | 594 | 'binding': [ |
@@ -629,109 +622,106 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, { | |||
629 | 622 | ||
630 | result = {}; | 623 | result = {}; |
631 | for (bindingKey in someData['bindings']) { | 624 | for (bindingKey in someData['bindings']) { |
632 | result[bindingKey] = someData['fieldValues'][someData['bindings'][bindingKey].fieldKey()]['value']; | 625 | result[bindingKey] = someData['fieldValues'][someData['bindings'][bindingKey].fieldKey()]['value']; |
633 | } | 626 | } |
634 | 627 | ||
635 | return result; | 628 | return result; |
636 | } | 629 | } |
637 | ], {trace:false}); | 630 | ], {trace:false}); |
638 | }, | 631 | }, |
639 | */ | 632 | */ |
640 | //------------------------------------------------------------------------- | 633 | //------------------------------------------------------------------------- |
641 | 634 | ||
642 | 'updateBindingsAfterChangingBookmarkletConfiguration': function () { | 635 | 'updateBindingsAfterChangingBookmarkletConfiguration': function () { |
643 | return Clipperz.Async.callbacks("DirectLogin.updateBindingsAfterChangingBookmarkletConfiguration", [ | 636 | return Clipperz.Async.callbacks("DirectLogin.updateBindingsAfterChangingBookmarkletConfiguration", [ |
644 | Clipperz.Async.collectResults("DirectLogin.updateBindingsAfterChangingBookmarkletConfiguration<collect results>", { | 637 | Clipperz.Async.collectResults("DirectLogin.updateBindingsAfterChangingBookmarkletConfiguration<collect results>", { |
645 | 'currentValues':MochiKit.Base.method(this, 'getValue', ''), | 638 | 'currentValues':MochiKit.Base.method(this, 'getValue', ''), |
646 | 'originalValues':MochiKit.Base.method(this, 'originalConfiguration'), | 639 | 'originalValues':MochiKit.Base.method(this, 'originalConfiguration'), |
647 | 'inputs': MochiKit.Base.method(this, 'inputs') | 640 | 'inputs': MochiKit.Base.method(this, 'inputs') |
648 | }, {trace:false}), | 641 | }, {trace:false}), |
649 | MochiKit.Base.bind(function (someValues) { | 642 | MochiKit.Base.bind(function (someValues) { |
650 | var availableBindingValues; | 643 | var availableBindingValues; |
651 | var inputRequiringBindingValues; | 644 | var inputRequiringBindingValues; |
652 | var newBindingValues; | 645 | var newBindingValues; |
653 | 646 | ||
654 | if (MochiKit.Base.isUndefinedOrNull(someValues['originalValues']) || MochiKit.Base.isUndefinedOrNull(someValues['originalValues']['bindingData'])) { | 647 | if (MochiKit.Base.isUndefinedOrNull(someValues['originalValues']) || MochiKit.Base.isUndefinedOrNull(someValues['originalValues']['bindingData'])) { |
655 | availableBindingValues = {}; | 648 | availableBindingValues = {}; |
656 | } else { | 649 | } else { |
657 | availableBindingValues = Clipperz.Base.deepClone(someValues['originalValues']['bindingData']) | 650 | availableBindingValues = Clipperz.Base.deepClone(someValues['originalValues']['bindingData']) |
658 | } | 651 | } |
659 | 652 | ||
660 | if (someValues['currentValues'] != null) { | 653 | if (someValues['currentValues'] != null) { |
661 | MochiKit.Base.update(availableBindingValues, someValues['currentValues']['bindingData']); | 654 | MochiKit.Base.update(availableBindingValues, someValues['currentValues']['bindingData']); |
662 | } | 655 | } |
663 | 656 | ||
664 | this._bindings = {}; | 657 | this._bindings = {}; |
665 | newBindingValues = {} | 658 | newBindingValues = {} |
666 | MochiKit.Iter.forEach(MochiKit.Base.filter(MochiKit.Base.methodcaller('needsBinding'), MochiKit.Base.values(someValues['inputs'])), MochiKit.Base.bind(function (anInput) { | 659 | MochiKit.Iter.forEach(MochiKit.Base.filter(MochiKit.Base.methodcaller('needsBinding'), MochiKit.Base.values(someValues['inputs'])), MochiKit.Base.bind(function (anInput) { |
667 | varnewBinding; | 660 | varnewBinding; |
668 | 661 | ||
669 | newBindingValues[anInput.name()] = availableBindingValues[anInput.name()]; | 662 | newBindingValues[anInput.name()] = availableBindingValues[anInput.name()]; |
670 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { | 663 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { |
671 | 'key': anInput.name(), | 664 | 'key': anInput.name(), |
672 | 'field':availableBindingValues[anInput.name()] | 665 | 'field':availableBindingValues[anInput.name()] |
673 | }); | 666 | }); |
674 | 667 | ||
675 | this._bindings[anInput.name()] = newBinding; | 668 | this._bindings[anInput.name()] = newBinding; |
676 | }, this)) | 669 | }, this)) |
677 | //console.log("THIS._BINDINGS", this._bindings); | ||
678 | 670 | ||
679 | return newBindingValues; | 671 | return newBindingValues; |
680 | 672 | ||
681 | /* | 673 | /* |
682 | this._bindings = {}; | 674 | this._bindings = {}; |
683 | //console.log("CONFIGURATION", aConfiguration); | ||
684 | 675 | ||
685 | if (someValues['currentValues'] != null) { | 676 | if (someValues['currentValues'] != null) { |
686 | if (someValues['currentValues']['bindingData'] != null) { | 677 | if (someValues['currentValues']['bindingData'] != null) { |
687 | var bindingKey; | 678 | var bindingKey; |
688 | 679 | ||
689 | //console.log("BINDING DATA", someValues['currentValues']['bindingData']); | ||
690 | for (bindingKey in someValues['currentValues']['bindingData']) { | 680 | for (bindingKey in someValues['currentValues']['bindingData']) { |
691 | var newBinding; | 681 | var newBinding; |
692 | 682 | ||
693 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { | 683 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { |
694 | 'key': bindingKey, | 684 | 'key': bindingKey, |
695 | 'field':someValues['currentValues']['bindingData'][bindingKey] | 685 | 'field':someValues['currentValues']['bindingData'][bindingKey] |
696 | }); | 686 | }); |
697 | this._bindings[newBinding.key()] = newBinding; | 687 | this._bindings[newBinding.key()] = newBinding; |
698 | } | 688 | } |
699 | } else if (someValues['currentValues']['legacyBindingData'] == null) { | 689 | } else if (someValues['currentValues']['legacyBindingData'] == null) { |
700 | var bindingKey; | 690 | var bindingKey; |
701 | 691 | ||
702 | for (bindingKey in someValues['currentValues']['legacyBindingData']) { | 692 | for (bindingKey in someValues['currentValues']['legacyBindingData']) { |
703 | var newBinding; | 693 | var newBinding; |
704 | 694 | ||
705 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { | 695 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { |
706 | 'key': bindingKey, | 696 | 'key': bindingKey, |
707 | 'field':someValues['currentValues']['legacyBindingData'][bindingKey] | 697 | 'field':someValues['currentValues']['legacyBindingData'][bindingKey] |
708 | }); | 698 | }); |
709 | this._bindings[newBinding.key()] = newBinding; | 699 | this._bindings[newBinding.key()] = newBinding; |
710 | } | 700 | } |
711 | } else { | 701 | } else { |
712 | WTF = TODO; | 702 | WTF = TODO; |
713 | } | 703 | } |
714 | } | 704 | } |
715 | 705 | ||
716 | return this._bindings; | 706 | return this._bindings; |
717 | */ | 707 | */ |
718 | }, this), | 708 | }, this), |
719 | MochiKit.Base.method(this, 'setValue', 'bindingData') | 709 | MochiKit.Base.method(this, 'setValue', 'bindingData') |
720 | ], {trace:false}); | 710 | ], {trace:false}); |
721 | }, | 711 | }, |
722 | 712 | ||
723 | //========================================================================= | 713 | //========================================================================= |
724 | 714 | ||
725 | 'formValues': function () { | 715 | 'formValues': function () { |
726 | return Clipperz.Async.callbacks("DirectLogin.formValues", [ | 716 | return Clipperz.Async.callbacks("DirectLogin.formValues", [ |
727 | Clipperz.Async.deferredIf("this._formValues is defined", [ | 717 | Clipperz.Async.deferredIf("this._formValues is defined", [ |
728 | ], [ | 718 | ], [ |
729 | MochiKit.Base.method(this, 'updateFormValuesAfterChangingBookmarkletConfiguration'), | 719 | MochiKit.Base.method(this, 'updateFormValuesAfterChangingBookmarkletConfiguration'), |
730 | MochiKit.Base.bind(function () { return this._formValues;}, this) | 720 | MochiKit.Base.bind(function () { return this._formValues;}, this) |
731 | ]) | 721 | ]) |
732 | ], {trace:false}, this._formValues); | 722 | ], {trace:false}, this._formValues); |
733 | }, | 723 | }, |
734 | 724 | ||
735 | //------------------------------------------------------------------------- | 725 | //------------------------------------------------------------------------- |
736 | 726 | ||
737 | 'updateFormValuesAfterChangingBookmarkletConfiguration': function () { | 727 | 'updateFormValuesAfterChangingBookmarkletConfiguration': function () { |