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 | 1076 |
1 files changed, 1076 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js new file mode 100644 index 0000000..1d38509 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js | |||
@@ -0,0 +1,1076 @@ | |||
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.DataModel'); | ||
30 | |||
31 | Clipperz.PM.DataModel.DirectLogin = function(args) { | ||
32 | args = args || {}; | ||
33 | |||
34 | Clipperz.PM.DataModel.DirectLogin.superclass.constructor.apply(this, arguments); | ||
35 | |||
36 | this._reference =args.reference | ||
37 | ||Clipperz.PM.Crypto.randomKey(); | ||
38 | this._record =args.record | ||
39 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | ||
40 | |||
41 | this._retrieveIndexDataFunction = args.retrieveIndexDataFunction | ||
42 | ||this.record().retrieveDirectLoginIndexDataFunction() | ||
43 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | ||
44 | this._setIndexDataFunction = args.setIndexDataFunction | ||
45 | ||this.record().setDirectLoginIndexDataFunction() | ||
46 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | ||
47 | this._removeIndexDataFunction =args.removeIndexDataFunction | ||
48 | ||this.record().removeDirectLoginIndexDataFunction() | ||
49 | ||Clipperz.Base.exception.raise('MandatoryParameter'); | ||
50 | |||
51 | this._inputs = null; | ||
52 | this._bindings = null; | ||
53 | this._formValues = null; | ||
54 | |||
55 | // this._inputsDeferredLock = new MochiKit.Async.DeferredLock(); | ||
56 | // this._bindingsDeferredLock = new MochiKit.Async.DeferredLock(); | ||
57 | // this._formValuesDeferredLock = new MochiKit.Async.DeferredLock(); | ||
58 | |||
59 | this._transientState = null; | ||
60 | |||
61 | this._isBrandNew = MochiKit.Base.isUndefinedOrNull(args.reference); | ||
62 | |||
63 | this.record().addDirectLogin(this); | ||
64 | |||
65 | return this; | ||
66 | } | ||
67 | |||
68 | Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, { | ||
69 | |||
70 | 'toString': function() { | ||
71 | return "DirectLogin (" + this.reference() + ")"; | ||
72 | }, | ||
73 | |||
74 | //========================================================================= | ||
75 | |||
76 | 'reference': function () { | ||
77 | return this._reference; | ||
78 | }, | ||
79 | |||
80 | //------------------------------------------------------------------------- | ||
81 | |||
82 | 'record': function () { | ||
83 | return this._record; | ||
84 | }, | ||
85 | |||
86 | //========================================================================= | ||
87 | |||
88 | 'isBrandNew': function () { | ||
89 | return this._isBrandNew; | ||
90 | }, | ||
91 | |||
92 | //========================================================================= | ||
93 | |||
94 | 'removeIndexDataFunction': function () { | ||
95 | return this._removeIndexDataFunction; | ||
96 | }, | ||
97 | |||
98 | 'remove': function () { | ||
99 | return Clipperz.Async.callbacks("DirectLogin.remove", [ | ||
100 | MochiKit.Base.partial(this.removeIndexDataFunction(), this.reference()), | ||
101 | MochiKit.Base.method(this.record(), 'removeDirectLogin', this) | ||
102 | ], {trace:false}); | ||
103 | }, | ||
104 | |||
105 | //========================================================================= | ||
106 | /* | ||
107 | 'inputsDeferredLock': function () { | ||
108 | return this._inputsDeferredLock; | ||
109 | }, | ||
110 | |||
111 | 'bindingsDeferredLock': function () { | ||
112 | return this._bindingsDeferredLock; | ||
113 | }, | ||
114 | |||
115 | 'formValuesDeferredLock': function () { | ||
116 | return this._formValuesDeferredLock; | ||
117 | }, | ||
118 | */ | ||
119 | //========================================================================= | ||
120 | |||
121 | 'label': function () { | ||
122 | return this.getIndexDataForKey('label'); | ||
123 | }, | ||
124 | |||
125 | 'setLabelKeepingBackwardCompatibilityWithBeta': function (aValue) { | ||
126 | return Clipperz.Async.callbacks("DirectLogin.setLabelKeepingBackwardCompatibilityWithBeta", [ | ||
127 | MochiKit.Base.method(this, 'setIndexDataForKey', 'label', aValue), | ||
128 | MochiKit.Base.method(this, 'setValue', 'label', aValue) | ||
129 | ], {trace:false}); | ||
130 | }, | ||
131 | |||
132 | 'setLabel': function (aValue) { | ||
133 | return this.setLabelKeepingBackwardCompatibilityWithBeta(aValue); | ||
134 | // return this.setIndexDataForKey('label', aValue); | ||
135 | }, | ||
136 | |||
137 | //========================================================================= | ||
138 | |||
139 | 'favicon': function () { | ||
140 | return this.getIndexDataForKey('favicon'); | ||
141 | }, | ||
142 | |||
143 | 'setFavicon': function (aValue) { | ||
144 | return this.setIndexDataForKey('favicon', aValue); | ||
145 | }, | ||
146 | |||
147 | 'faviconUrlWithBookmarkletConfiguration': function (aBookmarkletConfiguration) { | ||
148 | varresult; | ||
149 | |||
150 | if (! MochiKit.Base.isUndefinedOrNull(aBookmarkletConfiguration['page']['favicon'])) { | ||
151 | result = aBookmarkletConfiguration['page']['favicon']; | ||
152 | } else if (! MochiKit.Base.isUndefinedOrNull(aBookmarkletConfiguration['form']['attributes']['action'])) { | ||
153 | var actionUrl; | ||
154 | var hostname; | ||
155 | |||
156 | actionUrl = aBookmarkletConfiguration['form']['attributes']['action']; | ||
157 | hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1'); | ||
158 | result = "http://" + hostname + "/favicon.ico"; | ||
159 | } else { | ||
160 | result = null; | ||
161 | } | ||
162 | |||
163 | |||
164 | return result; | ||
165 | }, | ||
166 | |||
167 | //------------------------------------------------------------------------- | ||
168 | /* | ||
169 | 'faviconData': function () { | ||
170 | var regexp = new RegExp('^data\:\/\/.*', 'i'); | ||
171 | |||
172 | return Clipperz.Async.callbacks("DirectLogin.favicon", [ | ||
173 | MochiKit.Base.method(this, 'getIndexDataForKey', 'favicon'), | ||
174 | MochiKit.Base.method(regexp, 'test'), | ||
175 | Clipperz.Async.deferredIf("is data URL", [ | ||
176 | MochiKit.Base.method(this, 'getIndexDataForKey', 'favicon') | ||
177 | ], [ | ||
178 | MochiKit.Base.method(this, 'transientState'), | ||
179 | MochiKit.Base.itemgetter('faviconData'), | ||
180 | Clipperz.Async.deferredIf('has a chaced value for the favicon data', [ | ||
181 | MochiKit.Base.operator.identity | ||
182 | ], [ | ||
183 | MochiKit.Base.method(this, 'getIndexDataForKey', 'favicon'), | ||
184 | MochiKit.Base.method(this, 'loadFaviconDataFromURL') | ||
185 | ]) | ||
186 | |||
187 | ]) | ||
188 | ], {trace:false}); | ||
189 | }, | ||
190 | |||
191 | //------------------------------------------------------------------------- | ||
192 | |||
193 | 'loadFaviconDataFromURL': function (anURL) { | ||
194 | var deferredResult; | ||
195 | var image; | ||
196 | |||
197 | deferredResult = new Clipperz.Async.Deferred("DirectLogin.loadFaviconDataFromURL", {trace:false}); | ||
198 | deferredResult.addCallback(function (anEvent) { | ||
199 | var image = anEvent.src(); | ||
200 | var canvas = document.createElement("canvas"); | ||
201 | var result; | ||
202 | |||
203 | canvas.width = image.width; | ||
204 | canvas.height = image.height; | ||
205 | |||
206 | var ctx = canvas.getContext("2d"); | ||
207 | ctx.drawImage(image, 0, 0); | ||
208 | |||
209 | result = canvas.toDataURL(/*"image/png"* /); | ||
210 | |||
211 | return result; | ||
212 | }); | ||
213 | deferredResult.addErrback(MochiKit.Async.succeed, Clipperz.PM.Strings.getValue('defaultFaviconUrl')); | ||
214 | deferredResult.addBoth(MochiKit.Base.bind(function (aDataUrl) { | ||
215 | this.transientState()['faviconData'] = aDataUrl; | ||
216 | |||
217 | return aDataUrl; | ||
218 | }, this)); | ||
219 | |||
220 | image = new Image(); | ||
221 | MochiKit.Signal.connect(image, 'onload', MochiKit.Base.method(deferredResult, 'callback')); | ||
222 | MochiKit.Signal.connect(image, 'onerror', MochiKit.Base.method(deferredResult, 'errback')); | ||
223 | MochiKit.Signal.connect(image, 'onabort', MochiKit.Base.method(deferredResult, 'errback')); | ||
224 | |||
225 | image.src = anURL; | ||
226 | |||
227 | return deferredResult; | ||
228 | }, | ||
229 | */ | ||
230 | |||
231 | //========================================================================= | ||
232 | |||
233 | 'type': function () { | ||
234 | return this.getValue('formData.attributes.type') | ||
235 | }, | ||
236 | |||
237 | //========================================================================= | ||
238 | |||
239 | 'serializedData': function () { | ||
240 | return Clipperz.Async.collectResults("DirectLogin.serializedData", { | ||
241 | 'bookmarkletVersion': MochiKit.Base.method(this, 'getValue', 'bookmarkletVersion'), | ||
242 | 'formData': MochiKit.Base.method(this, 'getValue', 'formData'), | ||
243 | 'formValues': MochiKit.Base.method(this, 'getValue', 'formValues'), | ||
244 | 'bindingData': [ | ||
245 | MochiKit.Base.method(this, 'bindings'), | ||
246 | function (someBindings) { | ||
247 | var result; | ||
248 | var bindingKey; | ||
249 | |||
250 | result = {} | ||
251 | for (bindingKey in someBindings) { | ||
252 | result[bindingKey] = someBindings[bindingKey].serializedData(); | ||
253 | } | ||
254 | |||
255 | return result; | ||
256 | } | ||
257 | ] | ||
258 | }, {trace:false})() | ||
259 | }, | ||
260 | |||
261 | //========================================================================= | ||
262 | /* | ||
263 | 'fixFormDataFromBookmarkletVersion_0_1': function(aValue) { | ||
264 | //{"type":"radio", "name":"action", "value":"new-user", "checked":false }, { "type":"radio", "name":"action", "value":"sign-in", "checked":true } | ||
265 | // || | ||
266 | // \ / | ||
267 | // \/ | ||
268 | //{"name":"dominio", "type":"radio", "options":[{"value":"@alice.it", "checked":true}, {"value":"@tin.it", "checked":false}, {"value":"@virgilio.it", "checked":false}, {"value":"@tim.it", "checked":false}]} | ||
269 | var result; | ||
270 | var inputs; | ||
271 | var updatedInputs; | ||
272 | var radios; | ||
273 | |||
274 | result = aValue; | ||
275 | inputs = aValue['inputs']; | ||
276 | |||
277 | updatedInputs = MochiKit.Base.filter(function(anInput) { | ||
278 | varresult; | ||
279 | var type; | ||
280 | |||
281 | type = anInput['type'] || 'text'; | ||
282 | result = type.toLowerCase() != 'radio'; | ||
283 | |||
284 | return result; | ||
285 | }, inputs); | ||
286 | radios = MochiKit.Base.filter(function(anInput) { | ||
287 | varresult; | ||
288 | var type; | ||
289 | |||
290 | type = anInput['type'] || 'text'; | ||
291 | result = type.toLowerCase() == 'radio'; | ||
292 | |||
293 | return result; | ||
294 | }, inputs); | ||
295 | |||
296 | if (radios.length > 0) { | ||
297 | var updatedRadios; | ||
298 | |||
299 | updatedRadios = {}; | ||
300 | MochiKit.Iter.forEach(radios, MochiKit.Base.bind(function(aRadio) { | ||
301 | varradioConfiguration; | ||
302 | |||
303 | radioConfiguration = updatedRadios[aRadio['name']]; | ||
304 | if (radioConfiguration == null) { | ||
305 | radioConfiguration = {type:'radio', name:aRadio['name'], options:[]}; | ||
306 | updatedRadios[aRadio['name']] = radioConfiguration; | ||
307 | } | ||
308 | |||
309 | //TODO: remove the value: field and replace it with element.dom.value = <some value> | ||
310 | radioConfiguration.options.push({value:aRadio['value'], checked:aRadio['checked']}); | ||
311 | |||
312 | //TODO: shoud remove the 'formValues' call, as it is now deferred | ||
313 | // if ((aRadio['checked'] == true) && (this.formValues()[aRadio['name']] == null)) { | ||
314 | // this.formValues()[aRadio['name']] = aRadio['value']; | ||
315 | // } | ||
316 | }, this)) | ||
317 | |||
318 | updatedInputs = MochiKit.Base.concat(updatedInputs, MochiKit.Base.values(updatedRadios)); | ||
319 | } | ||
320 | |||
321 | delete result.inputs; | ||
322 | result.inputs = updatedInputs; | ||
323 | |||
324 | return result; | ||
325 | }, | ||
326 | |||
327 | '_fixConfiguration': function (aConfiguration) { | ||
328 | var fixedConfiguration; | ||
329 | // var inputs; | ||
330 | // var bindings; | ||
331 | // var i,c; | ||
332 | |||
333 | fixedConfiguration = Clipperz.Base.deepClone(aConfiguration); | ||
334 | |||
335 | //console.log("PROCESS CONFIGURATION", aConfiguration); | ||
336 | switch (aConfiguration['bookmarkletVersion']) { | ||
337 | case '0.1': | ||
338 | fixedConfiguration['formData'] = this.fixFormDataFromBookmarkletVersion_0_1(aConfiguration['formData']); | ||
339 | break; | ||
340 | case '0.2': | ||
341 | fixedConfiguration['formData'] = aConfiguration['formData']; | ||
342 | break; | ||
343 | } | ||
344 | |||
345 | / * | ||
346 | aConfiguration['_inputs'] = []; | ||
347 | c = formData['inputs'].length; | ||
348 | for (i=0; i<c; i++) { | ||
349 | aConfiguration['_inputs'].push(new Clipperz.PM.DataModel.DirectLoginInput(formData['inputs'][i])); | ||
350 | } | ||
351 | * / | ||
352 | / * | ||
353 | aConfiguration['_bindings'] = {}; | ||
354 | if (aConfiguration['legacyBindingData'] == null) { | ||
355 | if (aConfiguration['bindingData'] != null) { | ||
356 | var bindingKey; | ||
357 | |||
358 | for (bindingKey in aConfiguration['bindingData']) { | ||
359 | var newBinding; | ||
360 | |||
361 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldKey:aConfiguration['bindingData'][bindingKey]}); | ||
362 | aConfiguration['_bindings'][newBinding.key()] = newBinding; | ||
363 | } | ||
364 | } else { | ||
365 | var editableFields; | ||
366 | |||
367 | editableFields = MochiKit.Base.filter(function(aField) { | ||
368 | var result; | ||
369 | var type; | ||
370 | |||
371 | type = aField['type'].toLowerCase(); | ||
372 | result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select')); | ||
373 | |||
374 | return result; | ||
375 | }, aConfiguration['_inputs']); | ||
376 | |||
377 | MochiKit.Iter.forEach(editableFields, MochiKit.Base.bind(function(anEditableField) { | ||
378 | var newBinding; | ||
379 | |||
380 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(anEditableField['name']); | ||
381 | aConfiguration['_bindings'][newBinding.key()] = newBinding; | ||
382 | }, this)); | ||
383 | } | ||
384 | |||
385 | } else { | ||
386 | var bindingKey; | ||
387 | |||
388 | for (bindingKey in aConfiguration['legacyBindingData']) { | ||
389 | var newBinding; | ||
390 | |||
391 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldName:aConfiguration['legacyBindingData'][bindingKey]}); | ||
392 | aConfiguration['_bindings'][newBinding.key()] = newBinding; | ||
393 | } | ||
394 | } | ||
395 | * / | ||
396 | |||
397 | return fixedConfiguration; | ||
398 | }, | ||
399 | |||
400 | //------------------------------------------------------------------------- | ||
401 | |||
402 | 'getObjectDataStore': function () { | ||
403 | var deferredResult; | ||
404 | |||
405 | deferredResult = new Clipperz.Async.Deferred("DirectLogin.getObjectDataStore", {trace:false}); | ||
406 | deferredResult.acquireLock(this.objectDataStoreDeferredLock()); | ||
407 | deferredResult.addCallback(MochiKit.Base.bind(function () { | ||
408 | var innerDeferredResult; | ||
409 | |||
410 | if (this._objectDataStore == null) { | ||
411 | this._objectDataStore = new Clipperz.KeyValueObjectStore(); | ||
412 | |||
413 | innerDeferredResult = new Clipperz.Async.Deferred("DirectLogin.getObjectDataStore <inner deferred>", {trace:false}); | ||
414 | // innerDeferredResult.addMethod(this.record(), 'getValue', 'directLogins' + '.' + this.reference()); | ||
415 | innerDeferredResult.addMethod(this, 'getValue', ''), | ||
416 | innerDeferredResult.addMethod(this, 'setOriginalState'); | ||
417 | innerDeferredResult.addMethod(this, '_fixConfiguration'); | ||
418 | innerDeferredResult.addMethod(this._objectDataStore, 'initWithValues'); | ||
419 | // innerDeferredResult.addMethod(this._objectDataStore, 'setValues'); | ||
420 | innerDeferredResult.callback(); | ||
421 | } else { | ||
422 | innerDeferredResult = MochiKit.Async.succeed(this._objectDataStore); | ||
423 | } | ||
424 | |||
425 | return innerDeferredResult; | ||
426 | }, this)); | ||
427 | deferredResult.releaseLock(this.objectDataStoreDeferredLock()); | ||
428 | deferredResult.callback(); | ||
429 | |||
430 | return deferredResult; | ||
431 | }, | ||
432 | |||
433 | //------------------------------------------------------------------------- | ||
434 | |||
435 | 'hasInitiatedObjectDataStore': function () { | ||
436 | return (this._objectDataStore != null); | ||
437 | }, | ||
438 | |||
439 | //------------------------------------------------------------------------- | ||
440 | |||
441 | 'resetObjectDataStore': function () { | ||
442 | this._objectDataStore.removeAllData(); | ||
443 | this._objectDataStore = null; | ||
444 | }, | ||
445 | */ | ||
446 | //========================================================================= | ||
447 | |||
448 | 'bookmarkletConfiguration': function () { | ||
449 | return Clipperz.Async.callbacks("DirectLogin.bookmarkletConfiguration", [ | ||
450 | Clipperz.Async.collectResults("DirectLogin.bookmarkletConfiguration <inner results>", { | ||
451 | 'label': MochiKit.Base.method(this, 'label'), | ||
452 | 'configuration': MochiKit.Base.method(this, 'getValue', '') | ||
453 | }, {trace:false}), | ||
454 | function (someValues) { | ||
455 | var result; | ||
456 | |||
457 | if (someValues['configuration'] != null) { | ||
458 | varconfiguration; | ||
459 | |||
460 | configuration = { | ||
461 | 'page': { | ||
462 | 'title': someValues['label'] | ||
463 | //'favicon' | ||
464 | // 'url' | ||
465 | }, | ||
466 | 'form': someValues['configuration']['formData'], | ||
467 | 'version':someValues['configuration']['bookmarkletVersion'] | ||
468 | } | ||
469 | |||
470 | result = Clipperz.Base.formatJSON(configuration); | ||
471 | } else { | ||
472 | result = ''; | ||
473 | } | ||
474 | |||
475 | return result; | ||
476 | } | ||
477 | ], {trace:false}); | ||
478 | |||
479 | }, | ||
480 | |||
481 | //------------------------------------------------------------------------- | ||
482 | |||
483 | 'setBookmarkletConfiguration': function (aValue) { | ||
484 | var bookmarkletConfiguration; | ||
485 | |||
486 | bookmarkletConfiguration = Clipperz.PM.DataModel.DirectLogin.checkBookmarkletConfiguration(aValue); | ||
487 | //console.log("BOOKMARKLET CONFIGURATION", bookmarkletConfiguration); | ||
488 | return Clipperz.Async.callbacks("DirectLogin.setBookmarkletConfiguration", [ | ||
489 | MochiKit.Base.method(this, 'setValue', 'formData', bookmarkletConfiguration['form']), | ||
490 | //function (aValue) { console.log("SET VALUE - formData", aValue); return aValue; }, | ||
491 | MochiKit.Base.method(this, 'setValue', 'bookmarkletVersion', bookmarkletConfiguration['version']), | ||
492 | |||
493 | MochiKit.Base.method(this, 'favicon'), | ||
494 | Clipperz.Async.deferredIf("the favicon is not set", [ | ||
495 | ], [ | ||
496 | MochiKit.Base.method(this, 'faviconUrlWithBookmarkletConfiguration', bookmarkletConfiguration), | ||
497 | MochiKit.Base.method(this, 'setFavicon') | ||
498 | ]), | ||
499 | |||
500 | MochiKit.Base.method(this, 'updateInputsAfterChangingBookmarkletConfiguration'), | ||
501 | MochiKit.Base.method(this, 'updateFormValuesAfterChangingBookmarkletConfiguration'), | ||
502 | MochiKit.Base.method(this, 'updateBindingsAfterChangingBookmarkletConfiguration'), | ||
503 | |||
504 | MochiKit.Base.noop | ||
505 | ], {trace:false}); | ||
506 | }, | ||
507 | |||
508 | //========================================================================= | ||
509 | |||
510 | 'formAttributes': function () { | ||
511 | return this.getValue('formData.attributes'); | ||
512 | }, | ||
513 | |||
514 | //========================================================================= | ||
515 | |||
516 | 'inputs': function () { | ||
517 | return Clipperz.Async.callbacks("DirectLogin.inputs", [ | ||
518 | Clipperz.Async.deferredIf("this._inputs is defined", [ | ||
519 | ], [ | ||
520 | MochiKit.Base.method(this, 'updateInputsAfterChangingBookmarkletConfiguration') | ||
521 | ]) | ||
522 | ], {trace:false}, this._inputs); | ||
523 | }, | ||
524 | |||
525 | 'setInputWithFormDataConfiguration': function (aFormDataConfiguration) { | ||
526 | this._inputs = {}; | ||
527 | |||
528 | if (aFormDataConfiguration != null) { | ||
529 | MochiKit.Iter.forEach(aFormDataConfiguration['inputs'], MochiKit.Base.bind(function (anInputData) { | ||
530 | var newInput; | ||
531 | |||
532 | newInput = new Clipperz.PM.DataModel.DirectLoginInput(anInputData); | ||
533 | this._inputs[newInput.name()] = newInput; | ||
534 | }, this)); | ||
535 | } | ||
536 | |||
537 | return this._inputs; | ||
538 | }, | ||
539 | |||
540 | 'updateInputsAfterChangingBookmarkletConfiguration': function () { | ||
541 | return Clipperz.Async.callbacks("DirectLogin.updateInputsAfterChangingBookmarkletConfiguration", [ | ||
542 | // MochiKit.Base.method(this, 'getValue', ''), | ||
543 | //function (aValue) { console.log("VALUE", aValue); return aValue }, | ||
544 | MochiKit.Base.method(this, 'getValue', 'formData'), | ||
545 | //function (aValue) { console.log("FORM DATA", aValue); return aValue }, | ||
546 | MochiKit.Base.method(this, 'setInputWithFormDataConfiguration') | ||
547 | ], {trace:false}); | ||
548 | }, | ||
549 | |||
550 | //========================================================================= | ||
551 | |||
552 | 'inputValues': function () { | ||
553 | return Clipperz.Async.callbacks("DirectLogin.inputValues", [ | ||
554 | MochiKit.Base.method(this, 'inputs'), | ||
555 | MochiKit.Base.values, | ||
556 | //function (aValue) { console.log("INPUTS", aValue); return aValue; }, | ||
557 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.partial(MochiKit.Base.method(this, 'inputValue'))), | ||
558 | Clipperz.Async.collectAll, | ||
559 | Clipperz.Base.mergeItems | ||
560 | ], {trace:false}); | ||
561 | }, | ||
562 | |||
563 | 'inputValue': function (anInput) { | ||
564 | vardeferredResult; | ||
565 | |||
566 | deferredResult = new Clipperz.Async.Deferred("DirectLogin.inputValue", {trace:false}); | ||
567 | |||
568 | if (anInput.needsFormValue()) { | ||
569 | deferredResult.addMethod(this, 'formValues'); | ||
570 | deferredResult.addCallback(MochiKit.Base.itemgetter(anInput.name())); | ||
571 | deferredResult.addMethodcaller('value'); | ||
572 | } else if (anInput.needsBinding()) { | ||
573 | deferredResult.addMethod(this, 'bindings'); | ||
574 | deferredResult.addCallback(MochiKit.Base.itemgetter(anInput.name())); | ||
575 | deferredResult.addMethodcaller('field'); | ||
576 | deferredResult.addMethodcaller('value'); | ||
577 | } else { | ||
578 | deferredResult.addCallback(MochiKit.Async.succeed, anInput.value()); | ||
579 | } | ||
580 | deferredResult.addCallback(function (anActualValue) { | ||
581 | return [anInput.name(), anActualValue]; | ||
582 | }); | ||
583 | |||
584 | deferredResult.callback(); | ||
585 | |||
586 | return deferredResult; | ||
587 | }, | ||
588 | |||
589 | //========================================================================= | ||
590 | |||
591 | 'bindings': function () { | ||
592 | return Clipperz.Async.callbacks("DirectLogin.bindings", [ | ||
593 | Clipperz.Async.deferredIf("this._bindings is defined", [ | ||
594 | ], [ | ||
595 | MochiKit.Base.method(this, 'updateBindingsAfterChangingBookmarkletConfiguration'), | ||
596 | MochiKit.Base.bind(function () { return this._bindings;}, this) | ||
597 | ]) | ||
598 | ], {trace:false}, this._bindings); | ||
599 | }, | ||
600 | |||
601 | 'bindFormFieldWithLabelToRecordFieldWithLabel': function (aFormFieldLabel, aRecordFieldLabel) { | ||
602 | return Clipperz.Async.callbacks("DirectLogin.bindFormFieldWithLabelToCardFieldWithLabel", [ | ||
603 | Clipperz.Async.collectResults("DirectLogin.bindFormFieldWithLabelToCardFieldWithLabel - collect results", { | ||
604 | 'binding': [ | ||
605 | MochiKit.Base.method(this, 'bindings'), | ||
606 | MochiKit.Base.itemgetter(aFormFieldLabel) | ||
607 | ], | ||
608 | 'field': [ | ||
609 | MochiKit.Base.method(this.record(), 'fieldWithLabel', aRecordFieldLabel) | ||
610 | ] | ||
611 | }), | ||
612 | function (someValues) { | ||
613 | someValues['binding'].setField(someValues['field']) | ||
614 | } | ||
615 | ], {trace:false}); | ||
616 | }, | ||
617 | |||
618 | //------------------------------------------------------------------------- | ||
619 | /* | ||
620 | 'bindingValues': function () { | ||
621 | return Clipperz.Async.callbacks("DirectLogin.bindingValues", [ | ||
622 | Clipperz.Async.collectResults("DirectLogin.bindingValues [collectResults]", { | ||
623 | 'fieldValues': [ | ||
624 | MochiKit.Base.method(this, 'record'), | ||
625 | MochiKit.Base.methodcaller('getFieldsValues') | ||
626 | ], | ||
627 | 'bindings': MochiKit.Base.method(this, 'bindings') | ||
628 | }, {trace:false}), | ||
629 | function (someData) { | ||
630 | var result; | ||
631 | varbindingKey; | ||
632 | |||
633 | result = {}; | ||
634 | for (bindingKey in someData['bindings']) { | ||
635 | result[bindingKey] = someData['fieldValues'][someData['bindings'][bindingKey].fieldKey()]['value']; | ||
636 | } | ||
637 | |||
638 | return result; | ||
639 | } | ||
640 | ], {trace:false}); | ||
641 | }, | ||
642 | */ | ||
643 | //------------------------------------------------------------------------- | ||
644 | |||
645 | 'updateBindingsAfterChangingBookmarkletConfiguration': function () { | ||
646 | return Clipperz.Async.callbacks("DirectLogin.updateBindingsAfterChangingBookmarkletConfiguration", [ | ||
647 | Clipperz.Async.collectResults("DirectLogin.updateBindingsAfterChangingBookmarkletConfiguration<collect results>", { | ||
648 | 'currentValues':MochiKit.Base.method(this, 'getValue', ''), | ||
649 | 'originalValues':MochiKit.Base.method(this, 'originalConfiguration'), | ||
650 | 'inputs': MochiKit.Base.method(this, 'inputs') | ||
651 | }, {trace:false}), | ||
652 | MochiKit.Base.bind(function (someValues) { | ||
653 | var availableBindingValues; | ||
654 | var inputRequiringBindingValues; | ||
655 | var newBindingValues; | ||
656 | |||
657 | if (MochiKit.Base.isUndefinedOrNull(someValues['originalValues']) || MochiKit.Base.isUndefinedOrNull(someValues['originalValues']['bindingData'])) { | ||
658 | availableBindingValues = {}; | ||
659 | } else { | ||
660 | availableBindingValues = Clipperz.Base.deepClone(someValues['originalValues']['bindingData']) | ||
661 | } | ||
662 | |||
663 | if (someValues['currentValues'] != null) { | ||
664 | MochiKit.Base.update(availableBindingValues, someValues['currentValues']['bindingData']); | ||
665 | } | ||
666 | |||
667 | this._bindings = {}; | ||
668 | newBindingValues = {} | ||
669 | MochiKit.Iter.forEach(MochiKit.Base.filter(MochiKit.Base.methodcaller('needsBinding'), MochiKit.Base.values(someValues['inputs'])), MochiKit.Base.bind(function (anInput) { | ||
670 | varnewBinding; | ||
671 | |||
672 | newBindingValues[anInput.name()] = availableBindingValues[anInput.name()]; | ||
673 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { | ||
674 | 'key': anInput.name(), | ||
675 | 'field':availableBindingValues[anInput.name()] | ||
676 | }); | ||
677 | |||
678 | this._bindings[anInput.name()] = newBinding; | ||
679 | }, this)) | ||
680 | //console.log("THIS._BINDINGS", this._bindings); | ||
681 | |||
682 | return newBindingValues; | ||
683 | |||
684 | /* | ||
685 | this._bindings = {}; | ||
686 | //console.log("CONFIGURATION", aConfiguration); | ||
687 | |||
688 | if (someValues['currentValues'] != null) { | ||
689 | if (someValues['currentValues']['bindingData'] != null) { | ||
690 | var bindingKey; | ||
691 | |||
692 | //console.log("BINDING DATA", someValues['currentValues']['bindingData']); | ||
693 | for (bindingKey in someValues['currentValues']['bindingData']) { | ||
694 | var newBinding; | ||
695 | |||
696 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { | ||
697 | 'key': bindingKey, | ||
698 | 'field':someValues['currentValues']['bindingData'][bindingKey] | ||
699 | }); | ||
700 | this._bindings[newBinding.key()] = newBinding; | ||
701 | } | ||
702 | } else if (someValues['currentValues']['legacyBindingData'] == null) { | ||
703 | var bindingKey; | ||
704 | |||
705 | for (bindingKey in someValues['currentValues']['legacyBindingData']) { | ||
706 | var newBinding; | ||
707 | |||
708 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(this, { | ||
709 | 'key': bindingKey, | ||
710 | 'field':someValues['currentValues']['legacyBindingData'][bindingKey] | ||
711 | }); | ||
712 | this._bindings[newBinding.key()] = newBinding; | ||
713 | } | ||
714 | } else { | ||
715 | WTF = TODO; | ||
716 | } | ||
717 | } | ||
718 | |||
719 | return this._bindings; | ||
720 | */ | ||
721 | }, this), | ||
722 | MochiKit.Base.method(this, 'setValue', 'bindingData') | ||
723 | ], {trace:false}); | ||
724 | }, | ||
725 | |||
726 | //========================================================================= | ||
727 | |||
728 | 'formValues': function () { | ||
729 | return Clipperz.Async.callbacks("DirectLogin.formValues", [ | ||
730 | Clipperz.Async.deferredIf("this._formValues is defined", [ | ||
731 | ], [ | ||
732 | MochiKit.Base.method(this, 'updateFormValuesAfterChangingBookmarkletConfiguration'), | ||
733 | MochiKit.Base.bind(function () { return this._formValues;}, this) | ||
734 | ]) | ||
735 | ], {trace:false}, this._formValues); | ||
736 | }, | ||
737 | |||
738 | //------------------------------------------------------------------------- | ||
739 | |||
740 | 'updateFormValuesAfterChangingBookmarkletConfiguration': function () { | ||
741 | return Clipperz.Async.callbacks("DirectLogin.updateFormValuesAfterChangingBookmarkletConfiguration", [ | ||
742 | Clipperz.Async.collectResults("DirectLogin.updateFormValuesAfterChangingBookmarkletConfiguration <collect results>", { | ||
743 | 'currentValues':MochiKit.Base.method(this, 'getValue', ''), | ||
744 | 'originalValues':MochiKit.Base.method(this, 'originalConfiguration'), | ||
745 | 'inputs': MochiKit.Base.method(this, 'inputs') | ||
746 | }, {trace:false}), | ||
747 | MochiKit.Base.bind(function (someValues) { | ||
748 | var availableFormValues; | ||
749 | var inputRequiringFormValues; | ||
750 | var newFormValues; | ||
751 | |||
752 | if (MochiKit.Base.isUndefinedOrNull(someValues['originalValues']) || MochiKit.Base.isUndefinedOrNull(someValues['originalValues']['formValues'])) { | ||
753 | availableFormValues = {}; | ||
754 | } else { | ||
755 | availableFormValues = Clipperz.Base.deepClone(someValues['originalValues']['formValues']) | ||
756 | } | ||
757 | |||
758 | MochiKit.Base.update(availableFormValues, someValues['currentValues']['formValues']); | ||
759 | |||
760 | this._formValues = {}; | ||
761 | newFormValues = {}; | ||
762 | MochiKit.Iter.forEach(MochiKit.Base.filter(MochiKit.Base.methodcaller('needsFormValue'), MochiKit.Base.values(someValues['inputs'])), MochiKit.Base.bind(function (anInput) { | ||
763 | varnewFormValue; | ||
764 | var fieldOptions; | ||
765 | |||
766 | fieldOptions = { | ||
767 | 'type': anInput.type(), | ||
768 | 'options':anInput.options() | ||
769 | }; | ||
770 | |||
771 | newFormValues[anInput.name()] = availableFormValues[anInput.name()] | ||
772 | newFormValue = new Clipperz.PM.DataModel.DirectLoginFormValue(this, { | ||
773 | 'key': anInput.name(), | ||
774 | 'fieldOptions':fieldOptions, | ||
775 | 'value': availableFormValues[anInput.name()] | ||
776 | }); | ||
777 | |||
778 | this._formValues[anInput.name()] = newFormValue; | ||
779 | }, this)) | ||
780 | |||
781 | return newFormValues; | ||
782 | }, this), | ||
783 | MochiKit.Base.method(this, 'setValue', 'formValues') | ||
784 | ], {trace:false}); | ||
785 | }, | ||
786 | |||
787 | //========================================================================= | ||
788 | |||
789 | 'retrieveIndexDataFunction': function () { | ||
790 | return this._retrieveIndexDataFunction; | ||
791 | }, | ||
792 | |||
793 | 'getIndexDataForKey': function (aKey) { | ||
794 | return Clipperz.Async.callbacks("DirectLogin.getIndexDataForKey", [ | ||
795 | MochiKit.Base.partial(this.retrieveIndexDataFunction(), this.reference()), | ||
796 | Clipperz.Async.deferredIf("DirectLogin.getIndexDataForKey - index data not null", [ | ||
797 | MochiKit.Base.itemgetter(aKey) | ||
798 | ],[ | ||
799 | MochiKit.Async.succeed | ||
800 | ]) | ||
801 | ], {trace:false}); | ||
802 | }, | ||
803 | |||
804 | //------------------------------------------------------------------------- | ||
805 | |||
806 | 'setIndexDataForKey': function (aKey, aValue) { | ||
807 | return Clipperz.Async.callbacks("DirectLogin.setValueForKey", [ | ||
808 | MochiKit.Base.method(this, 'getIndexDataForKey', aKey), | ||
809 | MochiKit.Base.bind(function (anActualValue) { | ||
810 | var transientStateKey; | ||
811 | |||
812 | transientStateKey = 'original_' + aKey; | ||
813 | if (MochiKit.Base.isUndefinedOrNull(this.transientState()[transientStateKey])) { | ||
814 | if (anActualValue != aValue) { | ||
815 | this.transientState()[transientStateKey] = anActualValue; | ||
816 | } | ||
817 | } else if (this.transientState()[transientStateKey] == aValue) { | ||
818 | this.transientState()[transientStateKey] = null; | ||
819 | } | ||
820 | }, this), | ||
821 | MochiKit.Base.partial(this._setIndexDataFunction, this.reference(), aKey, aValue) | ||
822 | ], {trace:false}) | ||
823 | }, | ||
824 | |||
825 | //------------------------------------------------------------------------- | ||
826 | /* | ||
827 | 'setValueForKey': function (aKey, aValue) { | ||
828 | return Clipperz.Async.callbacks("DirectLogin.setValueForKey", [ | ||
829 | MochiKit.Base.method(this, 'getIndexDataForKey', aKey), | ||
830 | MochiKit.Base.bind(function (anActualValue) { | ||
831 | var transientStateKey; | ||
832 | |||
833 | transientStateKey = 'original_' + aKey; | ||
834 | if (MochiKit.Base.isUndefinedOrNull(this.transientState()[transientStateKey])) { | ||
835 | if (anActualValue != aValue) { | ||
836 | this.transientState()[transientStateKey] = anActualValue; | ||
837 | } | ||
838 | } else if (this.transientState()[transientStateKey] == aValue) { | ||
839 | this.transientState()[transientStateKey] = null; | ||
840 | } | ||
841 | }, this), | ||
842 | MochiKit.Base.method(this, 'setIndexDataForKey', aKey, aValue) | ||
843 | ], {trace:false}) | ||
844 | }, | ||
845 | */ | ||
846 | //========================================================================= | ||
847 | /* | ||
848 | 'storedConfiguration': function () { | ||
849 | return this.record().getValue('directLogins' + '.' + this.reference()); | ||
850 | }, | ||
851 | |||
852 | //'setStoredConfiguration': function (aValue) { | ||
853 | // return this.record().setValue('directLogins' + '.' + this.reference(), aValue); | ||
854 | //}, | ||
855 | */ | ||
856 | //========================================================================= | ||
857 | |||
858 | 'hasPendingChanges': function () { | ||
859 | varresult; | ||
860 | var deferredResult; | ||
861 | |||
862 | result = false; | ||
863 | result = result || this.isBrandNew(); | ||
864 | result = result || (! MochiKit.Base.isUndefinedOrNull(this.transientState()['original_label'])); | ||
865 | result = result || (! MochiKit.Base.isUndefinedOrNull(this.transientState()['original_favicon'])); | ||
866 | |||
867 | if ((result == false) && (this.originalConfiguration() != null)) { | ||
868 | deferredResult = Clipperz.Async.callbacks("DirectLogin.hasPendingChanges", [ | ||
869 | MochiKit.Base.method(this, 'serializedData'), | ||
870 | MochiKit.Base.bind(function (aCurrentConfiguration) { | ||
871 | varoriginalConfiguration; | ||
872 | var currentConfiguration; | ||
873 | var result; | ||
874 | |||
875 | originalConfiguration = this.originalConfiguration(); | ||
876 | currentConfiguration = aCurrentConfiguration; | ||
877 | |||
878 | result = false; | ||
879 | result = result || (MochiKit.Base.compare(originalConfiguration['bookmarkletVersion'], currentConfiguration['bookmarkletVersion'])!= 0); | ||
880 | result = result || (MochiKit.Base.compare(originalConfiguration['formData'], currentConfiguration['formData']) != 0); | ||
881 | result = result || (MochiKit.Base.compare(originalConfiguration['formValues'], currentConfiguration['formValues']) != 0); | ||
882 | result = result || (MochiKit.Base.compare(originalConfiguration['bindingData'], currentConfiguration['bindingData']) != 0); | ||
883 | |||
884 | return result; | ||
885 | }, this) | ||
886 | ], {trace:false}); | ||
887 | } else { | ||
888 | deferredResult = MochiKit.Async.succeed(result); | ||
889 | } | ||
890 | |||
891 | return deferredResult; | ||
892 | }, | ||
893 | |||
894 | //------------------------------------------------------------------------- | ||
895 | |||
896 | 'revertChanges': function () { | ||
897 | var deferredResult; | ||
898 | |||
899 | if (this.transientState()['original_label'] != null) { | ||
900 | this.setLabel(this.transientState()['original_label']); | ||
901 | } | ||
902 | |||
903 | if (this.transientState()['original_favicon'] != null) { | ||
904 | this.setFavicon(this.transientState()['original_favicon']); | ||
905 | } | ||
906 | |||
907 | if (this.originalConfiguration() != null) { | ||
908 | deferredResult = this.setValue('', this.originalConfiguration()); | ||
909 | } else { | ||
910 | deferredResult = MochiKit.Async.succeed(); | ||
911 | } | ||
912 | |||
913 | this._inputs = null; | ||
914 | this._bindings = null; | ||
915 | this._formValues= null; | ||
916 | |||
917 | this.resetTransientState(false); | ||
918 | |||
919 | /* | ||
920 | if (this.hasInitiatedObjectDataStore()) { | ||
921 | deferredResult = Clipperz.Async.callbacks("DirectLogin.revertChanges", [ | ||
922 | // MochiKit.Base.method(this.record(), 'setValue', 'directLogins' + '.' + this.reference(), this.originalState()), | ||
923 | MochiKit.Base.method(this, 'setValue', '', this.originalState()), | ||
924 | MochiKit.Base.method(this, 'resetObjectDataStore') | ||
925 | ], {trace:false}) | ||
926 | } else { | ||
927 | deferredResult = MochiKit.Async.succeed(); | ||
928 | } | ||
929 | */ | ||
930 | return deferredResult; | ||
931 | }, | ||
932 | |||
933 | |||
934 | //========================================================================= | ||
935 | |||
936 | 'transientState': function () { | ||
937 | if (this._transientState == null) { | ||
938 | this._transientState = {} | ||
939 | } | ||
940 | |||
941 | return this._transientState; | ||
942 | }, | ||
943 | |||
944 | 'resetTransientState': function (isCommitting) { | ||
945 | this._transientState = null; | ||
946 | }, | ||
947 | |||
948 | 'commitTransientState': function (isCommitting) { | ||
949 | this._transientState = null; | ||
950 | this._isBrandNew = false; | ||
951 | }, | ||
952 | |||
953 | //------------------------------------------------------------------------- | ||
954 | |||
955 | 'originalConfiguration': function () { | ||
956 | return this.transientState()['original_configuration']; | ||
957 | }, | ||
958 | |||
959 | 'setOriginalConfiguration': function (aConfiguration) { | ||
960 | this.transientState()['original_configuration'] = Clipperz.Base.deepClone(aConfiguration); | ||
961 | }, | ||
962 | |||
963 | //========================================================================= | ||
964 | |||
965 | 'actualKey': function (aValueKey) { | ||
966 | var actualKey; | ||
967 | |||
968 | actualKey = 'directLogins' + '.' + this.reference(); | ||
969 | if (aValueKey != '') { | ||
970 | actualKey = actualKey + '.' + aValueKey; | ||
971 | } | ||
972 | |||
973 | return actualKey; | ||
974 | }, | ||
975 | |||
976 | //------------------------------------------------------------------------- | ||
977 | |||
978 | 'getValue': function (aValueKey) { | ||
979 | return this.record().getValue(this.actualKey(aValueKey)); | ||
980 | }, | ||
981 | |||
982 | 'setValue': function (aValueKey, aValue) { | ||
983 | // return this.record().setValue(this.actualKey(aValueKey), aValue); | ||
984 | |||
985 | return Clipperz.Async.callbacks("DirectLogin.setValue", [ | ||
986 | MochiKit.Base.method(this, 'getValue', ''), | ||
987 | MochiKit.Base.bind(function (aValue) { | ||
988 | if (this.originalConfiguration() == null) { | ||
989 | this.setOriginalConfiguration(aValue); | ||
990 | } | ||
991 | }, this), | ||
992 | // MochiKit.Base.method(this, 'originalConfiguration'), | ||
993 | // Clipperz.Async.deferredIf("originalConfiguration has been set", [ | ||
994 | // ], [ | ||
995 | // MochiKit.Base.method(this, 'getValue', ''), | ||
996 | // MochiKit.Base.method(this, 'setOriginalConfiguration') | ||
997 | // ]), | ||
998 | MochiKit.Base.method(this.record(), 'setValue', this.actualKey(aValueKey), aValue) | ||
999 | ], {trace:false}); | ||
1000 | }, | ||
1001 | |||
1002 | 'removeValue': function (aValueKey) { | ||
1003 | // return this.record().removeValue(this.actualKey(aValueKey)); | ||
1004 | |||
1005 | return Clipperz.Async.callbacks("DirectLogin.setValue", [ | ||
1006 | MochiKit.Base.method(this, 'originalConfiguration'), | ||
1007 | Clipperz.Async.deferredIf("originalConfiguration has been set", [ | ||
1008 | ], [ | ||
1009 | MochiKit.Base.method(this, 'getValue', ''), | ||
1010 | MochiKit.Base.method(this, 'setOriginalConfiguration') | ||
1011 | ]), | ||
1012 | MochiKit.Base.method(this.record(), 'removeValue', this.actualKey(aValueKey)) | ||
1013 | ], {trace:false}); | ||
1014 | }, | ||
1015 | |||
1016 | //========================================================================= | ||
1017 | |||
1018 | 'deleteAllCleanTextData': function () { | ||
1019 | this._inputs = null; | ||
1020 | this._bindings = null; | ||
1021 | this._formValues = null; | ||
1022 | |||
1023 | this.resetTransientState(); | ||
1024 | }, | ||
1025 | |||
1026 | //------------------------------------------------------------------------- | ||
1027 | |||
1028 | 'hasAnyCleanTextData': function () { | ||
1029 | var result; | ||
1030 | |||
1031 | result = false; | ||
1032 | |||
1033 | result = result || (this._inputs != null); | ||
1034 | result = result || (this._bindings != null); | ||
1035 | result = result || (this._formValues != null); | ||
1036 | result = result || (MochiKit.Base.keys(this.transientState()).length != 0); | ||
1037 | |||
1038 | return MochiKit.Async.succeed(result); | ||
1039 | }, | ||
1040 | |||
1041 | //========================================================================= | ||
1042 | __syntaxFix__: "syntax fix" | ||
1043 | }); | ||
1044 | |||
1045 | //############################################################################# | ||
1046 | |||
1047 | Clipperz.PM.DataModel.DirectLogin.exception = { | ||
1048 | 'WrongBookmarkletConfiguration': new MochiKit.Base.NamedError("Clipperz.PM.DataModel.DirectLogin.exception.WrongBookmarkletConfiguration") | ||
1049 | }; | ||
1050 | |||
1051 | Clipperz.PM.DataModel.DirectLogin.checkBookmarkletConfiguration = function(aConfiguration) { | ||
1052 | var configuration; | ||
1053 | |||
1054 | try { | ||
1055 | configuration = Clipperz.Base.evalJSON(aConfiguration); | ||
1056 | // configuration = Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration(configuration); | ||
1057 | |||
1058 | if (MochiKit.Base.isUndefinedOrNull(configuration['page']['title']) | ||
1059 | ||MochiKit.Base.isUndefinedOrNull(configuration['form']['attributes']['action']) | ||
1060 | // ||MochiKit.Base.isUndefinedOrNull(configuration['form']['attributes']['method']) | ||
1061 | ||MochiKit.Base.isUndefinedOrNull(configuration['form']['inputs']) | ||
1062 | ||MochiKit.Base.isUndefinedOrNull(configuration['version']) | ||
1063 | ) { | ||
1064 | throw Clipperz.PM.DataModel.DirectLogin.exception.WrongBookmarkletConfiguration; | ||
1065 | } | ||
1066 | |||
1067 | // if (MochiKit.Base.isUndefinedOrNull(configuration['favicon'])) { | ||
1068 | // throw Clipperz.PM.DataModel.DirectLogin.exception.WrongBookmarkletConfiguration; | ||
1069 | // } | ||
1070 | |||
1071 | } catch (exception) { | ||
1072 | throw exception; | ||
1073 | } | ||
1074 | |||
1075 | return configuration; | ||
1076 | }; | ||