author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/PM/DataModel | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel') (more/less context) (ignore whitespace changes)
14 files changed, 165 insertions, 262 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,118 +1,116 @@ | |||
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 | ||
71 | //========================================================================= | 69 | //========================================================================= |
72 | 70 | ||
73 | 'reference': function () { | 71 | 'reference': function () { |
74 | return this._reference; | 72 | return this._reference; |
75 | }, | 73 | }, |
76 | 74 | ||
77 | //------------------------------------------------------------------------- | 75 | //------------------------------------------------------------------------- |
78 | 76 | ||
79 | 'record': function () { | 77 | 'record': function () { |
80 | return this._record; | 78 | return this._record; |
81 | }, | 79 | }, |
82 | 80 | ||
83 | //========================================================================= | 81 | //========================================================================= |
84 | 82 | ||
85 | 'isBrandNew': function () { | 83 | 'isBrandNew': function () { |
86 | return this._isBrandNew; | 84 | return this._isBrandNew; |
87 | }, | 85 | }, |
88 | 86 | ||
89 | //========================================================================= | 87 | //========================================================================= |
90 | 88 | ||
91 | 'removeIndexDataFunction': function () { | 89 | 'removeIndexDataFunction': function () { |
92 | return this._removeIndexDataFunction; | 90 | return this._removeIndexDataFunction; |
93 | }, | 91 | }, |
94 | 92 | ||
95 | 'remove': function () { | 93 | 'remove': function () { |
96 | return Clipperz.Async.callbacks("DirectLogin.remove", [ | 94 | return Clipperz.Async.callbacks("DirectLogin.remove", [ |
97 | MochiKit.Base.partial(this.removeIndexDataFunction(), this.reference()), | 95 | MochiKit.Base.partial(this.removeIndexDataFunction(), this.reference()), |
98 | MochiKit.Base.method(this.record(), 'removeDirectLogin', this) | 96 | MochiKit.Base.method(this.record(), 'removeDirectLogin', this) |
99 | ], {trace:false}); | 97 | ], {trace:false}); |
100 | }, | 98 | }, |
101 | 99 | ||
102 | //========================================================================= | 100 | //========================================================================= |
103 | /* | 101 | /* |
104 | 'inputsDeferredLock': function () { | 102 | 'inputsDeferredLock': function () { |
105 | return this._inputsDeferredLock; | 103 | return this._inputsDeferredLock; |
106 | }, | 104 | }, |
107 | 105 | ||
108 | 'bindingsDeferredLock': function () { | 106 | 'bindingsDeferredLock': function () { |
109 | return this._bindingsDeferredLock; | 107 | return this._bindingsDeferredLock; |
110 | }, | 108 | }, |
111 | 109 | ||
112 | 'formValuesDeferredLock': function () { | 110 | 'formValuesDeferredLock': function () { |
113 | return this._formValuesDeferredLock; | 111 | return this._formValuesDeferredLock; |
114 | }, | 112 | }, |
115 | */ | 113 | */ |
116 | //========================================================================= | 114 | //========================================================================= |
117 | 115 | ||
118 | 'label': function () { | 116 | 'label': function () { |
@@ -236,550 +234,542 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, { | |||
236 | 'serializedData': function () { | 234 | 'serializedData': function () { |
237 | return Clipperz.Async.collectResults("DirectLogin.serializedData", { | 235 | return Clipperz.Async.collectResults("DirectLogin.serializedData", { |
238 | 'bookmarkletVersion': MochiKit.Base.method(this, 'getValue', 'bookmarkletVersion'), | 236 | 'bookmarkletVersion': MochiKit.Base.method(this, 'getValue', 'bookmarkletVersion'), |
239 | 'formData': MochiKit.Base.method(this, 'getValue', 'formData'), | 237 | 'formData': MochiKit.Base.method(this, 'getValue', 'formData'), |
240 | 'formValues': MochiKit.Base.method(this, 'getValue', 'formValues'), | 238 | 'formValues': MochiKit.Base.method(this, 'getValue', 'formValues'), |
241 | 'bindingData': [ | 239 | 'bindingData': [ |
242 | MochiKit.Base.method(this, 'bindings'), | 240 | MochiKit.Base.method(this, 'bindings'), |
243 | function (someBindings) { | 241 | function (someBindings) { |
244 | var result; | 242 | var result; |
245 | var bindingKey; | 243 | var bindingKey; |
246 | 244 | ||
247 | result = {} | 245 | result = {} |
248 | for (bindingKey in someBindings) { | 246 | for (bindingKey in someBindings) { |
249 | result[bindingKey] = someBindings[bindingKey].serializedData(); | 247 | result[bindingKey] = someBindings[bindingKey].serializedData(); |
250 | } | 248 | } |
251 | 249 | ||
252 | return result; | 250 | return result; |
253 | } | 251 | } |
254 | ] | 252 | ] |
255 | }, {trace:false})() | 253 | }, {trace:false})() |
256 | }, | 254 | }, |
257 | 255 | ||
258 | //========================================================================= | 256 | //========================================================================= |
259 | /* | 257 | /* |
260 | 'fixFormDataFromBookmarkletVersion_0_1': function(aValue) { | 258 | 'fixFormDataFromBookmarkletVersion_0_1': function(aValue) { |
261 | //{"type":"radio", "name":"action", "value":"new-user", "checked":false }, { "type":"radio", "name":"action", "value":"sign-in", "checked":true } | 259 | //{"type":"radio", "name":"action", "value":"new-user", "checked":false }, { "type":"radio", "name":"action", "value":"sign-in", "checked":true } |
262 | // || | 260 | // || |
263 | // \ / | 261 | // \ / |
264 | // \/ | 262 | // \/ |
265 | //{"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}]} | 263 | //{"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}]} |
266 | var result; | 264 | var result; |
267 | var inputs; | 265 | var inputs; |
268 | var updatedInputs; | 266 | var updatedInputs; |
269 | var radios; | 267 | var radios; |
270 | 268 | ||
271 | result = aValue; | 269 | result = aValue; |
272 | inputs = aValue['inputs']; | 270 | inputs = aValue['inputs']; |
273 | 271 | ||
274 | updatedInputs = MochiKit.Base.filter(function(anInput) { | 272 | updatedInputs = MochiKit.Base.filter(function(anInput) { |
275 | varresult; | 273 | varresult; |
276 | var type; | 274 | var type; |
277 | 275 | ||
278 | type = anInput['type'] || 'text'; | 276 | type = anInput['type'] || 'text'; |
279 | result = type.toLowerCase() != 'radio'; | 277 | result = type.toLowerCase() != 'radio'; |
280 | 278 | ||
281 | return result; | 279 | return result; |
282 | }, inputs); | 280 | }, inputs); |
283 | radios = MochiKit.Base.filter(function(anInput) { | 281 | radios = MochiKit.Base.filter(function(anInput) { |
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 | } |
381 | 379 | ||
382 | } else { | 380 | } else { |
383 | var bindingKey; | 381 | var bindingKey; |
384 | 382 | ||
385 | for (bindingKey in aConfiguration['legacyBindingData']) { | 383 | for (bindingKey in aConfiguration['legacyBindingData']) { |
386 | var newBinding; | 384 | var newBinding; |
387 | 385 | ||
388 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldName:aConfiguration['legacyBindingData'][bindingKey]}); | 386 | newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldName:aConfiguration['legacyBindingData'][bindingKey]}); |
389 | aConfiguration['_bindings'][newBinding.key()] = newBinding; | 387 | aConfiguration['_bindings'][newBinding.key()] = newBinding; |
390 | } | 388 | } |
391 | } | 389 | } |
392 | * / | 390 | * / |
393 | 391 | ||
394 | return fixedConfiguration; | 392 | return fixedConfiguration; |
395 | }, | 393 | }, |
396 | 394 | ||
397 | //------------------------------------------------------------------------- | 395 | //------------------------------------------------------------------------- |
398 | 396 | ||
399 | 'getObjectDataStore': function () { | 397 | 'getObjectDataStore': function () { |
400 | var deferredResult; | 398 | var deferredResult; |
401 | 399 | ||
402 | deferredResult = new Clipperz.Async.Deferred("DirectLogin.getObjectDataStore", {trace:false}); | 400 | deferredResult = new Clipperz.Async.Deferred("DirectLogin.getObjectDataStore", {trace:false}); |
403 | deferredResult.acquireLock(this.objectDataStoreDeferredLock()); | 401 | deferredResult.acquireLock(this.objectDataStoreDeferredLock()); |
404 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 402 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
405 | var innerDeferredResult; | 403 | var innerDeferredResult; |
406 | 404 | ||
407 | if (this._objectDataStore == null) { | 405 | if (this._objectDataStore == null) { |
408 | this._objectDataStore = new Clipperz.KeyValueObjectStore(); | 406 | this._objectDataStore = new Clipperz.KeyValueObjectStore(); |
409 | 407 | ||
410 | innerDeferredResult = new Clipperz.Async.Deferred("DirectLogin.getObjectDataStore <inner deferred>", {trace:false}); | 408 | innerDeferredResult = new Clipperz.Async.Deferred("DirectLogin.getObjectDataStore <inner deferred>", {trace:false}); |
411 | // innerDeferredResult.addMethod(this.record(), 'getValue', 'directLogins' + '.' + this.reference()); | 409 | // innerDeferredResult.addMethod(this.record(), 'getValue', 'directLogins' + '.' + this.reference()); |
412 | innerDeferredResult.addMethod(this, 'getValue', ''), | 410 | innerDeferredResult.addMethod(this, 'getValue', ''), |
413 | innerDeferredResult.addMethod(this, 'setOriginalState'); | 411 | innerDeferredResult.addMethod(this, 'setOriginalState'); |
414 | innerDeferredResult.addMethod(this, '_fixConfiguration'); | 412 | innerDeferredResult.addMethod(this, '_fixConfiguration'); |
415 | innerDeferredResult.addMethod(this._objectDataStore, 'initWithValues'); | 413 | innerDeferredResult.addMethod(this._objectDataStore, 'initWithValues'); |
416 | // innerDeferredResult.addMethod(this._objectDataStore, 'setValues'); | 414 | // innerDeferredResult.addMethod(this._objectDataStore, 'setValues'); |
417 | innerDeferredResult.callback(); | 415 | innerDeferredResult.callback(); |
418 | } else { | 416 | } else { |
419 | innerDeferredResult = MochiKit.Async.succeed(this._objectDataStore); | 417 | innerDeferredResult = MochiKit.Async.succeed(this._objectDataStore); |
420 | } | 418 | } |
421 | 419 | ||
422 | return innerDeferredResult; | 420 | return innerDeferredResult; |
423 | }, this)); | 421 | }, this)); |
424 | deferredResult.releaseLock(this.objectDataStoreDeferredLock()); | 422 | deferredResult.releaseLock(this.objectDataStoreDeferredLock()); |
425 | deferredResult.callback(); | 423 | deferredResult.callback(); |
426 | 424 | ||
427 | return deferredResult; | 425 | return deferredResult; |
428 | }, | 426 | }, |
429 | 427 | ||
430 | //------------------------------------------------------------------------- | 428 | //------------------------------------------------------------------------- |
431 | 429 | ||
432 | 'hasInitiatedObjectDataStore': function () { | 430 | 'hasInitiatedObjectDataStore': function () { |
433 | return (this._objectDataStore != null); | 431 | return (this._objectDataStore != null); |
434 | }, | 432 | }, |
435 | 433 | ||
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': [ |
602 | MochiKit.Base.method(this, 'bindings'), | 595 | MochiKit.Base.method(this, 'bindings'), |
603 | MochiKit.Base.itemgetter(aFormFieldLabel) | 596 | MochiKit.Base.itemgetter(aFormFieldLabel) |
604 | ], | 597 | ], |
605 | 'field': [ | 598 | 'field': [ |
606 | MochiKit.Base.method(this.record(), 'fieldWithLabel', aRecordFieldLabel) | 599 | MochiKit.Base.method(this.record(), 'fieldWithLabel', aRecordFieldLabel) |
607 | ] | 600 | ] |
608 | }), | 601 | }), |
609 | function (someValues) { | 602 | function (someValues) { |
610 | someValues['binding'].setField(someValues['field']) | 603 | someValues['binding'].setField(someValues['field']) |
611 | } | 604 | } |
612 | ], {trace:false}); | 605 | ], {trace:false}); |
613 | }, | 606 | }, |
614 | 607 | ||
615 | //------------------------------------------------------------------------- | 608 | //------------------------------------------------------------------------- |
616 | /* | 609 | /* |
617 | 'bindingValues': function () { | 610 | 'bindingValues': function () { |
618 | return Clipperz.Async.callbacks("DirectLogin.bindingValues", [ | 611 | return Clipperz.Async.callbacks("DirectLogin.bindingValues", [ |
619 | Clipperz.Async.collectResults("DirectLogin.bindingValues [collectResults]", { | 612 | Clipperz.Async.collectResults("DirectLogin.bindingValues [collectResults]", { |
620 | 'fieldValues': [ | 613 | 'fieldValues': [ |
621 | MochiKit.Base.method(this, 'record'), | 614 | MochiKit.Base.method(this, 'record'), |
622 | MochiKit.Base.methodcaller('getFieldsValues') | 615 | MochiKit.Base.methodcaller('getFieldsValues') |
623 | ], | 616 | ], |
624 | 'bindings': MochiKit.Base.method(this, 'bindings') | 617 | 'bindings': MochiKit.Base.method(this, 'bindings') |
625 | }, {trace:false}), | 618 | }, {trace:false}), |
626 | function (someData) { | 619 | function (someData) { |
627 | var result; | 620 | var result; |
628 | varbindingKey; | 621 | varbindingKey; |
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 () { |
738 | return Clipperz.Async.callbacks("DirectLogin.updateFormValuesAfterChangingBookmarkletConfiguration", [ | 728 | return Clipperz.Async.callbacks("DirectLogin.updateFormValuesAfterChangingBookmarkletConfiguration", [ |
739 | Clipperz.Async.collectResults("DirectLogin.updateFormValuesAfterChangingBookmarkletConfiguration <collect results>", { | 729 | Clipperz.Async.collectResults("DirectLogin.updateFormValuesAfterChangingBookmarkletConfiguration <collect results>", { |
740 | 'currentValues':MochiKit.Base.method(this, 'getValue', ''), | 730 | 'currentValues':MochiKit.Base.method(this, 'getValue', ''), |
741 | 'originalValues':MochiKit.Base.method(this, 'originalConfiguration'), | 731 | 'originalValues':MochiKit.Base.method(this, 'originalConfiguration'), |
742 | 'inputs': MochiKit.Base.method(this, 'inputs') | 732 | 'inputs': MochiKit.Base.method(this, 'inputs') |
743 | }, {trace:false}), | 733 | }, {trace:false}), |
744 | MochiKit.Base.bind(function (someValues) { | 734 | MochiKit.Base.bind(function (someValues) { |
745 | var availableFormValues; | 735 | var availableFormValues; |
746 | var inputRequiringFormValues; | 736 | var inputRequiringFormValues; |
747 | var newFormValues; | 737 | var newFormValues; |
748 | 738 | ||
749 | if (MochiKit.Base.isUndefinedOrNull(someValues['originalValues']) || MochiKit.Base.isUndefinedOrNull(someValues['originalValues']['formValues'])) { | 739 | if (MochiKit.Base.isUndefinedOrNull(someValues['originalValues']) || MochiKit.Base.isUndefinedOrNull(someValues['originalValues']['formValues'])) { |
750 | availableFormValues = {}; | 740 | availableFormValues = {}; |
751 | } else { | 741 | } else { |
752 | availableFormValues = Clipperz.Base.deepClone(someValues['originalValues']['formValues']) | 742 | availableFormValues = Clipperz.Base.deepClone(someValues['originalValues']['formValues']) |
753 | } | 743 | } |
754 | 744 | ||
755 | MochiKit.Base.update(availableFormValues, someValues['currentValues']['formValues']); | 745 | MochiKit.Base.update(availableFormValues, someValues['currentValues']['formValues']); |
756 | 746 | ||
757 | this._formValues = {}; | 747 | this._formValues = {}; |
758 | newFormValues = {}; | 748 | newFormValues = {}; |
759 | MochiKit.Iter.forEach(MochiKit.Base.filter(MochiKit.Base.methodcaller('needsFormValue'), MochiKit.Base.values(someValues['inputs'])), MochiKit.Base.bind(function (anInput) { | 749 | MochiKit.Iter.forEach(MochiKit.Base.filter(MochiKit.Base.methodcaller('needsFormValue'), MochiKit.Base.values(someValues['inputs'])), MochiKit.Base.bind(function (anInput) { |
760 | varnewFormValue; | 750 | varnewFormValue; |
761 | var fieldOptions; | 751 | var fieldOptions; |
762 | 752 | ||
763 | fieldOptions = { | 753 | fieldOptions = { |
764 | 'type': anInput.type(), | 754 | 'type': anInput.type(), |
765 | 'options':anInput.options() | 755 | 'options':anInput.options() |
766 | }; | 756 | }; |
767 | 757 | ||
768 | newFormValues[anInput.name()] = availableFormValues[anInput.name()] | 758 | newFormValues[anInput.name()] = availableFormValues[anInput.name()] |
769 | newFormValue = new Clipperz.PM.DataModel.DirectLoginFormValue(this, { | 759 | newFormValue = new Clipperz.PM.DataModel.DirectLoginFormValue(this, { |
770 | 'key': anInput.name(), | 760 | 'key': anInput.name(), |
771 | 'fieldOptions':fieldOptions, | 761 | 'fieldOptions':fieldOptions, |
772 | 'value': availableFormValues[anInput.name()] | 762 | 'value': availableFormValues[anInput.name()] |
773 | }); | 763 | }); |
774 | 764 | ||
775 | this._formValues[anInput.name()] = newFormValue; | 765 | this._formValues[anInput.name()] = newFormValue; |
776 | }, this)) | 766 | }, this)) |
777 | 767 | ||
778 | return newFormValues; | 768 | return newFormValues; |
779 | }, this), | 769 | }, this), |
780 | MochiKit.Base.method(this, 'setValue', 'formValues') | 770 | MochiKit.Base.method(this, 'setValue', 'formValues') |
781 | ], {trace:false}); | 771 | ], {trace:false}); |
782 | }, | 772 | }, |
783 | 773 | ||
784 | //========================================================================= | 774 | //========================================================================= |
785 | 775 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginBinding.js b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginBinding.js index 4377853..a8ebb97 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginBinding.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginBinding.js | |||
@@ -1,118 +1,116 @@ | |||
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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | 28 | ||
31 | //############################################################################# | 29 | //############################################################################# |
32 | 30 | ||
33 | Clipperz.PM.DataModel.DirectLoginBinding = function(aDirectLogin, args) { | 31 | Clipperz.PM.DataModel.DirectLoginBinding = function(aDirectLogin, args) { |
34 | args = args || {}; | 32 | args = args || {}; |
35 | 33 | ||
36 | this._directLogin = aDirectLogin|| Clipperz.Base.exception.raise('MandatoryParameter'); | 34 | this._directLogin = aDirectLogin|| Clipperz.Base.exception.raise('MandatoryParameter'); |
37 | 35 | ||
38 | this._key = args.key|| Clipperz.Base.exception.raise('MandatoryParameter'); | 36 | this._key = args.key|| Clipperz.Base.exception.raise('MandatoryParameter'); |
39 | this._fieldKey = args.field || /* this.directLogin().fieldWithName(args.fieldName).reference() || */null; | 37 | this._fieldKey = args.field || /* this.directLogin().fieldWithName(args.fieldName).reference() || */null; |
40 | 38 | ||
41 | return this; | 39 | return this; |
42 | } | 40 | } |
43 | 41 | ||
44 | Clipperz.PM.DataModel.DirectLoginBinding.prototype = MochiKit.Base.update(null, { | 42 | Clipperz.PM.DataModel.DirectLoginBinding.prototype = MochiKit.Base.update(null, { |
45 | 43 | ||
46 | 'toString': function() { | 44 | 'toString': function() { |
47 | return "DirectLoginBinding (" + this.key() + ", " + this.fieldKey() + ")"; | 45 | return "DirectLoginBinding (" + this.key() + ", " + this.fieldKey() + ")"; |
48 | }, | 46 | }, |
49 | 47 | ||
50 | //------------------------------------------------------------------------- | 48 | //------------------------------------------------------------------------- |
51 | 49 | ||
52 | 'directLogin': function () { | 50 | 'directLogin': function () { |
53 | return this._directLogin; | 51 | return this._directLogin; |
54 | }, | 52 | }, |
55 | 53 | ||
56 | //------------------------------------------------------------------------- | 54 | //------------------------------------------------------------------------- |
57 | 55 | ||
58 | 'key': function() { | 56 | 'key': function() { |
59 | return this._key; | 57 | return this._key; |
60 | }, | 58 | }, |
61 | 59 | ||
62 | //------------------------------------------------------------------------- | 60 | //------------------------------------------------------------------------- |
63 | 61 | ||
64 | 'fieldKey': function() { | 62 | 'fieldKey': function() { |
65 | return this._fieldKey; | 63 | return this._fieldKey; |
66 | }, | 64 | }, |
67 | 65 | ||
68 | 'setFieldKey': function(aValue) { | 66 | 'setFieldKey': function(aValue) { |
69 | this._fieldKey = aValue; | 67 | this._fieldKey = aValue; |
70 | 68 | ||
71 | return this.directLogin().setValue('bindingData' + '.' + this.key(), aValue); | 69 | return this.directLogin().setValue('bindingData' + '.' + this.key(), aValue); |
72 | }, | 70 | }, |
73 | 71 | ||
74 | //'fieldName': function() { | 72 | //'fieldName': function() { |
75 | // return this._fieldName; | 73 | // return this._fieldName; |
76 | //}, | 74 | //}, |
77 | 75 | ||
78 | //------------------------------------------------------------------------- | 76 | //------------------------------------------------------------------------- |
79 | 77 | ||
80 | 'field': function() { | 78 | 'field': function() { |
81 | var deferredResult; | 79 | var deferredResult; |
82 | 80 | ||
83 | if (this.fieldKey() != null) { | 81 | if (this.fieldKey() != null) { |
84 | deferredResult = Clipperz.Async.callbacks("DirectLoginBinding.field [1]", [ | 82 | deferredResult = Clipperz.Async.callbacks("DirectLoginBinding.field [1]", [ |
85 | MochiKit.Base.method(this.directLogin().record(), 'fields'), | 83 | MochiKit.Base.method(this.directLogin().record(), 'fields'), |
86 | MochiKit.Base.itemgetter(this.fieldKey()) | 84 | MochiKit.Base.itemgetter(this.fieldKey()) |
87 | ], {trace:false}); | 85 | ], {trace:false}); |
88 | // } else if (this.fieldName() != null) { | 86 | // } else if (this.fieldName() != null) { |
89 | // WTF = TODO; | 87 | // WTF = TODO; |
90 | // result = this.directLogin().record().fieldWithName(this.fieldName()); | 88 | // result = this.directLogin().record().fieldWithName(this.fieldName()); |
91 | // | 89 | // |
92 | // this.setFieldKey(result.key()); | 90 | // this.setFieldKey(result.key()); |
93 | } else { | 91 | } else { |
94 | deferredResult = MochiKit.Async.succeed(null); | 92 | deferredResult = MochiKit.Async.succeed(null); |
95 | } | 93 | } |
96 | 94 | ||
97 | return deferredResult; | 95 | return deferredResult; |
98 | }, | 96 | }, |
99 | 97 | ||
100 | 'setField': function (aField) { | 98 | 'setField': function (aField) { |
101 | this.setFieldKey(aField.reference()); | 99 | this.setFieldKey(aField.reference()); |
102 | }, | 100 | }, |
103 | 101 | ||
104 | //------------------------------------------------------------------------- | 102 | //------------------------------------------------------------------------- |
105 | /* | 103 | /* |
106 | 'fieldValue': function () { | 104 | 'fieldValue': function () { |
107 | return Clipperz.Async.callbacks("DirectLoginBinding.fieldValue", [ | 105 | return Clipperz.Async.callbacks("DirectLoginBinding.fieldValue", [ |
108 | MochiKit.Base.method('field'), | 106 | MochiKit.Base.method('field'), |
109 | MochiKit.Base.methodcaller('value') | 107 | MochiKit.Base.methodcaller('value') |
110 | ], {trace:false}); | 108 | ], {trace:false}); |
111 | }, | 109 | }, |
112 | */ | 110 | */ |
113 | //------------------------------------------------------------------------- | 111 | //------------------------------------------------------------------------- |
114 | 112 | ||
115 | 'serializedData': function() { | 113 | 'serializedData': function() { |
116 | return this.fieldKey(); | 114 | return this.fieldKey(); |
117 | }, | 115 | }, |
118 | 116 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginFormValue.js b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginFormValue.js index a461197..2429f88 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginFormValue.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginFormValue.js | |||
@@ -1,104 +1,101 @@ | |||
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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | 28 | ||
31 | //############################################################################# | 29 | //############################################################################# |
32 | 30 | ||
33 | Clipperz.PM.DataModel.DirectLoginFormValue = function(aDirectLogin, args) { | 31 | Clipperz.PM.DataModel.DirectLoginFormValue = function(aDirectLogin, args) { |
34 | args = args || {}; | 32 | args = args || {}; |
35 | 33 | ||
36 | this._directLogin = aDirectLogin|| Clipperz.Base.exception.raise('MandatoryParameter'); | 34 | this._directLogin = aDirectLogin|| Clipperz.Base.exception.raise('MandatoryParameter'); |
37 | 35 | ||
38 | this._key = args.key || Clipperz.Base.exception.raise('MandatoryParameter'); | 36 | this._key = args.key || Clipperz.Base.exception.raise('MandatoryParameter'); |
39 | this._fieldOptions = args.fieldOptions|| Clipperz.Base.exception.raise('MandatoryParameter'); | 37 | this._fieldOptions = args.fieldOptions|| Clipperz.Base.exception.raise('MandatoryParameter'); |
40 | this._value = args.value || null; | 38 | this._value = args.value || null; |
41 | 39 | ||
42 | return this; | 40 | return this; |
43 | } | 41 | } |
44 | 42 | ||
45 | Clipperz.PM.DataModel.DirectLoginFormValue.prototype = MochiKit.Base.update(null, { | 43 | Clipperz.PM.DataModel.DirectLoginFormValue.prototype = MochiKit.Base.update(null, { |
46 | 44 | ||
47 | 'toString': function() { | 45 | 'toString': function() { |
48 | return "DirectLoginFormValue (" + this.key() + ", " + this.value() + ")"; | 46 | return "DirectLoginFormValue (" + this.key() + ", " + this.value() + ")"; |
49 | }, | 47 | }, |
50 | 48 | ||
51 | //------------------------------------------------------------------------- | 49 | //------------------------------------------------------------------------- |
52 | 50 | ||
53 | 'directLogin': function () { | 51 | 'directLogin': function () { |
54 | return this._directLogin; | 52 | return this._directLogin; |
55 | }, | 53 | }, |
56 | 54 | ||
57 | //------------------------------------------------------------------------- | 55 | //------------------------------------------------------------------------- |
58 | 56 | ||
59 | 'key': function() { | 57 | 'key': function() { |
60 | return this._key; | 58 | return this._key; |
61 | }, | 59 | }, |
62 | 60 | ||
63 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
64 | 62 | ||
65 | 'fieldOptions': function() { | 63 | 'fieldOptions': function() { |
66 | return this._fieldOptions; | 64 | return this._fieldOptions; |
67 | }, | 65 | }, |
68 | 66 | ||
69 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
70 | 68 | ||
71 | 'type': function () { | 69 | 'type': function () { |
72 | return this.fieldOptions()['type']; | 70 | return this.fieldOptions()['type']; |
73 | }, | 71 | }, |
74 | 72 | ||
75 | //------------------------------------------------------------------------- | 73 | //------------------------------------------------------------------------- |
76 | 74 | ||
77 | 'value': function() { | 75 | 'value': function() { |
78 | varresult; | 76 | varresult; |
79 | 77 | ||
80 | result = this._value; | 78 | result = this._value; |
81 | 79 | ||
82 | // if ((result == null) && (this.type() == 'checkbox')) { | 80 | // if ((result == null) && (this.type() == 'checkbox')) { |
83 | // result = false; | 81 | // result = false; |
84 | // }; | 82 | // }; |
85 | 83 | ||
86 | return result; | 84 | return result; |
87 | }, | 85 | }, |
88 | 86 | ||
89 | 'setValue': function (aValue) { | 87 | 'setValue': function (aValue) { |
90 | //console.log("DirectLoginFormValue.setValue", aValue); | ||
91 | this._value = aValue; | 88 | this._value = aValue; |
92 | return this.directLogin().setValue('formValues' + '.' + this.key(), aValue); | 89 | return this.directLogin().setValue('formValues' + '.' + this.key(), aValue); |
93 | }, | 90 | }, |
94 | 91 | ||
95 | //------------------------------------------------------------------------- | 92 | //------------------------------------------------------------------------- |
96 | /* | 93 | /* |
97 | 'serializedData': function() { | 94 | 'serializedData': function() { |
98 | return this.value(); | 95 | return this.value(); |
99 | }, | 96 | }, |
100 | */ | 97 | */ |
101 | //------------------------------------------------------------------------- | 98 | //------------------------------------------------------------------------- |
102 | __syntaxFix__: "syntax fix" | 99 | __syntaxFix__: "syntax fix" |
103 | }); | 100 | }); |
104 | 101 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginInput.js b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginInput.js index 8188389..d9995fc 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginInput.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLoginInput.js | |||
@@ -1,200 +1,192 @@ | |||
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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | //############################################################################# | 28 | //############################################################################# |
31 | 29 | ||
32 | Clipperz.PM.DataModel.DirectLoginInput = function(args) { | 30 | Clipperz.PM.DataModel.DirectLoginInput = function(args) { |
33 | this._args = args; | 31 | this._args = args; |
34 | 32 | ||
35 | return this; | 33 | return this; |
36 | } | 34 | } |
37 | 35 | ||
38 | Clipperz.PM.DataModel.DirectLoginInput.prototype = MochiKit.Base.update(null, { | 36 | Clipperz.PM.DataModel.DirectLoginInput.prototype = MochiKit.Base.update(null, { |
39 | 37 | ||
40 | 'args': function() { | 38 | 'args': function() { |
41 | return this._args; | 39 | return this._args; |
42 | }, | 40 | }, |
43 | 41 | ||
44 | //------------------------------------------------------------------------- | 42 | //------------------------------------------------------------------------- |
45 | 43 | ||
46 | 'name': function() { | 44 | 'name': function() { |
47 | return this.args()['name']; | 45 | return this.args()['name']; |
48 | }, | 46 | }, |
49 | 47 | ||
50 | //------------------------------------------------------------------------- | 48 | //------------------------------------------------------------------------- |
51 | 49 | ||
52 | 'type': function() { | 50 | 'type': function() { |
53 | var result; | 51 | var result; |
54 | 52 | ||
55 | result = this.args()['type']; | 53 | result = this.args()['type']; |
56 | 54 | ||
57 | if (result != null) { | 55 | if (result != null) { |
58 | result = result.toLowerCase(); | 56 | result = result.toLowerCase(); |
59 | } | 57 | } |
60 | return result; | 58 | return result; |
61 | }, | 59 | }, |
62 | 60 | ||
63 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
64 | 62 | ||
65 | 'options': function() { | 63 | 'options': function() { |
66 | return this.args()['options']; | 64 | return this.args()['options']; |
67 | }, | 65 | }, |
68 | 66 | ||
69 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
70 | 68 | ||
71 | 'value': function() { | 69 | 'value': function() { |
72 | return this.args()['value']; | 70 | return this.args()['value']; |
73 | }, | 71 | }, |
74 | 72 | ||
75 | //------------------------------------------------------------------------- | 73 | //------------------------------------------------------------------------- |
76 | /* | 74 | /* |
77 | 'formConfiguration': function(someFormValues, someBindings, someFields) { | 75 | 'formConfiguration': function(someFormValues, someBindings, someFields) { |
78 | var result; | 76 | var result; |
79 | //console.log("### DirectLoginInput.formConfiguration", someFields); | 77 | |
80 | if (this.shouldSetValue()) { | 78 | if (this.shouldSetValue()) { |
81 | switch (this.type()) { | 79 | switch (this.type()) { |
82 | case 'select': | 80 | case 'select': |
83 | var currentValue; | 81 | var currentValue; |
84 | var options; | 82 | var options; |
85 | 83 | ||
86 | // currentValue = this.directLogin()._configuration['formValues'][this.name()]; | 84 | // currentValue = this.directLogin()._configuration['formValues'][this.name()]; |
87 | currentValue = someFormValues[this.name()]; | 85 | currentValue = someFormValues[this.name()]; |
88 | options = this.args()['options']; | 86 | options = this.args()['options']; |
89 | 87 | ||
90 | result = MochiKit.DOM.SELECT({name:this.name()}, | 88 | result = MochiKit.DOM.SELECT({name:this.name()}, |
91 | MochiKit.Base.map(function(anOption) { | 89 | MochiKit.Base.map(function(anOption) { |
92 | var options; | 90 | var options; |
93 | 91 | ||
94 | options = {value:anOption['value']}; | 92 | options = {value:anOption['value']}; |
95 | if (currentValue == anOption['value']) { | 93 | if (currentValue == anOption['value']) { |
96 | options.selected = true; | 94 | options.selected = true; |
97 | } | 95 | } |
98 | 96 | ||
99 | return MochiKit.DOM.OPTION(options, anOption['label']) | 97 | return MochiKit.DOM.OPTION(options, anOption['label']) |
100 | }, options) | 98 | }, options) |
101 | ) | 99 | ) |
102 | break; | 100 | break; |
103 | case 'checkbox': | 101 | case 'checkbox': |
104 | var options; | 102 | var options; |
105 | 103 | ||
106 | options = {type:'checkbox', name: this.name()}; | 104 | options = {type:'checkbox', name: this.name()}; |
107 | // if (this.directLogin()._configuration['formValues'][this.name()] == true) { | 105 | // if (this.directLogin()._configuration['formValues'][this.name()] == true) { |
108 | if (someFormValues[this.name()] == true) { | 106 | if (someFormValues[this.name()] == true) { |
109 | options['checked'] = true; | 107 | options['checked'] = true; |
110 | }; | 108 | }; |
111 | 109 | ||
112 | result = MochiKit.DOM.INPUT(options, null); | 110 | result = MochiKit.DOM.INPUT(options, null); |
113 | break; | 111 | break; |
114 | case 'radio': | 112 | case 'radio': |
115 | var currentName; | 113 | var currentName; |
116 | var currentValue; | 114 | var currentValue; |
117 | var options; | 115 | var options; |
118 | 116 | ||
119 | currentName = this.name(); | 117 | currentName = this.name(); |
120 | // currentValue = this.directLogin()._configuration['formValues'][this.name()]; | 118 | // currentValue = this.directLogin()._configuration['formValues'][this.name()]; |
121 | currentValue = someFormValues[this.name()]; | 119 | currentValue = someFormValues[this.name()]; |
122 | options = this.args()['options']; | 120 | options = this.args()['options']; |
123 | 121 | ||
124 | result = MochiKit.DOM.DIV(null, | 122 | result = MochiKit.DOM.DIV(null, |
125 | MochiKit.Base.map(function(anOption) { | 123 | MochiKit.Base.map(function(anOption) { |
126 | var options; | 124 | var options; |
127 | var isChecked; | 125 | var isChecked; |
128 | var inputNode; | 126 | var inputNode; |
129 | var divNode; | 127 | var divNode; |
130 | 128 | ||
131 | options = {type:'radio', name:currentName, value:anOption['value']} | 129 | options = {type:'radio', name:currentName, value:anOption['value']} |
132 | isChecked = (currentValue == anOption['value']); | 130 | isChecked = (currentValue == anOption['value']); |
133 | if (isChecked) { | 131 | if (isChecked) { |
134 | options.checked = true; | 132 | options.checked = true; |
135 | } | 133 | } |
136 | 134 | ||
137 | if (Clipperz_IEisBroken == true) { | 135 | if (Clipperz_IEisBroken == true) { |
138 | var checkedValue; | 136 | var checkedValue; |
139 | 137 | ||
140 | checkedValue = (isChecked ? " CHECKED" : ""); | 138 | checkedValue = (isChecked ? " CHECKED" : ""); |
141 | inputNode = MochiKit.DOM.currentDocument().createElement("<INPUT TYPE='RADIO' NAME='" + currentName + "' VALUE='" + anOption['value'] + "'" + checkedValue + ">"); | 139 | inputNode = MochiKit.DOM.currentDocument().createElement("<INPUT TYPE='RADIO' NAME='" + currentName + "' VALUE='" + anOption['value'] + "'" + checkedValue + ">"); |
142 | } else { | 140 | } else { |
143 | inputNode = MochiKit.DOM.INPUT(options, anOption['value']); | 141 | inputNode = MochiKit.DOM.INPUT(options, anOption['value']); |
144 | } | 142 | } |
145 | divNode = MochiKit.DOM.DIV(null, inputNode); | 143 | divNode = MochiKit.DOM.DIV(null, inputNode); |
146 | 144 | ||
147 | return divNode; | 145 | return divNode; |
148 | }, options) | 146 | }, options) |
149 | ); | 147 | ); |
150 | break; | 148 | break; |
151 | } | 149 | } |
152 | } else { | 150 | } else { |
153 | var binding; | 151 | var binding; |
154 | // binding = this.directLogin().bindings()[this.name()]; | 152 | // binding = this.directLogin().bindings()[this.name()]; |
155 | binding = someBindings[this.name()]; | 153 | binding = someBindings[this.name()]; |
156 | 154 | ||
157 | //console.log("### binding", binding); | ||
158 | //if (binding != null) { | ||
159 | ///console.log(" binding.field()", binding.field()); | ||
160 | ///console.log(" binding.field().value()", binding.field().value()); | ||
161 | //console.log(" someFields[binding.fieldKey()].value()", someFields[binding.fieldKey()].value()); | ||
162 | //} | ||
163 | result = MochiKit.DOM.INPUT({ | 155 | result = MochiKit.DOM.INPUT({ |
164 | type:((this.type() != 'password') ? this.type() : 'text'), | 156 | type:((this.type() != 'password') ? this.type() : 'text'), |
165 | name:this.name(), | 157 | name:this.name(), |
166 | // value:((binding != null)? binding.field().value() : this.value()) | 158 | // value:((binding != null)? binding.field().value() : this.value()) |
167 | value:((binding != null)? someFields[binding.fieldKey()]['value'] : this.value()) | 159 | value:((binding != null)? someFields[binding.fieldKey()]['value'] : this.value()) |
168 | // value:((binding != null)? someFields[binding.fieldKey()].value() : this.value()) | 160 | // value:((binding != null)? someFields[binding.fieldKey()].value() : this.value()) |
169 | }, null); | 161 | }, null); |
170 | } | 162 | } |
171 | 163 | ||
172 | return result; | 164 | return result; |
173 | }, | 165 | }, |
174 | */ | 166 | */ |
175 | //------------------------------------------------------------------------- | 167 | //------------------------------------------------------------------------- |
176 | 168 | ||
177 | 'needsFormValue': function() { | 169 | 'needsFormValue': function() { |
178 | var type; | 170 | var type; |
179 | var result; | 171 | var result; |
180 | 172 | ||
181 | type = this.type(); | 173 | type = this.type(); |
182 | result = ((type == 'checkbox') || (type == 'radio') || (type == 'select')); | 174 | result = ((type == 'checkbox') || (type == 'radio') || (type == 'select')); |
183 | 175 | ||
184 | return result; | 176 | return result; |
185 | }, | 177 | }, |
186 | 178 | ||
187 | 'needsBinding': function() { | 179 | 'needsBinding': function() { |
188 | var type; | 180 | var type; |
189 | var result; | 181 | var result; |
190 | 182 | ||
191 | type = this.type(); | 183 | type = this.type(); |
192 | result = ((type == 'text') || (type == 'password')); | 184 | result = ((type == 'text') || (type == 'password')); |
193 | 185 | ||
194 | return result; | 186 | return result; |
195 | }, | 187 | }, |
196 | 188 | ||
197 | //------------------------------------------------------------------------- | 189 | //------------------------------------------------------------------------- |
198 | __syntaxFix__: "syntax fix" | 190 | __syntaxFix__: "syntax fix" |
199 | }); | 191 | }); |
200 | 192 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js b/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js index cdeec8b..1aa7a52 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js | |||
@@ -1,118 +1,116 @@ | |||
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 | try { if (typeof(Clipperz.KeyValueObjectStore) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.KeyValueObjectStore) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.DataModel.EncryptedRemoteObject depends on Clipperz.KeyValueObjectStore!"; | 25 | throw "Clipperz.PM.DataModel.EncryptedRemoteObject depends on Clipperz.KeyValueObjectStore!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 28 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
31 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 29 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
32 | 30 | ||
33 | Clipperz.PM.DataModel.EncryptedRemoteObject = function(args) { | 31 | Clipperz.PM.DataModel.EncryptedRemoteObject = function(args) { |
34 | args = args || {}; | 32 | args = args || {}; |
35 | 33 | ||
36 | this._name = args.name || null; | 34 | this._name = args.name || null; |
37 | this._reference = args.reference || Clipperz.PM.Crypto.randomKey(); | 35 | this._reference = args.reference || Clipperz.PM.Crypto.randomKey(); |
38 | this._isBrandNew = ((args.reference == null) && (args.remoteData == null)); | 36 | this._isBrandNew = ((args.reference == null) && (args.remoteData == null)); |
39 | 37 | ||
40 | if ((this._isBrandNew == false) && (args['retrieveKeyFunction'] == null)) { | 38 | if ((this._isBrandNew == false) && (args['retrieveKeyFunction'] == null)) { |
41 | Clipperz.Base.exception.raise('MandatoryParameter'); | 39 | Clipperz.Base.exception.raise('MandatoryParameter'); |
42 | } else { | 40 | } else { |
43 | this._retrieveKeyFunction = args['retrieveKeyFunction']; | 41 | this._retrieveKeyFunction = args['retrieveKeyFunction']; |
44 | } | 42 | } |
45 | 43 | ||
46 | this._retrieveRemoteDataFunction = args.retrieveRemoteDataFunction|| null; | 44 | this._retrieveRemoteDataFunction = args.retrieveRemoteDataFunction|| null; |
47 | this._remoteData = args.remoteData || null; | 45 | this._remoteData = args.remoteData || null; |
48 | // this._remoteData = args.remoteData ? Clipperz.Base.deepClone(args.remoteData) : null; | 46 | // this._remoteData = args.remoteData ? Clipperz.Base.deepClone(args.remoteData) : null; |
49 | if ((!this._isBrandNew) && ((this._retrieveRemoteDataFunction == null) && (this._remoteData == null))) { | 47 | if ((!this._isBrandNew) && ((this._retrieveRemoteDataFunction == null) && (this._remoteData == null))) { |
50 | Clipperz.Base.exception.raise('MandatoryParameter'); | 48 | Clipperz.Base.exception.raise('MandatoryParameter'); |
51 | } | 49 | } |
52 | 50 | ||
53 | 51 | ||
54 | this._encryptedDataKeypath = args.encryptedDataKeypath || 'data'; //Clipperz.Base.exception.raise('MandatoryParameter'); | 52 | this._encryptedDataKeypath = args.encryptedDataKeypath || 'data'; //Clipperz.Base.exception.raise('MandatoryParameter'); |
55 | this._encryptedVersionKeypath = args.encryptedVersionKeypath || 'version';//Clipperz.Base.exception.raise('MandatoryParameter'); | 53 | this._encryptedVersionKeypath = args.encryptedVersionKeypath || 'version';//Clipperz.Base.exception.raise('MandatoryParameter'); |
56 | 54 | ||
57 | 55 | ||
58 | this._transientState = null; | 56 | this._transientState = null; |
59 | this._deferredLocks = {}; | 57 | this._deferredLocks = {}; |
60 | 58 | ||
61 | if (this._isBrandNew == true) { | 59 | if (this._isBrandNew == true) { |
62 | this._objectDataStore = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.objectDataStore [1]'}*/); | 60 | this._objectDataStore = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.objectDataStore [1]'}*/); |
63 | } else { | 61 | } else { |
64 | this._objectDataStore = null; | 62 | this._objectDataStore = null; |
65 | } | 63 | } |
66 | 64 | ||
67 | return this; | 65 | return this; |
68 | } | 66 | } |
69 | 67 | ||
70 | // | 68 | // |
71 | // Basic data workflow | 69 | // Basic data workflow |
72 | //======================= | 70 | //======================= |
73 | // | 71 | // |
74 | //getRemoteData | 72 | //getRemoteData |
75 | // unpackRemoteData | 73 | // unpackRemoteData |
76 | // getDecryptData [encryptedDataKeypath, encryptedVersionKeypath] | 74 | // getDecryptData [encryptedDataKeypath, encryptedVersionKeypath] |
77 | // unpackData | 75 | // unpackData |
78 | // | 76 | // |
79 | // | 77 | // |
80 | // ?? packData | 78 | // ?? packData |
81 | // ?? encryptDataWithKey | 79 | // ?? encryptDataWithKey |
82 | // ??packRemoteData [encryptedDataKeypath (?), encryptedVersionKeypath (?)] | 80 | // ??packRemoteData [encryptedDataKeypath (?), encryptedVersionKeypath (?)] |
83 | // | 81 | // |
84 | 82 | ||
85 | Clipperz.PM.DataModel.EncryptedRemoteObject.prototype = MochiKit.Base.update(null, { | 83 | Clipperz.PM.DataModel.EncryptedRemoteObject.prototype = MochiKit.Base.update(null, { |
86 | 84 | ||
87 | 'toString': function () { | 85 | 'toString': function () { |
88 | return "Clipperz.PM.DataModel.EncryptedRemoteObject" + (this.name() != null ? " - " + this.name() : ""); | 86 | return "Clipperz.PM.DataModel.EncryptedRemoteObject" + (this.name() != null ? " - " + this.name() : ""); |
89 | }, | 87 | }, |
90 | 88 | ||
91 | //------------------------------------------------------------------------- | 89 | //------------------------------------------------------------------------- |
92 | 90 | ||
93 | 'name': function () { | 91 | 'name': function () { |
94 | return this._name; | 92 | return this._name; |
95 | }, | 93 | }, |
96 | 94 | ||
97 | //------------------------------------------------------------------------- | 95 | //------------------------------------------------------------------------- |
98 | 96 | ||
99 | 'reference': function () { | 97 | 'reference': function () { |
100 | return this._reference; | 98 | return this._reference; |
101 | }, | 99 | }, |
102 | 100 | ||
103 | 'setReference': function (aValue) { | 101 | 'setReference': function (aValue) { |
104 | this._reference = aValue; | 102 | this._reference = aValue; |
105 | 103 | ||
106 | return this._reference; | 104 | return this._reference; |
107 | }, | 105 | }, |
108 | 106 | ||
109 | //------------------------------------------------------------------------- | 107 | //------------------------------------------------------------------------- |
110 | 108 | ||
111 | 'transientState': function () { | 109 | 'transientState': function () { |
112 | if (this._transientState == null) { | 110 | if (this._transientState == null) { |
113 | this._transientState = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.transientState [2]'}*/); | 111 | this._transientState = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.transientState [2]'}*/); |
114 | } | 112 | } |
115 | 113 | ||
116 | return this._transientState; | 114 | return this._transientState; |
117 | }, | 115 | }, |
118 | 116 | ||
@@ -318,196 +316,192 @@ Clipperz.PM.DataModel.EncryptedRemoteObject.prototype = MochiKit.Base.update(nul | |||
318 | MochiKit.Base.method(this, '_getObjectDataStore'), | 316 | MochiKit.Base.method(this, '_getObjectDataStore'), |
319 | MochiKit.Base.methodcaller('values') | 317 | MochiKit.Base.methodcaller('values') |
320 | ], {trace:false}); | 318 | ], {trace:false}); |
321 | }, | 319 | }, |
322 | 320 | ||
323 | 'setValues': function (someValues) { | 321 | 'setValues': function (someValues) { |
324 | return Clipperz.Async.callbacks("EncryptedRemoteObject.values", [ | 322 | return Clipperz.Async.callbacks("EncryptedRemoteObject.values", [ |
325 | MochiKit.Base.method(this, '_getObjectDataStore'), | 323 | MochiKit.Base.method(this, '_getObjectDataStore'), |
326 | MochiKit.Base.methodcaller('setValues', someValues) | 324 | MochiKit.Base.methodcaller('setValues', someValues) |
327 | ], {trace:false}); | 325 | ], {trace:false}); |
328 | }, | 326 | }, |
329 | 327 | ||
330 | //......................................................................... | 328 | //......................................................................... |
331 | 329 | ||
332 | '_getObjectDataStore': function () { | 330 | '_getObjectDataStore': function () { |
333 | var deferredResult; | 331 | var deferredResult; |
334 | var deferredLock; | 332 | var deferredLock; |
335 | 333 | ||
336 | deferredLock = this.getDeferredLockForKey('objectDataStore'); | 334 | deferredLock = this.getDeferredLockForKey('objectDataStore'); |
337 | 335 | ||
338 | deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject._getObjectDataStore", {trace:false}); | 336 | deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject._getObjectDataStore", {trace:false}); |
339 | deferredResult.acquireLock(deferredLock); | 337 | deferredResult.acquireLock(deferredLock); |
340 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 338 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
341 | var innerDeferredResult; | 339 | var innerDeferredResult; |
342 | 340 | ||
343 | if (this._objectDataStore == null) { | 341 | if (this._objectDataStore == null) { |
344 | this._objectDataStore = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.objectDataStore [4]'}*/); | 342 | this._objectDataStore = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.objectDataStore [4]'}*/); |
345 | 343 | ||
346 | innerDeferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject._getObjectDataStore <inner deferred>", {trace:false}); | 344 | innerDeferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject._getObjectDataStore <inner deferred>", {trace:false}); |
347 | innerDeferredResult.addMethod(this, 'getDecryptedData'); | 345 | innerDeferredResult.addMethod(this, 'getDecryptedData'); |
348 | innerDeferredResult.addMethod(this._objectDataStore, 'initWithValues'); | 346 | innerDeferredResult.addMethod(this._objectDataStore, 'initWithValues'); |
349 | innerDeferredResult.callback(); | 347 | innerDeferredResult.callback(); |
350 | } else { | 348 | } else { |
351 | innerDeferredResult = MochiKit.Async.succeed(this._objectDataStore); | 349 | innerDeferredResult = MochiKit.Async.succeed(this._objectDataStore); |
352 | } | 350 | } |
353 | 351 | ||
354 | return innerDeferredResult; | 352 | return innerDeferredResult; |
355 | }, this)); | 353 | }, this)); |
356 | deferredResult.releaseLock(deferredLock); | 354 | deferredResult.releaseLock(deferredLock); |
357 | deferredResult.callback(); | 355 | deferredResult.callback(); |
358 | 356 | ||
359 | return deferredResult; | 357 | return deferredResult; |
360 | }, | 358 | }, |
361 | 359 | ||
362 | 'hasInitiatedObjectDataStore': function () { | 360 | 'hasInitiatedObjectDataStore': function () { |
363 | return (this._objectDataStore != null); | 361 | return (this._objectDataStore != null); |
364 | }, | 362 | }, |
365 | 363 | ||
366 | //------------------------------------------------------------------------- | 364 | //------------------------------------------------------------------------- |
367 | 365 | ||
368 | 'getDeferredLockForKey': function (aKey) { | 366 | 'getDeferredLockForKey': function (aKey) { |
369 | var result; | 367 | var result; |
370 | 368 | ||
371 | result = this._deferredLocks[aKey]; | 369 | result = this._deferredLocks[aKey]; |
372 | 370 | ||
373 | if (typeof(result) == 'undefined') { | 371 | if (typeof(result) == 'undefined') { |
374 | result = new MochiKit.Async.DeferredLock(); | 372 | result = new MochiKit.Async.DeferredLock(); |
375 | this._deferredLocks[aKey] = result; | 373 | this._deferredLocks[aKey] = result; |
376 | } | 374 | } |
377 | 375 | ||
378 | return result; | 376 | return result; |
379 | }, | 377 | }, |
380 | 378 | ||
381 | //------------------------------------------------------------------------- | 379 | //------------------------------------------------------------------------- |
382 | 380 | ||
383 | 'unpackData': function (someData) { //++ | 381 | 'unpackData': function (someData) { //++ |
384 | return someData; | 382 | return someData; |
385 | }, | 383 | }, |
386 | 384 | ||
387 | 'packData': function (someData) { //++ | 385 | 'packData': function (someData) { //++ |
388 | return someData; | 386 | return someData; |
389 | }, | 387 | }, |
390 | 388 | ||
391 | //------------------------------------------------------------------------- | 389 | //------------------------------------------------------------------------- |
392 | 390 | ||
393 | 'hasPendingChanges': function () { | 391 | 'hasPendingChanges': function () { |
394 | var deferredResult; | 392 | var deferredResult; |
395 | var tempObj = this; | 393 | var tempObj = this; |
396 | 394 | ||
397 | if (this.isBrandNew()) { | 395 | if (this.isBrandNew()) { |
398 | // deferredResult = MochiKit.Async.succeed(true); | 396 | // deferredResult = MochiKit.Async.succeed(true); |
399 | deferredResult = this.hasPendingChangesWhenBrandNew(); | 397 | deferredResult = this.hasPendingChangesWhenBrandNew(); |
400 | } else if (this.hasInitiatedObjectDataStore()) { | 398 | } else if (this.hasInitiatedObjectDataStore()) { |
401 | deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject.hasPendingChanges", {trace:false}); | 399 | deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject.hasPendingChanges", {trace:false}); |
402 | deferredResult.collectResults({ | 400 | deferredResult.collectResults({ |
403 | 'decryptedData': [ | 401 | 'decryptedData': [ |
404 | MochiKit.Base.method(this, 'getDecryptedData'), | 402 | MochiKit.Base.method(this, 'getDecryptedData'), |
405 | Clipperz.Base.serializeJSON | 403 | Clipperz.Base.serializeJSON |
406 | ], | 404 | ], |
407 | 'objectData': [ | 405 | 'objectData': [ |
408 | MochiKit.Base.method(this, '_getObjectDataStore'), | 406 | MochiKit.Base.method(this, '_getObjectDataStore'), |
409 | MochiKit.Base.methodcaller('values'), | 407 | MochiKit.Base.methodcaller('values'), |
410 | Clipperz.Base.serializeJSON | 408 | Clipperz.Base.serializeJSON |
411 | ] | 409 | ] |
412 | }); | 410 | }); |
413 | deferredResult.addCallback(function (someValues) { | 411 | deferredResult.addCallback(function (someValues) { |
414 | //if (someValues['decryptedData'] != someValues['objectData']) { | ||
415 | //console.log("ORIGINAL DATA", '[[[' + someValues['decryptedData'] + ']]]'); | ||
416 | //console.log("CURRENT DATA", '>>>' + someValues['objectData'] + '<<<'); | ||
417 | //} | ||
418 | return (someValues['decryptedData'] != someValues['objectData']); | 412 | return (someValues['decryptedData'] != someValues['objectData']); |
419 | }); | 413 | }); |
420 | deferredResult.callback(); | 414 | deferredResult.callback(); |
421 | } else { | 415 | } else { |
422 | deferredResult = MochiKit.Async.succeed(false); | 416 | deferredResult = MochiKit.Async.succeed(false); |
423 | } | 417 | } |
424 | 418 | ||
425 | return deferredResult; | 419 | return deferredResult; |
426 | }, | 420 | }, |
427 | 421 | ||
428 | 'hasPendingChangesWhenBrandNew': function () { | 422 | 'hasPendingChangesWhenBrandNew': function () { |
429 | return MochiKit.Async.succeed(true); | 423 | return MochiKit.Async.succeed(true); |
430 | }, | 424 | }, |
431 | 425 | ||
432 | //------------------------------------------------------------------------- | 426 | //------------------------------------------------------------------------- |
433 | 427 | ||
434 | 'commitTransientState': function () { | 428 | 'commitTransientState': function () { |
435 | var deferredResult; | 429 | var deferredResult; |
436 | 430 | ||
437 | // if (this.transientState().getValue('__prepareRemoteData') == true) { | 431 | // if (this.transientState().getValue('__prepareRemoteData') == true) { |
438 | if (this.transientState().getValue('packedRemoteData') != null) { | 432 | if (this.transientState().getValue('packedRemoteData') != null) { |
439 | deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - prepareRemoteData", [ | 433 | deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - prepareRemoteData", [ |
440 | MochiKit.Base.bind(function (someData) { | 434 | MochiKit.Base.bind(function (someData) { |
441 | this._remoteData = this.transientState().getValue('packedRemoteData'); | 435 | this._remoteData = this.transientState().getValue('packedRemoteData'); |
442 | }, this), | 436 | }, this), |
443 | 437 | ||
444 | MochiKit.Base.method(this, '_getObjectDataStore'), | 438 | MochiKit.Base.method(this, '_getObjectDataStore'), |
445 | MochiKit.Base.methodcaller('values'), | 439 | MochiKit.Base.methodcaller('values'), |
446 | Clipperz.Base.deepClone, | 440 | Clipperz.Base.deepClone, |
447 | MochiKit.Base.method(this.decryptedDataStore(), 'setValue', 'decryptedData'), | 441 | MochiKit.Base.method(this.decryptedDataStore(), 'setValue', 'decryptedData'), |
448 | 442 | ||
449 | MochiKit.Base.method(this, 'resetTransientState', true) | 443 | MochiKit.Base.method(this, 'resetTransientState', true) |
450 | ], {trace:false}); | 444 | ], {trace:false}); |
451 | 445 | ||
452 | } else { | 446 | } else { |
453 | deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - NO prepareRemoteData", [ | 447 | deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - NO prepareRemoteData", [ |
454 | MochiKit.Base.method(this, 'resetTransientState', true) | 448 | MochiKit.Base.method(this, 'resetTransientState', true) |
455 | ], {trace:false}); | 449 | ], {trace:false}); |
456 | } | 450 | } |
457 | 451 | ||
458 | this._isBrandNew = false; | 452 | this._isBrandNew = false; |
459 | 453 | ||
460 | return deferredResult; | 454 | return deferredResult; |
461 | }, | 455 | }, |
462 | 456 | ||
463 | //------------------------------------------------------------------------- | 457 | //------------------------------------------------------------------------- |
464 | 458 | ||
465 | 'revertChanges': function () { | 459 | 'revertChanges': function () { |
466 | if (this.hasInitiatedObjectDataStore()) { | 460 | if (this.hasInitiatedObjectDataStore()) { |
467 | this._objectDataStore.removeAllData(); | 461 | this._objectDataStore.removeAllData(); |
468 | this._objectDataStore = null; | 462 | this._objectDataStore = null; |
469 | } | 463 | } |
470 | this.resetTransientState(false); | 464 | this.resetTransientState(false); |
471 | 465 | ||
472 | return MochiKit.Async.succeed(); | 466 | return MochiKit.Async.succeed(); |
473 | }, | 467 | }, |
474 | 468 | ||
475 | //------------------------------------------------------------------------- | 469 | //------------------------------------------------------------------------- |
476 | 470 | ||
477 | 'deleteAllCleanTextData': function () { | 471 | 'deleteAllCleanTextData': function () { |
478 | var deferredResult; | 472 | var deferredResult; |
479 | 473 | ||
480 | deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject.deleteAllCleanTextData", {trace:false}); | 474 | deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject.deleteAllCleanTextData", {trace:false}); |
481 | 475 | ||
482 | deferredResult.addMethod(this, 'resetTransientState', false); | 476 | deferredResult.addMethod(this, 'resetTransientState', false); |
483 | 477 | ||
484 | deferredResult.acquireLock(this.getDeferredLockForKey('decryptedData')); | 478 | deferredResult.acquireLock(this.getDeferredLockForKey('decryptedData')); |
485 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 479 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
486 | if (this._decryptedDataStore != null) { | 480 | if (this._decryptedDataStore != null) { |
487 | this._decryptedDataStore.removeAllData(); | 481 | this._decryptedDataStore.removeAllData(); |
488 | } | 482 | } |
489 | }, this)); | 483 | }, this)); |
490 | deferredResult.releaseLock(this.getDeferredLockForKey('decryptedData')); | 484 | deferredResult.releaseLock(this.getDeferredLockForKey('decryptedData')); |
491 | 485 | ||
492 | deferredResult.acquireLock(this.getDeferredLockForKey('objectDataStore')); | 486 | deferredResult.acquireLock(this.getDeferredLockForKey('objectDataStore')); |
493 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 487 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
494 | if (this._objectDataStore != null) { | 488 | if (this._objectDataStore != null) { |
495 | this._objectDataStore.removeAllData(); | 489 | this._objectDataStore.removeAllData(); |
496 | this._objectDataStore = null; | 490 | this._objectDataStore = null; |
497 | } | 491 | } |
498 | }, this)); | 492 | }, this)); |
499 | deferredResult.releaseLock(this.getDeferredLockForKey('objectDataStore')); | 493 | deferredResult.releaseLock(this.getDeferredLockForKey('objectDataStore')); |
500 | 494 | ||
501 | deferredResult.callback(); | 495 | deferredResult.callback(); |
502 | 496 | ||
503 | return deferredResult; | 497 | return deferredResult; |
504 | }, | 498 | }, |
505 | 499 | ||
506 | //......................................................................... | 500 | //......................................................................... |
507 | 501 | ||
508 | 'hasAnyCleanTextData': function () { | 502 | 'hasAnyCleanTextData': function () { |
509 | var result; | 503 | var result; |
510 | 504 | ||
511 | result = false; | 505 | result = false; |
512 | 506 | ||
513 | result = result || (! this.decryptedDataStore().isEmpty()); | 507 | result = result || (! this.decryptedDataStore().isEmpty()); |
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js b/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js index 834e21b..fbca1ff 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js | |||
@@ -1,354 +1,350 @@ | |||
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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | 28 | ||
31 | //############################################################################# | 29 | //############################################################################# |
32 | 30 | ||
33 | Clipperz.PM.DataModel.OneTimePassword = function(args) { | 31 | Clipperz.PM.DataModel.OneTimePassword = function(args) { |
34 | args = args || {}; | 32 | args = args || {}; |
35 | 33 | ||
36 | //this._user = args['user']; | 34 | //this._user = args['user']; |
37 | this._reference = args['reference']|| Clipperz.PM.Crypto.randomKey(); | 35 | this._reference = args['reference']|| Clipperz.PM.Crypto.randomKey(); |
38 | this._password = args['password']; | 36 | this._password = args['password']; |
39 | this._passwordValue = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(args['password']); | 37 | this._passwordValue = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(args['password']); |
40 | this._creationDate = args['created'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['created']) : new Date(); | 38 | this._creationDate = args['created'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['created']) : new Date(); |
41 | this._usageDate = args['used'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['used']) : null; | 39 | this._usageDate = args['used'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['used']) : null; |
42 | 40 | ||
43 | this._status = args['status'] || 'ACTIVE'; //'REQUESTED', 'USED', 'DISABLED' | 41 | this._status = args['status'] || 'ACTIVE'; //'REQUESTED', 'USED', 'DISABLED' |
44 | this._connectionInfo= null; | 42 | this._connectionInfo= null; |
45 | 43 | ||
46 | this._key = null; | 44 | this._key = null; |
47 | this._keyChecksum= null; | 45 | this._keyChecksum= null; |
48 | 46 | ||
49 | return this; | 47 | return this; |
50 | } | 48 | } |
51 | 49 | ||
52 | Clipperz.PM.DataModel.OneTimePassword.prototype = MochiKit.Base.update(null, { | 50 | Clipperz.PM.DataModel.OneTimePassword.prototype = MochiKit.Base.update(null, { |
53 | 51 | ||
54 | 'toString': function() { | 52 | 'toString': function() { |
55 | return "Clipperz.PM.DataModel.OneTimePassword"; | 53 | return "Clipperz.PM.DataModel.OneTimePassword"; |
56 | }, | 54 | }, |
57 | /* | 55 | /* |
58 | //------------------------------------------------------------------------- | 56 | //------------------------------------------------------------------------- |
59 | 57 | ||
60 | 'user': function() { | 58 | 'user': function() { |
61 | return this._user; | 59 | return this._user; |
62 | }, | 60 | }, |
63 | 61 | ||
64 | //------------------------------------------------------------------------- | 62 | //------------------------------------------------------------------------- |
65 | 63 | ||
66 | 'password': function() { | 64 | 'password': function() { |
67 | return this._password; | 65 | return this._password; |
68 | }, | 66 | }, |
69 | 67 | ||
70 | //------------------------------------------------------------------------- | 68 | //------------------------------------------------------------------------- |
71 | 69 | ||
72 | 'passwordValue': function() { | 70 | 'passwordValue': function() { |
73 | return this._passwordValue; | 71 | return this._passwordValue; |
74 | }, | 72 | }, |
75 | 73 | ||
76 | //------------------------------------------------------------------------- | 74 | //------------------------------------------------------------------------- |
77 | 75 | ||
78 | 'creationDate': function() { | 76 | 'creationDate': function() { |
79 | return this._creationDate; | 77 | return this._creationDate; |
80 | }, | 78 | }, |
81 | 79 | ||
82 | //------------------------------------------------------------------------- | 80 | //------------------------------------------------------------------------- |
83 | 81 | ||
84 | 'reference': function() { | 82 | 'reference': function() { |
85 | return this._reference; | 83 | return this._reference; |
86 | }, | 84 | }, |
87 | 85 | ||
88 | //------------------------------------------------------------------------- | 86 | //------------------------------------------------------------------------- |
89 | 87 | ||
90 | 'key': function() { | 88 | 'key': function() { |
91 | if (this._key == null) { | 89 | if (this._key == null) { |
92 | this._key = Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(this.user().username(), this.passwordValue()); | 90 | this._key = Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(this.user().username(), this.passwordValue()); |
93 | } | 91 | } |
94 | 92 | ||
95 | return this._key; | 93 | return this._key; |
96 | }, | 94 | }, |
97 | 95 | ||
98 | //------------------------------------------------------------------------- | 96 | //------------------------------------------------------------------------- |
99 | 97 | ||
100 | 'keyChecksum': function() { | 98 | 'keyChecksum': function() { |
101 | if (this._keyChecksum == null) { | 99 | if (this._keyChecksum == null) { |
102 | this._keyChecksum = Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(this.user().username(), this.passwordValue()); | 100 | this._keyChecksum = Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(this.user().username(), this.passwordValue()); |
103 | } | 101 | } |
104 | 102 | ||
105 | return this._keyChecksum; | 103 | return this._keyChecksum; |
106 | }, | 104 | }, |
107 | */ | 105 | */ |
108 | //------------------------------------------------------------------------- | 106 | //------------------------------------------------------------------------- |
109 | 107 | ||
110 | 'status': function() { | 108 | 'status': function() { |
111 | return this._status; | 109 | return this._status; |
112 | }, | 110 | }, |
113 | 111 | ||
114 | 'setStatus': function(aValue) { | 112 | 'setStatus': function(aValue) { |
115 | this._status = aValue; | 113 | this._status = aValue; |
116 | }, | 114 | }, |
117 | 115 | ||
118 | //------------------------------------------------------------------------- | 116 | //------------------------------------------------------------------------- |
119 | /* | 117 | /* |
120 | 'serializedData': function() { | 118 | 'serializedData': function() { |
121 | var result; | 119 | var result; |
122 | 120 | ||
123 | result = { | 121 | result = { |
124 | 'password': this.password(), | 122 | 'password': this.password(), |
125 | 'created': this.creationDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.creationDate()) : null, | 123 | 'created': this.creationDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.creationDate()) : null, |
126 | 'used': this.usageDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.usageDate()) : null, | 124 | 'used': this.usageDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.usageDate()) : null, |
127 | 'status': this.status() | 125 | 'status': this.status() |
128 | }; | 126 | }; |
129 | 127 | ||
130 | return result; | 128 | return result; |
131 | }, | 129 | }, |
132 | 130 | ||
133 | //------------------------------------------------------------------------- | 131 | //------------------------------------------------------------------------- |
134 | 132 | ||
135 | 'packedPassphrase': function() { | 133 | 'packedPassphrase': function() { |
136 | var result; | 134 | var result; |
137 | var packedPassphrase; | 135 | var packedPassphrase; |
138 | var encodedPassphrase; | 136 | var encodedPassphrase; |
139 | varprefixPadding; | 137 | varprefixPadding; |
140 | var suffixPadding; | 138 | var suffixPadding; |
141 | var getRandomBytes; | 139 | var getRandomBytes; |
142 | 140 | ||
143 | getRandomBytes = MochiKit.Base.method(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'getRandomBytes'); | 141 | getRandomBytes = MochiKit.Base.method(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'getRandomBytes'); |
144 | 142 | ||
145 | encodedPassphrase = new Clipperz.ByteArray(this.user().passphrase()).toBase64String(); | 143 | encodedPassphrase = new Clipperz.ByteArray(this.user().passphrase()).toBase64String(); |
146 | //MochiKit.Logging.logDebug("--- encodedPassphrase.length: " + encodedPassphrase.length); | 144 | //Clipperz.logDebug("--- encodedPassphrase.length: " + encodedPassphrase.length); |
147 | prefixPadding = getRandomBytes(getRandomBytes(1).byteAtIndex(0)).toBase64String(); | 145 | prefixPadding = getRandomBytes(getRandomBytes(1).byteAtIndex(0)).toBase64String(); |
148 | //MochiKit.Logging.logDebug("--- prefixPadding.length: " + prefixPadding.length); | 146 | //Clipperz.logDebug("--- prefixPadding.length: " + prefixPadding.length); |
149 | suffixPadding = getRandomBytes((500 - prefixPadding.length - encodedPassphrase.length) * 6 / 8).toBase64String(); | 147 | suffixPadding = getRandomBytes((500 - prefixPadding.length - encodedPassphrase.length) * 6 / 8).toBase64String(); |
150 | //MochiKit.Logging.logDebug("--- suffixPadding.length: " + suffixPadding.length); | 148 | //Clipperz.logDebug("--- suffixPadding.length: " + suffixPadding.length); |
151 | //MochiKit.Logging.logDebug("--- total.length: " + (prefixPadding.length + encodedPassphrase.length + suffixPadding.length)); | 149 | //Clipperz.logDebug("--- total.length: " + (prefixPadding.length + encodedPassphrase.length + suffixPadding.length)); |
152 | 150 | ||
153 | packedPassphrase = { | 151 | packedPassphrase = { |
154 | 'prefix': prefixPadding, | 152 | 'prefix': prefixPadding, |
155 | 'passphrase': encodedPassphrase, | 153 | 'passphrase': encodedPassphrase, |
156 | 'suffix': suffixPadding | 154 | 'suffix': suffixPadding |
157 | }; | 155 | }; |
158 | 156 | ||
159 | // result = Clipperz.Base.serializeJSON(packedPassphrase); | 157 | // result = Clipperz.Base.serializeJSON(packedPassphrase); |
160 | result = packedPassphrase; | 158 | result = packedPassphrase; |
161 | //MochiKit.Logging.logDebug("===== OTP packedPassprase: [" + result.length + "]" + result); | 159 | //Clipperz.logDebug("===== OTP packedPassprase: [" + result.length + "]" + result); |
162 | //MochiKit.Logging.logDebug("<<< OneTimePassword.packedPassphrase"); | 160 | //Clipperz.logDebug("<<< OneTimePassword.packedPassphrase"); |
163 | 161 | ||
164 | return result; | 162 | return result; |
165 | }, | 163 | }, |
166 | 164 | ||
167 | //------------------------------------------------------------------------- | 165 | //------------------------------------------------------------------------- |
168 | 166 | ||
169 | 'encryptedPackedPassphrase': function() { | 167 | 'encryptedPackedPassphrase': function() { |
170 | return Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion(this.passwordValue(), this.packedPassphrase()) | 168 | return Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion(this.passwordValue(), this.packedPassphrase()) |
171 | }, | 169 | }, |
172 | 170 | ||
173 | //------------------------------------------------------------------------- | 171 | //------------------------------------------------------------------------- |
174 | 172 | ||
175 | 'encryptedData': function() { | 173 | 'encryptedData': function() { |
176 | var deferredResult; | 174 | var deferredResult; |
177 | varresult; | 175 | varresult; |
178 | 176 | ||
179 | //MochiKit.Logging.logDebug(">>> OneTimePassword.encryptedData"); | 177 | //Clipperz.logDebug(">>> OneTimePassword.encryptedData"); |
180 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - id: " + this.reference()); | 178 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - id: " + this.reference()); |
181 | result = { | 179 | result = { |
182 | 'reference': this.reference(), | 180 | 'reference': this.reference(), |
183 | 'key': this.key(), | 181 | 'key': this.key(), |
184 | 'keyChecksum': this.keyChecksum(), | 182 | 'keyChecksum': this.keyChecksum(), |
185 | 'data': "", | 183 | 'data': "", |
186 | 'version': Clipperz.PM.Crypto.encryptingFunctions.currentVersion | 184 | 'version': Clipperz.PM.Crypto.encryptingFunctions.currentVersion |
187 | } | 185 | } |
188 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 2: " + Clipperz.Base.serializeJSON(result)); | 186 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 2: " + Clipperz.Base.serializeJSON(result)); |
189 | deferredResult = new MochiKit.Async.Deferred(); | 187 | deferredResult = new MochiKit.Async.Deferred(); |
190 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 3"); | 188 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 3"); |
191 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 1: " + res); return res;}); | 189 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.encryptedData - 1: " + res); return res;}); |
192 | //# deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.passwordValue(), this.packedPassphrase()); | 190 | //# deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.passwordValue(), this.packedPassphrase()); |
193 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedPackedPassphrase')); | 191 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedPackedPassphrase')); |
194 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 4"); | 192 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 4"); |
195 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 2: [" + res.length + "]" + res); return res;}); | 193 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.encryptedData - 2: [" + res.length + "]" + res); return res;}); |
196 | deferredResult.addCallback(function(aResult, res) { | 194 | deferredResult.addCallback(function(aResult, res) { |
197 | aResult['data'] = res; | 195 | aResult['data'] = res; |
198 | return aResult; | 196 | return aResult; |
199 | }, result); | 197 | }, result); |
200 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 5"); | 198 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 5"); |
201 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); | 199 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.encryptedData - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); |
202 | deferredResult.callback(); | 200 | deferredResult.callback(); |
203 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 6"); | 201 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 6"); |
204 | 202 | ||
205 | return deferredResult; | 203 | return deferredResult; |
206 | }, | 204 | }, |
207 | 205 | ||
208 | //------------------------------------------------------------------------- | 206 | //------------------------------------------------------------------------- |
209 | 207 | ||
210 | 'saveChanges': function() { | 208 | 'saveChanges': function() { |
211 | var deferredResult; | 209 | var deferredResult; |
212 | varresult; | 210 | varresult; |
213 | 211 | ||
214 | //MochiKit.Logging.logDebug(">>> OneTimePassword.saveChanges"); | 212 | //Clipperz.logDebug(">>> OneTimePassword.saveChanges"); |
215 | result = {}; | 213 | result = {}; |
216 | deferredResult = new MochiKit.Async.Deferred(); | 214 | deferredResult = new MochiKit.Async.Deferred(); |
217 | 215 | ||
218 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptUserData'); | 216 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptUserData'); |
219 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); | 217 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); |
220 | deferredResult.addCallback(function(aResult, res) { | 218 | deferredResult.addCallback(function(aResult, res) { |
221 | aResult['user'] = res; | 219 | aResult['user'] = res; |
222 | return aResult; | 220 | return aResult; |
223 | }, result); | 221 | }, result); |
224 | 222 | ||
225 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptOTPData'); | 223 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptOTPData'); |
226 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 224 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
227 | deferredResult.addCallback(function(aResult, res) { | 225 | deferredResult.addCallback(function(aResult, res) { |
228 | aResult['oneTimePassword'] = res; | 226 | aResult['oneTimePassword'] = res; |
229 | return aResult; | 227 | return aResult; |
230 | }, result); | 228 | }, result); |
231 | 229 | ||
232 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_sendingData'); | 230 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_sendingData'); |
233 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.saveChanges - 1: " + Clipperz.Base.serializeJSON(res)); return res;}); | 231 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.saveChanges - 1: " + Clipperz.Base.serializeJSON(res)); return res;}); |
234 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewOneTimePassword'); | 232 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewOneTimePassword'); |
235 | 233 | ||
236 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_updatingInterface'); | 234 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_updatingInterface'); |
237 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); | 235 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); |
238 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'OTPUpdated'); | 236 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'OTPUpdated'); |
239 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'oneTimePassword_saveChanges_done', null); | 237 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'oneTimePassword_saveChanges_done', null); |
240 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); | 238 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); |
241 | deferredResult.callback(); | 239 | deferredResult.callback(); |
242 | //MochiKit.Logging.logDebug("<<< OneTimePassword.saveChanges"); | 240 | //Clipperz.logDebug("<<< OneTimePassword.saveChanges"); |
243 | 241 | ||
244 | return deferredResult; | 242 | return deferredResult; |
245 | }, | 243 | }, |
246 | 244 | ||
247 | //------------------------------------------------------------------------- | 245 | //------------------------------------------------------------------------- |
248 | 246 | ||
249 | 'usageDate': function() { | 247 | 'usageDate': function() { |
250 | return this._usageDate; | 248 | return this._usageDate; |
251 | }, | 249 | }, |
252 | 250 | ||
253 | 'setUsageDate': function(aValue) { | 251 | 'setUsageDate': function(aValue) { |
254 | this._usageDate = aValue; | 252 | this._usageDate = aValue; |
255 | }, | 253 | }, |
256 | 254 | ||
257 | //------------------------------------------------------------------------- | 255 | //------------------------------------------------------------------------- |
258 | 256 | ||
259 | 'connectionInfo': function() { | 257 | 'connectionInfo': function() { |
260 | return this._connectionInfo; | 258 | return this._connectionInfo; |
261 | }, | 259 | }, |
262 | 260 | ||
263 | 'setConnectionInfo': function(aValue) { | 261 | 'setConnectionInfo': function(aValue) { |
264 | this._connectionInfo = aValue; | 262 | this._connectionInfo = aValue; |
265 | }, | 263 | }, |
266 | 264 | ||
267 | //------------------------------------------------------------------------- | 265 | //------------------------------------------------------------------------- |
268 | 266 | ||
269 | 'isExpired': function() { | 267 | 'isExpired': function() { |
270 | return (this.usageDate() != null); | 268 | return (this.usageDate() != null); |
271 | }, | 269 | }, |
272 | 270 | ||
273 | //------------------------------------------------------------------------- | 271 | //------------------------------------------------------------------------- |
274 | 272 | ||
275 | 'updateStatusWithValues': function(someValues) { | 273 | 'updateStatusWithValues': function(someValues) { |
276 | var result; | 274 | var result; |
277 | 275 | ||
278 | result = false; | 276 | result = false; |
279 | 277 | ||
280 | if (someValues['status'] != this.status()) { | 278 | if (someValues['status'] != this.status()) { |
281 | result = true; | 279 | result = true; |
282 | } | 280 | } |
283 | 281 | ||
284 | this.setStatus(someValues['status']); | 282 | this.setStatus(someValues['status']); |
285 | this.setUsageDate(Clipperz.PM.Date.parseDateWithUTCFormat(someValues['requestDate'])); | 283 | this.setUsageDate(Clipperz.PM.Date.parseDateWithUTCFormat(someValues['requestDate'])); |
286 | this.setConnectionInfo(someValues['connection']); | 284 | this.setConnectionInfo(someValues['connection']); |
287 | 285 | ||
288 | return result; | 286 | return result; |
289 | }, | 287 | }, |
290 | */ | 288 | */ |
291 | //------------------------------------------------------------------------- | 289 | //------------------------------------------------------------------------- |
292 | __syntaxFix__: "syntax fix" | 290 | __syntaxFix__: "syntax fix" |
293 | }); | 291 | }); |
294 | 292 | ||
295 | //############################################################################# | 293 | //############################################################################# |
296 | 294 | ||
297 | Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword = function(anUsername, aPassword) { | 295 | Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword = function(anUsername, aPassword) { |
298 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aPassword)).toHexString().substring(2); | 296 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aPassword)).toHexString().substring(2); |
299 | } | 297 | } |
300 | 298 | ||
301 | Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword = function(anUsername, aPassword) { | 299 | Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword = function(anUsername, aPassword) { |
302 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(anUsername + aPassword)).toHexString().substring(2); | 300 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(anUsername + aPassword)).toHexString().substring(2); |
303 | } | 301 | } |
304 | 302 | ||
305 | //============================================================================= | 303 | //============================================================================= |
306 | 304 | ||
307 | Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue = function(aPassword) { | 305 | Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue = function(aPassword) { |
308 | var result; | 306 | var result; |
309 | 307 | ||
310 | //"yaxx k7ww - f8y6 tqz5 - 58b6 th44 - 9cwv q0fg" | 308 | //"yaxx k7ww - f8y6 tqz5 - 58b6 th44 - 9cwv q0fg" |
311 | //console.log("Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue", aPassword); | ||
312 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { | 309 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { |
313 | try { | 310 | try { |
314 | var passwordByteArray; | 311 | var passwordByteArray; |
315 | 312 | ||
316 | passwordByteArray = new Clipperz.ByteArray(); | 313 | passwordByteArray = new Clipperz.ByteArray(); |
317 | passwordByteArray.appendBase32String(aPassword); | 314 | passwordByteArray.appendBase32String(aPassword); |
318 | 315 | ||
319 | result = true; | 316 | result = true; |
320 | } catch(exception) { | 317 | } catch(exception) { |
321 | result = false; | 318 | result = false; |
322 | } | 319 | } |
323 | } else { | 320 | } else { |
324 | result = false; | 321 | result = false; |
325 | } | 322 | } |
326 | 323 | ||
327 | return result; | 324 | return result; |
328 | } | 325 | } |
329 | 326 | ||
330 | //============================================================================= | 327 | //============================================================================= |
331 | 328 | ||
332 | Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword = function(aPassword) { | 329 | Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword = function(aPassword) { |
333 | varresult; | 330 | varresult; |
334 | 331 | ||
335 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { | 332 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { |
336 | try { | 333 | try { |
337 | var passwordByteArray; | 334 | var passwordByteArray; |
338 | 335 | ||
339 | passwordByteArray = new Clipperz.ByteArray(); | 336 | passwordByteArray = new Clipperz.ByteArray(); |
340 | passwordByteArray.appendBase32String(aPassword); | 337 | passwordByteArray.appendBase32String(aPassword); |
341 | 338 | ||
342 | result = passwordByteArray.toBase64String(); | 339 | result = passwordByteArray.toBase64String(); |
343 | } catch(exception) { | 340 | } catch(exception) { |
344 | result = aPassword; | 341 | result = aPassword; |
345 | } | 342 | } |
346 | } else { | 343 | } else { |
347 | result = aPassword; | 344 | result = aPassword; |
348 | } | 345 | } |
349 | 346 | ||
350 | //console.log("Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword", aPassword, result); | ||
351 | return result; | 347 | return result; |
352 | } | 348 | } |
353 | 349 | ||
354 | //############################################################################# | 350 | //############################################################################# |
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js b/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js index f51bbc2..986db40 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js | |||
@@ -1,118 +1,116 @@ | |||
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 | try { if (typeof(Clipperz.PM.DataModel.Record.Version) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.DataModel.Record.Version) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.DataModel.Record.Version.Field depends on Clipperz.PM.DataModel.Record.Version!"; | 25 | throw "Clipperz.PM.DataModel.Record.Version.Field depends on Clipperz.PM.DataModel.Record.Version!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | Clipperz.PM.DataModel.Record.Version.Field = function(args) { | 28 | Clipperz.PM.DataModel.Record.Version.Field = function(args) { |
31 | Clipperz.PM.DataModel.Record.Version.Field.superclass.constructor.apply(this, arguments); | 29 | Clipperz.PM.DataModel.Record.Version.Field.superclass.constructor.apply(this, arguments); |
32 | 30 | ||
33 | this._recordVersion = args.recordVersion|| Clipperz.Base.exception.raise('MandatoryParameter'); | 31 | this._recordVersion = args.recordVersion|| Clipperz.Base.exception.raise('MandatoryParameter'); |
34 | this._reference = args.reference || Clipperz.PM.Crypto.randomKey(); | 32 | this._reference = args.reference || Clipperz.PM.Crypto.randomKey(); |
35 | 33 | ||
36 | return this; | 34 | return this; |
37 | } | 35 | } |
38 | 36 | ||
39 | 37 | ||
40 | Clipperz.Base.extend(Clipperz.PM.DataModel.Record.Version.Field, Object, { | 38 | Clipperz.Base.extend(Clipperz.PM.DataModel.Record.Version.Field, Object, { |
41 | 39 | ||
42 | 'toString': function() { | 40 | 'toString': function() { |
43 | return "Record.Version.Field (" + this.reference() + ")"; | 41 | return "Record.Version.Field (" + this.reference() + ")"; |
44 | }, | 42 | }, |
45 | 43 | ||
46 | //------------------------------------------------------------------------- | 44 | //------------------------------------------------------------------------- |
47 | 45 | ||
48 | 'recordVersion': function () { | 46 | 'recordVersion': function () { |
49 | return this._recordVersion; | 47 | return this._recordVersion; |
50 | }, | 48 | }, |
51 | 49 | ||
52 | //------------------------------------------------------------------------- | 50 | //------------------------------------------------------------------------- |
53 | 51 | ||
54 | 'reference': function () { | 52 | 'reference': function () { |
55 | return this._reference; | 53 | return this._reference; |
56 | }, | 54 | }, |
57 | 55 | ||
58 | //------------------------------------------------------------------------- | 56 | //------------------------------------------------------------------------- |
59 | 57 | ||
60 | 'getItem': function (aKey) { | 58 | 'getItem': function (aKey) { |
61 | return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.getItem", [ | 59 | return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.getItem", [ |
62 | MochiKit.Base.method(this, 'recordVersion'), | 60 | MochiKit.Base.method(this, 'recordVersion'), |
63 | MochiKit.Base.methodcaller('getValue', 'fields' + '.' + this.reference() + '.' + aKey) | 61 | MochiKit.Base.methodcaller('getValue', 'fields' + '.' + this.reference() + '.' + aKey) |
64 | ], {trace:false}); | 62 | ], {trace:false}); |
65 | }, | 63 | }, |
66 | 64 | ||
67 | 'setItem': function (aKey, aValue) { | 65 | 'setItem': function (aKey, aValue) { |
68 | return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.getItem", [ | 66 | return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.getItem", [ |
69 | MochiKit.Base.method(this, 'recordVersion'), | 67 | MochiKit.Base.method(this, 'recordVersion'), |
70 | MochiKit.Base.methodcaller('setValue', 'fields' + '.' + this.reference() + '.' + aKey, aValue) | 68 | MochiKit.Base.methodcaller('setValue', 'fields' + '.' + this.reference() + '.' + aKey, aValue) |
71 | ], {trace:false}); | 69 | ], {trace:false}); |
72 | }, | 70 | }, |
73 | 71 | ||
74 | //------------------------------------------------------------------------- | 72 | //------------------------------------------------------------------------- |
75 | 73 | ||
76 | 'label': function () { | 74 | 'label': function () { |
77 | return this.getItem('label'); | 75 | return this.getItem('label'); |
78 | }, | 76 | }, |
79 | 77 | ||
80 | 'setLabel': function (aValue) { | 78 | 'setLabel': function (aValue) { |
81 | return this.setItem('label', aValue); | 79 | return this.setItem('label', aValue); |
82 | }, | 80 | }, |
83 | 81 | ||
84 | //------------------------------------------------------------------------- | 82 | //------------------------------------------------------------------------- |
85 | 83 | ||
86 | 'value': function () { | 84 | 'value': function () { |
87 | return this.getItem('value'); | 85 | return this.getItem('value'); |
88 | }, | 86 | }, |
89 | 87 | ||
90 | 'setValue': function (aValue) { | 88 | 'setValue': function (aValue) { |
91 | return this.setItem('value', aValue); | 89 | return this.setItem('value', aValue); |
92 | }, | 90 | }, |
93 | 91 | ||
94 | //------------------------------------------------------------------------- | 92 | //------------------------------------------------------------------------- |
95 | 93 | ||
96 | 'actionType': function () { | 94 | 'actionType': function () { |
97 | return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.actionType", [ | 95 | return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.actionType", [ |
98 | Clipperz.Async.collectResults("Clipperz.PM.DataModel.Record.Version.Field.actionType [collect results]", { | 96 | Clipperz.Async.collectResults("Clipperz.PM.DataModel.Record.Version.Field.actionType [collect results]", { |
99 | 'isHidden':MochiKit.Base.method(this, 'isHidden'), | 97 | 'isHidden':MochiKit.Base.method(this, 'isHidden'), |
100 | 'value':MochiKit.Base.method(this, 'value') | 98 | 'value':MochiKit.Base.method(this, 'value') |
101 | }, {trace:false}), | 99 | }, {trace:false}), |
102 | function (someValues) { | 100 | function (someValues) { |
103 | var result; //'NONE', 'URL', 'EMAIL', 'PASSWORD' | 101 | var result; //'NONE', 'URL', 'EMAIL', 'PASSWORD' |
104 | 102 | ||
105 | result = 'NONE'; | 103 | result = 'NONE'; |
106 | 104 | ||
107 | if (someValues['isHidden']) { | 105 | if (someValues['isHidden']) { |
108 | result = 'PASSWORD'; | 106 | result = 'PASSWORD'; |
109 | } else if (Clipperz.Base.isUrl(someValues['value'])) { | 107 | } else if (Clipperz.Base.isUrl(someValues['value'])) { |
110 | result = 'URL' | 108 | result = 'URL' |
111 | } else if (Clipperz.Base.isEmail(someValues['value'])) { | 109 | } else if (Clipperz.Base.isEmail(someValues['value'])) { |
112 | result = 'EMAIL' | 110 | result = 'EMAIL' |
113 | }; | 111 | }; |
114 | 112 | ||
115 | return result; | 113 | return result; |
116 | } | 114 | } |
117 | ], {trace:false}); | 115 | ], {trace:false}); |
118 | }, | 116 | }, |
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.js b/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.js index dd35fc9..87b319c 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.js | |||
@@ -1,333 +1,328 @@ | |||
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 | try { if (typeof(Clipperz.PM.DataModel.Record) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.DataModel.Record) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.DataModel.Record.Version depends on Clipperz.PM.DataModel.Record!"; | 25 | throw "Clipperz.PM.DataModel.Record.Version depends on Clipperz.PM.DataModel.Record!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | Clipperz.PM.DataModel.Record.Version = function(args) { | 28 | Clipperz.PM.DataModel.Record.Version = function(args) { |
31 | //console.log(">>> Record.new"); | ||
32 | Clipperz.PM.DataModel.Record.Version.superclass.constructor.apply(this, arguments); | 29 | Clipperz.PM.DataModel.Record.Version.superclass.constructor.apply(this, arguments); |
33 | 30 | ||
34 | this._getVersionFunction = args.getVersion|| Clipperz.Base.exception.raise('MandatoryParameter'); | 31 | this._getVersionFunction = args.getVersion|| Clipperz.Base.exception.raise('MandatoryParameter'); |
35 | this._fields = null; | 32 | this._fields = null; |
36 | 33 | ||
37 | return this; | 34 | return this; |
38 | } | 35 | } |
39 | 36 | ||
40 | 37 | ||
41 | Clipperz.Base.extend(Clipperz.PM.DataModel.Record.Version, Clipperz.PM.DataModel.EncryptedRemoteObject, { | 38 | Clipperz.Base.extend(Clipperz.PM.DataModel.Record.Version, Clipperz.PM.DataModel.EncryptedRemoteObject, { |
42 | 39 | ||
43 | 'toString': function() { | 40 | 'toString': function() { |
44 | return "Record.Version (" + this.reference() + ")"; | 41 | return "Record.Version (" + this.reference() + ")"; |
45 | }, | 42 | }, |
46 | 43 | ||
47 | //------------------------------------------------------------------------- | 44 | //------------------------------------------------------------------------- |
48 | 45 | ||
49 | 'reference': function () { | 46 | 'reference': function () { |
50 | return this._reference; | 47 | return this._reference; |
51 | }, | 48 | }, |
52 | 49 | ||
53 | //------------------------------------------------------------------------- | 50 | //------------------------------------------------------------------------- |
54 | /* | 51 | /* |
55 | 'hasPendingChanges': function () { | 52 | 'hasPendingChanges': function () { |
56 | var deferredResult; | 53 | var deferredResult; |
57 | 54 | ||
58 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.Version.hasPendingChanges", {trace:false}); | 55 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.Version.hasPendingChanges", {trace:false}); |
59 | deferredResult.addCallback(MochiKit.Base.bind(Clipperz.PM.DataModel.Record.Version.superclass.hasPendingChanges, this)); | 56 | deferredResult.addCallback(MochiKit.Base.bind(Clipperz.PM.DataModel.Record.Version.superclass.hasPendingChanges, this)); |
60 | deferredResult.callback(); | 57 | deferredResult.callback(); |
61 | 58 | ||
62 | return deferredResult; | 59 | return deferredResult; |
63 | }, | 60 | }, |
64 | */ | 61 | */ |
65 | //------------------------------------------------------------------------- | 62 | //------------------------------------------------------------------------- |
66 | 63 | ||
67 | 64 | ||
68 | 'hasPendingChangesWhenBrandNew': function () { | 65 | 'hasPendingChangesWhenBrandNew': function () { |
69 | var deferredResult; | 66 | var deferredResult; |
70 | 67 | ||
71 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.Version.hasPendingChangesWhenBrandNew", {trace:false}); | 68 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.Version.hasPendingChangesWhenBrandNew", {trace:false}); |
72 | deferredResult.addMethod(this, 'fields'); | 69 | deferredResult.addMethod(this, 'fields'); |
73 | deferredResult.addCallback(MochiKit.Base.values); | 70 | deferredResult.addCallback(MochiKit.Base.values); |
74 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.methodcaller('isEmpty')) | 71 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.methodcaller('isEmpty')) |
75 | deferredResult.addCallback(Clipperz.Async.collectAll); | 72 | deferredResult.addCallback(Clipperz.Async.collectAll); |
76 | deferredResult.addCallback(function(someValues) { | 73 | deferredResult.addCallback(function(someValues) { |
77 | return MochiKit.Iter.every(someValues, MochiKit.Base.operator.identity); | 74 | return MochiKit.Iter.every(someValues, MochiKit.Base.operator.identity); |
78 | }); | 75 | }); |
79 | deferredResult.addCallback(MochiKit.Base.operator.lognot) | 76 | deferredResult.addCallback(MochiKit.Base.operator.lognot) |
80 | deferredResult.callback(); | 77 | deferredResult.callback(); |
81 | 78 | ||
82 | return deferredResult; | 79 | return deferredResult; |
83 | }, | 80 | }, |
84 | 81 | ||
85 | //========================================================================= | 82 | //========================================================================= |
86 | 83 | ||
87 | 'commitTransientState': function () { | 84 | 'commitTransientState': function () { |
88 | var deferredResult; | 85 | var deferredResult; |
89 | 86 | ||
90 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.Version.commitTransientState", {trace:false}); | 87 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.Version.commitTransientState", {trace:false}); |
91 | deferredResult.addCallback(MochiKit.Base.bind(Clipperz.PM.DataModel.Record.Version.superclass.commitTransientState, this)); | 88 | deferredResult.addCallback(MochiKit.Base.bind(Clipperz.PM.DataModel.Record.Version.superclass.commitTransientState, this)); |
92 | deferredResult.callback(); | 89 | deferredResult.callback(); |
93 | 90 | ||
94 | return deferredResult; | 91 | return deferredResult; |
95 | }, | 92 | }, |
96 | 93 | ||
97 | //========================================================================= | 94 | //========================================================================= |
98 | 95 | ||
99 | 'unpackData': function (someData) { //++ | 96 | 'unpackData': function (someData) { //++ |
100 | varresult; | 97 | varresult; |
101 | 98 | ||
102 | //console.log("Record.Version - UNPACK DATA", this, someData); | ||
103 | result = someData; | 99 | result = someData; |
104 | if ((someData['fields'] != null) && (someData['fields'] instanceof Array)) { | 100 | if ((someData['fields'] != null) && (someData['fields'] instanceof Array)) { |
105 | varfields; | 101 | varfields; |
106 | var i,c; | 102 | var i,c; |
107 | 103 | ||
108 | fields = someData['fields']; | 104 | fields = someData['fields']; |
109 | delete someData['fields']; | 105 | delete someData['fields']; |
110 | 106 | ||
111 | someData['fields'] = {}; | 107 | someData['fields'] = {}; |
112 | c = fields.length; | 108 | c = fields.length; |
113 | for (i=0; i<c; i++) { | 109 | for (i=0; i<c; i++) { |
114 | someData['fields'][i] = fields[i]; | 110 | someData['fields'][i] = fields[i]; |
115 | } | 111 | } |
116 | } | 112 | } |
117 | 113 | ||
118 | 114 | ||
119 | 115 | ||
120 | return result; | 116 | return result; |
121 | }, | 117 | }, |
122 | 118 | ||
123 | //========================================================================= | 119 | //========================================================================= |
124 | 120 | ||
125 | 'fields': function () { | 121 | 'fields': function () { |
126 | vardeferredResult; | 122 | vardeferredResult; |
127 | var deferredLock; | 123 | var deferredLock; |
128 | 124 | ||
129 | deferredLock = this.getDeferredLockForKey('fields'); | 125 | deferredLock = this.getDeferredLockForKey('fields'); |
130 | 126 | ||
131 | deferredResult = new Clipperz.Async.Deferred("Record.Version.fields", {trace:false}); | 127 | deferredResult = new Clipperz.Async.Deferred("Record.Version.fields", {trace:false}); |
132 | deferredResult.acquireLock(deferredLock); | 128 | deferredResult.acquireLock(deferredLock); |
133 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 129 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
134 | var innerDeferredResult; | 130 | var innerDeferredResult; |
135 | 131 | ||
136 | if (this._fields == null) { | 132 | if (this._fields == null) { |
137 | innerDeferredResult = new Clipperz.Async.Deferred("Record.Version.fields <inner deferred>", {trace:false}); | 133 | innerDeferredResult = new Clipperz.Async.Deferred("Record.Version.fields <inner deferred>", {trace:false}); |
138 | innerDeferredResult.addMethod(this, 'getValue', 'fields'); | 134 | innerDeferredResult.addMethod(this, 'getValue', 'fields'); |
139 | innerDeferredResult.addCallback(MochiKit.Base.bind(function (someObjectData) { | 135 | innerDeferredResult.addCallback(MochiKit.Base.bind(function (someObjectData) { |
140 | var reference; | 136 | var reference; |
141 | 137 | ||
142 | this._fields = {}; | 138 | this._fields = {}; |
143 | 139 | ||
144 | for (reference in someObjectData) { | 140 | for (reference in someObjectData) { |
145 | varrecordVersionField; | 141 | varrecordVersionField; |
146 | 142 | ||
147 | recordVersionField = new Clipperz.PM.DataModel.Record.Version.Field({ | 143 | recordVersionField = new Clipperz.PM.DataModel.Record.Version.Field({ |
148 | 'recordVersion':this, | 144 | 'recordVersion':this, |
149 | 'reference': reference | 145 | 'reference': reference |
150 | }); | 146 | }); |
151 | 147 | ||
152 | this._fields[reference] = recordVersionField; | 148 | this._fields[reference] = recordVersionField; |
153 | } | 149 | } |
154 | 150 | ||
155 | return this._fields; | 151 | return this._fields; |
156 | }, this)); | 152 | }, this)); |
157 | innerDeferredResult.callback(); | 153 | innerDeferredResult.callback(); |
158 | } else { | 154 | } else { |
159 | innerDeferredResult = MochiKit.Async.succeed(this._fields); | 155 | innerDeferredResult = MochiKit.Async.succeed(this._fields); |
160 | } | 156 | } |
161 | 157 | ||
162 | return innerDeferredResult; | 158 | return innerDeferredResult; |
163 | }, this)); | 159 | }, this)); |
164 | deferredResult.releaseLock(deferredLock); | 160 | deferredResult.releaseLock(deferredLock); |
165 | deferredResult.callback(); | 161 | deferredResult.callback(); |
166 | 162 | ||
167 | return deferredResult; | 163 | return deferredResult; |
168 | }, | 164 | }, |
169 | 165 | ||
170 | //------------------------------------------------------------------------- | 166 | //------------------------------------------------------------------------- |
171 | 167 | ||
172 | 'getFieldsValues': function () { | 168 | 'getFieldsValues': function () { |
173 | return this.getValue('fields'); | 169 | return this.getValue('fields'); |
174 | }, | 170 | }, |
175 | 171 | ||
176 | //------------------------------------------------------------------------- | 172 | //------------------------------------------------------------------------- |
177 | 173 | ||
178 | 'addField': function (someParameters) { | 174 | 'addField': function (someParameters) { |
179 | varnewField; | 175 | varnewField; |
180 | 176 | ||
181 | newField = new Clipperz.PM.DataModel.Record.Version.Field({recordVersion:this}); | 177 | newField = new Clipperz.PM.DataModel.Record.Version.Field({recordVersion:this}); |
182 | 178 | ||
183 | return Clipperz.Async.callbacks("Record.Version.addField", [ | 179 | return Clipperz.Async.callbacks("Record.Version.addField", [ |
184 | MochiKit.Base.method(this, 'fields'), | 180 | MochiKit.Base.method(this, 'fields'), |
185 | 181 | ||
186 | MochiKit.Base.method(this, '_getObjectDataStore'), | 182 | MochiKit.Base.method(this, '_getObjectDataStore'), |
187 | MochiKit.Base.methodcaller('values'), | 183 | MochiKit.Base.methodcaller('values'), |
188 | Clipperz.Base.serializeJSON, | 184 | Clipperz.Base.serializeJSON, |
189 | 185 | ||
190 | MochiKit.Base.bind(function () { this._fields[newField.reference()] = newField; }, this), | 186 | MochiKit.Base.bind(function () { this._fields[newField.reference()] = newField; }, this), |
191 | MochiKit.Base.method(newField, 'setLabel', someParameters['label']), | 187 | MochiKit.Base.method(newField, 'setLabel', someParameters['label']), |
192 | MochiKit.Base.method(newField, 'setValue', someParameters['value']), | 188 | MochiKit.Base.method(newField, 'setValue', someParameters['value']), |
193 | MochiKit.Base.method(newField, 'setIsHidden',someParameters['isHidden']), | 189 | MochiKit.Base.method(newField, 'setIsHidden',someParameters['isHidden']), |
194 | 190 | ||
195 | MochiKit.Base.method(this, '_getObjectDataStore'), | 191 | MochiKit.Base.method(this, '_getObjectDataStore'), |
196 | MochiKit.Base.methodcaller('values'), | 192 | MochiKit.Base.methodcaller('values'), |
197 | Clipperz.Base.serializeJSON, | 193 | Clipperz.Base.serializeJSON, |
198 | 194 | ||
199 | MochiKit.Base.partial(MochiKit.Async.succeed, newField) | 195 | MochiKit.Base.partial(MochiKit.Async.succeed, newField) |
200 | ], {trace:false}); | 196 | ], {trace:false}); |
201 | }, | 197 | }, |
202 | 198 | ||
203 | //------------------------------------------------------------------------- | 199 | //------------------------------------------------------------------------- |
204 | 200 | ||
205 | 'removeField': function (aField) { | 201 | 'removeField': function (aField) { |
206 | return Clipperz.Async.callbacks("Record.Version.removeField", [ | 202 | return Clipperz.Async.callbacks("Record.Version.removeField", [ |
207 | MochiKit.Base.method(this, 'fields'), | 203 | MochiKit.Base.method(this, 'fields'), |
208 | MochiKit.Base.bind(function () { delete this._fields[aField.reference()]; }, this), | 204 | MochiKit.Base.bind(function () { delete this._fields[aField.reference()]; }, this), |
209 | MochiKit.Base.method(this, 'removeValue', 'fields' + '.' + aField.reference()) | 205 | MochiKit.Base.method(this, 'removeValue', 'fields' + '.' + aField.reference()) |
210 | ], {trace:false}); | 206 | ], {trace:false}); |
211 | }, | 207 | }, |
212 | 208 | ||
213 | //------------------------------------------------------------------------- | 209 | //------------------------------------------------------------------------- |
214 | /* | 210 | /* |
215 | 'sortFieldReference': function (someSortedFieldReferences) { | 211 | 'sortFieldReference': function (someSortedFieldReferences) { |
216 | 212 | ||
217 | 213 | ||
218 | 214 | ||
219 | }, | 215 | }, |
220 | */ | 216 | */ |
221 | //========================================================================= | 217 | //========================================================================= |
222 | /* | 218 | /* |
223 | 'directLogins': function () { | 219 | 'directLogins': function () { |
224 | return MochiKit.Base.values(this._directLogins); | 220 | return MochiKit.Base.values(this._directLogins); |
225 | }, | 221 | }, |
226 | 222 | ||
227 | 'addDirectLogin': function (aDirectLogin) { | 223 | 'addDirectLogin': function (aDirectLogin) { |
228 | this._directLogins[aDirectLogin.reference()] = aDirectLogin; | 224 | this._directLogins[aDirectLogin.reference()] = aDirectLogin; |
229 | }, | 225 | }, |
230 | */ | 226 | */ |
231 | 227 | ||
232 | //========================================================================= | 228 | //========================================================================= |
233 | /* | 229 | /* |
234 | 'updateValues': function (anotherVersion) { | 230 | 'updateValues': function (anotherVersion) { |
235 | return Clipperz.Async.callbacks("Record.Version.updateValue", [ | 231 | return Clipperz.Async.callbacks("Record.Version.updateValue", [ |
236 | MochiKit.Base.partial(MochiKit.Async.succeed, this) | 232 | MochiKit.Base.partial(MochiKit.Async.succeed, this) |
237 | ], {trace:false}); | 233 | ], {trace:false}); |
238 | }, | 234 | }, |
239 | */ | 235 | */ |
240 | //========================================================================= | 236 | //========================================================================= |
241 | 237 | ||
242 | 'setRemoteData': function (aValue) { | 238 | 'setRemoteData': function (aValue) { |
243 | this._remoteData = aValue; | 239 | this._remoteData = aValue; |
244 | 240 | ||
245 | return aValue; | 241 | return aValue; |
246 | }, | 242 | }, |
247 | 243 | ||
248 | //========================================================================= | 244 | //========================================================================= |
249 | 245 | ||
250 | 'getVersionFunction': function () { | 246 | 'getVersionFunction': function () { |
251 | return this._getVersionFunction; | 247 | return this._getVersionFunction; |
252 | }, | 248 | }, |
253 | 249 | ||
254 | 'previousVersion': function () { | 250 | 'previousVersion': function () { |
255 | return Clipperz.Async.callbacks("Record.Versions.previousVersion", [ | 251 | return Clipperz.Async.callbacks("Record.Versions.previousVersion", [ |
256 | MochiKit.Base.method(this, 'previousVersionReference'), | 252 | MochiKit.Base.method(this, 'previousVersionReference'), |
257 | this.getVersionFunction() | 253 | this.getVersionFunction() |
258 | ], {trace:false}); | 254 | ], {trace:false}); |
259 | }, | 255 | }, |
260 | 256 | ||
261 | 'previousVersionReference': function () { | 257 | 'previousVersionReference': function () { |
262 | return this.getValue('previousVersionReference'); | 258 | return this.getValue('previousVersionReference'); |
263 | }, | 259 | }, |
264 | 260 | ||
265 | 'previousVersionKey': function () { | 261 | 'previousVersionKey': function () { |
266 | //TODO: this value i encrypted on its own. So it can not be saved in the main objectStore!!! | 262 | //TODO: this value i encrypted on its own. So it can not be saved in the main objectStore!!! |
267 | return this.getValue('previousVersionKey'); | 263 | return this.getValue('previousVersionKey'); |
268 | }, | 264 | }, |
269 | 265 | ||
270 | //------------------------------------------------------------------------- | 266 | //------------------------------------------------------------------------- |
271 | 267 | ||
272 | 'setPreviousVersionReferenceAndKey': function (aVersionObjectAndKey) { | 268 | 'setPreviousVersionReferenceAndKey': function (aVersionObjectAndKey) { |
273 | // this._previousVersion = anotherVersion; | 269 | // this._previousVersion = anotherVersion; |
274 | return Clipperz.Async.callbacks("Record.Version.setPreviousVersion", [ | 270 | return Clipperz.Async.callbacks("Record.Version.setPreviousVersion", [ |
275 | MochiKit.Base.method(this, 'setValue', 'previousVersionReference',aVersionObjectAndKey['reference']), | 271 | MochiKit.Base.method(this, 'setValue', 'previousVersionReference',aVersionObjectAndKey['reference']), |
276 | MochiKit.Base.method(this, 'setValue', 'previousVersionKey', aVersionObjectAndKey['key']) | 272 | MochiKit.Base.method(this, 'setValue', 'previousVersionKey', aVersionObjectAndKey['key']) |
277 | ], {trace:false}); | 273 | ], {trace:false}); |
278 | }, | 274 | }, |
279 | 275 | ||
280 | //========================================================================= | 276 | //========================================================================= |
281 | 277 | ||
282 | 'revertChanges': function () { | 278 | 'revertChanges': function () { |
283 | this.setReference(this.transientState()['originalReference']); | 279 | this.setReference(this.transientState()['originalReference']); |
284 | Clipperz.PM.DataModel.Record.Version.superclass.revertChanges.apply(this, arguments); | 280 | Clipperz.PM.DataModel.Record.Version.superclass.revertChanges.apply(this, arguments); |
285 | }, | 281 | }, |
286 | 282 | ||
287 | //------------------------------------------------------------------------- | 283 | //------------------------------------------------------------------------- |
288 | 284 | ||
289 | 'prepareRemoteDataWithKey': function (aKey) { | 285 | 'prepareRemoteDataWithKey': function (aKey) { |
290 | var deferredResult; | 286 | var deferredResult; |
291 | var result; | 287 | var result; |
292 | 288 | ||
293 | result = {}; | 289 | result = {}; |
294 | 290 | ||
295 | //console.log("prepareRemoteDataWithKey", aKey); | ||
296 | deferredResult = new Clipperz.Async.Deferred("Record.Version.prepareRemoteDataWithKey", {trace:false}); | 291 | deferredResult = new Clipperz.Async.Deferred("Record.Version.prepareRemoteDataWithKey", {trace:false}); |
297 | if (this.isBrandNew() == false) { | 292 | if (this.isBrandNew() == false) { |
298 | this.transientState()['originalReference'] = this.reference(); | 293 | this.transientState()['originalReference'] = this.reference(); |
299 | 294 | ||
300 | deferredResult.collectResults({ | 295 | deferredResult.collectResults({ |
301 | 'key':MochiKit.Base.partial(MochiKit.Async.succeed, aKey), | 296 | 'key':MochiKit.Base.partial(MochiKit.Async.succeed, aKey), |
302 | 'value': MochiKit.Base.method(this, 'getKey'), | 297 | 'value': MochiKit.Base.method(this, 'getKey'), |
303 | 'version': MochiKit.Base.partial(MochiKit.Async.succeed, Clipperz.PM.Crypto.encryptingFunctions.currentVersion) | 298 | 'version': MochiKit.Base.partial(MochiKit.Async.succeed, Clipperz.PM.Crypto.encryptingFunctions.currentVersion) |
304 | }); | 299 | }); |
305 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncrypt); | 300 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncrypt); |
306 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'previousVersionKey'); | 301 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'previousVersionKey'); |
307 | } else { | 302 | } else { |
308 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'previousVersionKey', Clipperz.PM.Crypto.nullValue); | 303 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'previousVersionKey', Clipperz.PM.Crypto.nullValue); |
309 | } | 304 | } |
310 | deferredResult.addCallback(MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.prepareRemoteDataWithKey, this, aKey)); | 305 | deferredResult.addCallback(MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.prepareRemoteDataWithKey, this, aKey)); |
311 | deferredResult.addCallback(MochiKit.Base.update, result); | 306 | deferredResult.addCallback(MochiKit.Base.update, result); |
312 | deferredResult.addMethod(this, 'setRemoteData'); | 307 | deferredResult.addMethod(this, 'setRemoteData'); |
313 | 308 | ||
314 | deferredResult.callback(); | 309 | deferredResult.callback(); |
315 | 310 | ||
316 | return deferredResult; | 311 | return deferredResult; |
317 | }, | 312 | }, |
318 | 313 | ||
319 | //========================================================================= | 314 | //========================================================================= |
320 | /* | 315 | /* |
321 | 'deleteAllCleanTextData': function () { | 316 | 'deleteAllCleanTextData': function () { |
322 | return Clipperz.PM.DataModel.Record.Version.superclass.deleteAllCleanTextData.apply(this, arguments); | 317 | return Clipperz.PM.DataModel.Record.Version.superclass.deleteAllCleanTextData.apply(this, arguments); |
323 | }, | 318 | }, |
324 | 319 | ||
325 | 'hasAnyCleanTextData': function () { | 320 | 'hasAnyCleanTextData': function () { |
326 | return Clipperz.PM.DataModel.Record.Version.superclass.hasAnyCleanTextData.apply(this, arguments); | 321 | return Clipperz.PM.DataModel.Record.Version.superclass.hasAnyCleanTextData.apply(this, arguments); |
327 | }, | 322 | }, |
328 | */ | 323 | */ |
329 | //========================================================================= | 324 | //========================================================================= |
330 | __syntaxFix__: "syntax fix" | 325 | __syntaxFix__: "syntax fix" |
331 | }); | 326 | }); |
332 | 327 | ||
333 | 328 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/Record.js b/frontend/gamma/js/Clipperz/PM/DataModel/Record.js index b816f80..3fc1813 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/Record.js | |||
@@ -1,878 +1,854 @@ | |||
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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | 28 | ||
31 | Clipperz.PM.DataModel.Record = function(args) { | 29 | Clipperz.PM.DataModel.Record = function(args) { |
32 | //console.log(">>> new Clipperz.PM.DataModel.Record", args); | ||
33 | Clipperz.PM.DataModel.Record.superclass.constructor.apply(this, arguments); | 30 | Clipperz.PM.DataModel.Record.superclass.constructor.apply(this, arguments); |
34 | 31 | ||
35 | this._updateDate = (args.updateDate ? Clipperz.PM.Date.parse(args.updateDate) : Clipperz.Base.exception.raise('MandatoryParameter')); | 32 | this._updateDate = (args.updateDate ? Clipperz.PM.Date.parse(args.updateDate) : Clipperz.Base.exception.raise('MandatoryParameter')); |
36 | 33 | ||
37 | this._retrieveIndexDataFunction = args.retrieveIndexDataFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); | 34 | this._retrieveIndexDataFunction = args.retrieveIndexDataFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); |
38 | this._updateIndexDataFunction = args.updateIndexDataFunction || Clipperz.Base.exception.raise('MandatoryParameter'); | 35 | this._updateIndexDataFunction = args.updateIndexDataFunction || Clipperz.Base.exception.raise('MandatoryParameter'); |
39 | 36 | ||
40 | this._retrieveDirectLoginIndexDataFunction = args.retrieveDirectLoginIndexDataFunction|| null; | 37 | this._retrieveDirectLoginIndexDataFunction = args.retrieveDirectLoginIndexDataFunction|| null; |
41 | this._setDirectLoginIndexDataFunction = args.setDirectLoginIndexDataFunction || null; | 38 | this._setDirectLoginIndexDataFunction = args.setDirectLoginIndexDataFunction || null; |
42 | this._removeDirectLoginIndexDataFunction = args.removeDirectLoginIndexDataFunction|| null; | 39 | this._removeDirectLoginIndexDataFunction = args.removeDirectLoginIndexDataFunction|| null; |
43 | 40 | ||
44 | this._createNewDirectLoginFunction = args.createNewDirectLoginFunction || null; | 41 | this._createNewDirectLoginFunction = args.createNewDirectLoginFunction || null; |
45 | 42 | ||
46 | this._directLogins = {}; | 43 | this._directLogins = {}; |
47 | 44 | ||
48 | this._versions = {}; | 45 | this._versions = {}; |
49 | 46 | ||
50 | this._currentRecordVersion = null; | 47 | this._currentRecordVersion = null; |
51 | if (this.isBrandNew()) { | 48 | if (this.isBrandNew()) { |
52 | var newVersion; | 49 | var newVersion; |
53 | 50 | ||
54 | this.setNotes(''); | 51 | this.setNotes(''); |
55 | newVersion = new Clipperz.PM.DataModel.Record.Version({ | 52 | newVersion = new Clipperz.PM.DataModel.Record.Version({ |
56 | 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'), | 53 | 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'), |
57 | 'getVersion': MochiKit.Base.method(this, 'getVersion') | 54 | 'getVersion': MochiKit.Base.method(this, 'getVersion') |
58 | 55 | ||
59 | }); | 56 | }); |
60 | this._versions[newVersion.reference()] = newVersion; | 57 | this._versions[newVersion.reference()] = newVersion; |
61 | this._currentVersionReference = newVersion.reference(); | 58 | this._currentVersionReference = newVersion.reference(); |
62 | // this.setLabel(''); | 59 | // this.setLabel(''); |
63 | } | 60 | } |
64 | 61 | ||
65 | //console.log("<<< new Clipperz.PM.DataModel.Record", args); | ||
66 | |||
67 | return this; | 62 | return this; |
68 | } | 63 | } |
69 | 64 | ||
70 | 65 | ||
71 | Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.EncryptedRemoteObject, { | 66 | Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.EncryptedRemoteObject, { |
72 | 67 | ||
73 | 'toString': function() { | 68 | 'toString': function() { |
74 | return "Record (" + this.reference() + ")"; | 69 | return "Record (" + this.reference() + ")"; |
75 | }, | 70 | }, |
76 | 71 | ||
77 | //------------------------------------------------------------------------- | 72 | //------------------------------------------------------------------------- |
78 | 73 | ||
79 | 'reference': function () { | 74 | 'reference': function () { |
80 | return this._reference; | 75 | return this._reference; |
81 | }, | 76 | }, |
82 | 77 | ||
83 | //========================================================================= | 78 | //========================================================================= |
84 | 79 | ||
85 | 'getIndexData': function () { | 80 | 'getIndexData': function () { |
86 | return this._retrieveIndexDataFunction(this.reference()); | 81 | return this._retrieveIndexDataFunction(this.reference()); |
87 | }, | 82 | }, |
88 | 83 | ||
89 | //......................................................................... | 84 | //......................................................................... |
90 | 85 | ||
91 | 'getIndexDataForKey': function (aKey) { | 86 | 'getIndexDataForKey': function (aKey) { |
92 | return Clipperz.Async.callbacks("Record.getIndexDataForKey", [ | 87 | return Clipperz.Async.callbacks("Record.getIndexDataForKey", [ |
93 | MochiKit.Base.method(this, 'getIndexData'), | 88 | MochiKit.Base.method(this, 'getIndexData'), |
94 | MochiKit.Base.itemgetter(aKey) | 89 | MochiKit.Base.itemgetter(aKey) |
95 | ], {trace:false}); | 90 | ], {trace:false}); |
96 | }, | 91 | }, |
97 | 92 | ||
98 | //------------------------------------------------------------------------- | 93 | //------------------------------------------------------------------------- |
99 | 94 | ||
100 | 'setIndexDataForKey': function (aKey, aValue) { | 95 | 'setIndexDataForKey': function (aKey, aValue) { |
101 | // return this._updateIndexDataFunction(this.reference(), aKey, aValue); | 96 | // return this._updateIndexDataFunction(this.reference(), aKey, aValue); |
102 | 97 | ||
103 | var deferredResult; | 98 | var deferredResult; |
104 | 99 | ||
105 | deferredResult = new Clipperz.Async.Deferred("Record.setIndexDataForKey", {trace:false}); | 100 | deferredResult = new Clipperz.Async.Deferred("Record.setIndexDataForKey", {trace:false}); |
106 | deferredResult.addMethod(this, 'getIndexDataForKey', aKey); | 101 | deferredResult.addMethod(this, 'getIndexDataForKey', aKey); |
107 | deferredResult.addCallback(MochiKit.Base.bind(function (aCurrentValue) { | 102 | deferredResult.addCallback(MochiKit.Base.bind(function (aCurrentValue) { |
108 | var result; | 103 | var result; |
109 | var originalValue; | 104 | var originalValue; |
110 | 105 | ||
111 | originalValue = this.transientState().getValue('originalValues.indexData.' + aKey); | 106 | originalValue = this.transientState().getValue('originalValues.indexData.' + aKey); |
112 | if (originalValue == null) { | 107 | if (originalValue == null) { |
113 | originalValue = this.transientState().setValue('originalValues.indexData.' + aKey, aCurrentValue); | 108 | originalValue = this.transientState().setValue('originalValues.indexData.' + aKey, aCurrentValue); |
114 | } | 109 | } |
115 | 110 | ||
116 | if (aCurrentValue != aValue) { | 111 | if (aCurrentValue != aValue) { |
117 | if (originalValue != aValue) { | 112 | if (originalValue != aValue) { |
118 | this.transientState().setValue('hasPendingChanges.indexData.' + aKey, true); | 113 | this.transientState().setValue('hasPendingChanges.indexData.' + aKey, true); |
119 | } else { | 114 | } else { |
120 | this.transientState().setValue('hasPendingChanges.indexData.' + aKey, false); | 115 | this.transientState().setValue('hasPendingChanges.indexData.' + aKey, false); |
121 | } | 116 | } |
122 | 117 | ||
123 | result = this._updateIndexDataFunction(this.reference(), aKey, aValue); | 118 | result = this._updateIndexDataFunction(this.reference(), aKey, aValue); |
124 | } else { | 119 | } else { |
125 | result = MochiKit.Async.succeed(aValue); | 120 | result = MochiKit.Async.succeed(aValue); |
126 | } | 121 | } |
127 | 122 | ||
128 | return result; | 123 | return result; |
129 | }, this)); | 124 | }, this)); |
130 | 125 | ||
131 | deferredResult.callback(); | 126 | deferredResult.callback(); |
132 | 127 | ||
133 | return deferredResult; | 128 | return deferredResult; |
134 | }, | 129 | }, |
135 | 130 | ||
136 | //========================================================================= | 131 | //========================================================================= |
137 | /* | 132 | /* |
138 | 'key': function () { | 133 | 'key': function () { |
139 | return this.getIndexDataForKey('key'); | 134 | return this.getIndexDataForKey('key'); |
140 | }, | 135 | }, |
141 | */ | 136 | */ |
142 | //========================================================================= | 137 | //========================================================================= |
143 | 138 | ||
144 | 'label': function () { | 139 | 'label': function () { |
145 | return this.getIndexDataForKey('label'); | 140 | return this.getIndexDataForKey('label'); |
146 | }, | 141 | }, |
147 | 142 | ||
148 | //......................................................................... | 143 | //......................................................................... |
149 | 144 | ||
150 | 'setLabel': function (aValue) { | 145 | 'setLabel': function (aValue) { |
151 | return this.setIndexDataForKey('label', aValue); | 146 | return this.setIndexDataForKey('label', aValue); |
152 | }, | 147 | }, |
153 | 148 | ||
154 | //========================================================================= | 149 | //========================================================================= |
155 | 150 | ||
156 | 'headerNotes': function () { | 151 | 'headerNotes': function () { |
157 | return this.getIndexDataForKey('notes'); | 152 | return this.getIndexDataForKey('notes'); |
158 | }, | 153 | }, |
159 | 154 | ||
160 | //------------------------------------------------------------------------- | 155 | //------------------------------------------------------------------------- |
161 | 156 | ||
162 | 'notes': function () { | 157 | 'notes': function () { |
163 | return Clipperz.Async.callbacks("Record.notes", [ | 158 | return Clipperz.Async.callbacks("Record.notes", [ |
164 | MochiKit.Base.method(this, 'headerNotes'), | 159 | MochiKit.Base.method(this, 'headerNotes'), |
165 | MochiKit.Base.bind(function (someHeaderNotes) { | 160 | MochiKit.Base.bind(function (someHeaderNotes) { |
166 | var result; | 161 | var result; |
167 | 162 | ||
168 | if ((someHeaderNotes == null) || (typeof(someHeaderNotes) == 'undefined')) { | 163 | if ((someHeaderNotes == null) || (typeof(someHeaderNotes) == 'undefined')) { |
169 | result = this.getValue('notes'); | 164 | result = this.getValue('notes'); |
170 | } else { | 165 | } else { |
171 | result = MochiKit.Async.succeed(someHeaderNotes); | 166 | result = MochiKit.Async.succeed(someHeaderNotes); |
172 | } | 167 | } |
173 | 168 | ||
174 | return result; | 169 | return result; |
175 | }, this) | 170 | }, this) |
176 | ], {trace:false}); | 171 | ], {trace:false}); |
177 | }, | 172 | }, |
178 | 173 | ||
179 | //......................................................................... | 174 | //......................................................................... |
180 | 175 | ||
181 | 'setNotes': function (aValue) { | 176 | 'setNotes': function (aValue) { |
182 | return this.setValue('notes', aValue); | 177 | return this.setValue('notes', aValue); |
183 | }, | 178 | }, |
184 | 179 | ||
185 | //========================================================================= | 180 | //========================================================================= |
186 | 181 | ||
187 | 'updateDate': function () { | 182 | 'updateDate': function () { |
188 | return MochiKit.Async.succeed(this._updateDate); | 183 | return MochiKit.Async.succeed(this._updateDate); |
189 | }, | 184 | }, |
190 | 185 | ||
191 | //========================================================================= | 186 | //========================================================================= |
192 | 187 | ||
193 | 'favicon': function () { | 188 | 'favicon': function () { |
194 | var result; | 189 | var result; |
195 | var directLogins; | 190 | var directLogins; |
196 | 191 | ||
197 | directLogins = MochiKit.Base.values(this.directLogins()); | 192 | directLogins = MochiKit.Base.values(this.directLogins()); |
198 | if (directLogins.length > 0) { | 193 | if (directLogins.length > 0) { |
199 | result = directLogins[0].favicon(); | 194 | result = directLogins[0].favicon(); |
200 | // } else if (/* is there an URL to use for searching a favicon */){ | 195 | // } else if (/* is there an URL to use for searching a favicon */){ |
201 | } else { | 196 | } else { |
202 | result = null; //MochiKit.Async.succeed(Clipperz.PM.Strings['defaultFaviconUrl']); | 197 | result = null; //MochiKit.Async.succeed(Clipperz.PM.Strings['defaultFaviconUrl']); |
203 | } | 198 | } |
204 | 199 | ||
205 | return result; | 200 | return result; |
206 | }, | 201 | }, |
207 | 202 | ||
208 | //------------------------------------------------------------------------- | 203 | //------------------------------------------------------------------------- |
209 | 204 | ||
210 | 'searchableContent': function () { | 205 | 'searchableContent': function () { |
211 | var deferredResult; | 206 | var deferredResult; |
212 | 207 | ||
213 | //console.log(">>> searchableContent"); | ||
214 | deferredResult = new Clipperz.Async.Deferred("Record.searchableContent", {trace:false}); | 208 | deferredResult = new Clipperz.Async.Deferred("Record.searchableContent", {trace:false}); |
215 | 209 | ||
216 | deferredResult.collectResults({ | 210 | deferredResult.collectResults({ |
217 | 'recordLabel': MochiKit.Base.method(this, 'label'), | 211 | 'recordLabel': MochiKit.Base.method(this, 'label'), |
218 | 'directLoginLabels': [ | 212 | 'directLoginLabels': [ |
219 | MochiKit.Base.method(this, 'directLoginReferences'), | 213 | MochiKit.Base.method(this, 'directLoginReferences'), |
220 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.itemgetter('label')) | 214 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.itemgetter('label')) |
221 | ] | 215 | ] |
222 | }) | 216 | }) |
223 | deferredResult.addCallback(function (someValues) { | 217 | deferredResult.addCallback(function (someValues) { |
224 | return someValues['recordLabel'] + ' ' + someValues['directLoginLabels'].join(' '); | 218 | return someValues['recordLabel'] + ' ' + someValues['directLoginLabels'].join(' '); |
225 | }); | 219 | }); |
226 | deferredResult.callback(); | 220 | deferredResult.callback(); |
227 | //console.log("<<< searchableContent"); | ||
228 | 221 | ||
229 | return deferredResult; | 222 | return deferredResult; |
230 | }, | 223 | }, |
231 | 224 | ||
232 | //------------------------------------------------------------------------- | 225 | //------------------------------------------------------------------------- |
233 | 226 | ||
234 | 'isMatching': function (aRegExp) { | 227 | 'isMatching': function (aRegExp) { |
235 | return Clipperz.Async.callbacks("deferredFilterFunction", [ | 228 | return Clipperz.Async.callbacks("deferredFilterFunction", [ |
236 | MochiKit.Base.method(this, 'searchableContent'), | 229 | MochiKit.Base.method(this, 'searchableContent'), |
237 | MochiKit.Base.method(aRegExp, 'test'), | 230 | MochiKit.Base.method(aRegExp, 'test'), |
238 | function (doesItMatch) { | 231 | function (doesItMatch) { |
239 | var result; | 232 | var result; |
240 | 233 | ||
241 | if (doesItMatch) { | 234 | if (doesItMatch) { |
242 | result = MochiKit.Async.succeed('match'); | 235 | result = MochiKit.Async.succeed('match'); |
243 | } else { | 236 | } else { |
244 | result = MochiKit.Async.fail('miss'); | 237 | result = MochiKit.Async.fail('miss'); |
245 | } | 238 | } |
246 | 239 | ||
247 | return result; | 240 | return result; |
248 | } | 241 | } |
249 | ], {trace:false}); | 242 | ], {trace:false}); |
250 | }, | 243 | }, |
251 | 244 | ||
252 | //========================================================================= | 245 | //========================================================================= |
253 | 246 | ||
254 | 'directLogins': function () { | 247 | 'directLogins': function () { |
255 | return this._directLogins; | 248 | return this._directLogins; |
256 | }, | 249 | }, |
257 | 250 | ||
258 | 'addDirectLogin': function (aDirectLogin) { | 251 | 'addDirectLogin': function (aDirectLogin) { |
259 | this._directLogins[aDirectLogin.reference()] = aDirectLogin; | 252 | this._directLogins[aDirectLogin.reference()] = aDirectLogin; |
260 | }, | 253 | }, |
261 | 254 | ||
262 | 'directLoginWithReference': function (aDirectLoginReference) { | 255 | 'directLoginWithReference': function (aDirectLoginReference) { |
263 | return this._directLogins[aDirectLoginReference]; | 256 | return this._directLogins[aDirectLoginReference]; |
264 | }, | 257 | }, |
265 | 258 | ||
266 | 'createNewDirectLoginFunction': function () { | 259 | 'createNewDirectLoginFunction': function () { |
267 | return this._createNewDirectLoginFunction; | 260 | return this._createNewDirectLoginFunction; |
268 | }, | 261 | }, |
269 | 262 | ||
270 | 'saveOriginalDirectLoginStatusToTransientState': function () { | 263 | 'saveOriginalDirectLoginStatusToTransientState': function () { |
271 | if (this.transientState().getValue('directLogins') == null) { | 264 | if (this.transientState().getValue('directLogins') == null) { |
272 | // this.transientState().setValue('directLogins', this._directLogins) | 265 | // this.transientState().setValue('directLogins', this._directLogins) |
273 | //console.log("SET TRANSIENT STATE", Clipperz.Base.serializeJSON(MochiKit.Base.keys(this.transientState().getValue('directLogins')))) | ||
274 | MochiKit.Iter.forEach(MochiKit.Base.keys(this._directLogins), MochiKit.Base.bind(function(aKey) { | 266 | MochiKit.Iter.forEach(MochiKit.Base.keys(this._directLogins), MochiKit.Base.bind(function(aKey) { |
275 | this.transientState().setValue('directLogins' + '.' + aKey, this._directLogins[aKey]) | 267 | this.transientState().setValue('directLogins' + '.' + aKey, this._directLogins[aKey]) |
276 | }, this)) | 268 | }, this)) |
277 | } | 269 | } |
278 | }, | 270 | }, |
279 | 271 | ||
280 | 'createNewDirectLogin': function () { | 272 | 'createNewDirectLogin': function () { |
281 | this.saveOriginalDirectLoginStatusToTransientState(); | 273 | this.saveOriginalDirectLoginStatusToTransientState(); |
282 | 274 | ||
283 | return this.createNewDirectLoginFunction()(this); | 275 | return this.createNewDirectLoginFunction()(this); |
284 | }, | 276 | }, |
285 | 277 | ||
286 | 'removeDirectLogin': function(aDirectLogin) { | 278 | 'removeDirectLogin': function(aDirectLogin) { |
287 | this.saveOriginalDirectLoginStatusToTransientState(); | 279 | this.saveOriginalDirectLoginStatusToTransientState(); |
288 | 280 | ||
289 | return Clipperz.Async.callbacks("Record.removeDirectLogin", [ | 281 | return Clipperz.Async.callbacks("Record.removeDirectLogin", [ |
290 | MochiKit.Base.method(this, 'removeValue', 'directLogins' + '.' + aDirectLogin.reference()), | 282 | MochiKit.Base.method(this, 'removeValue', 'directLogins' + '.' + aDirectLogin.reference()), |
291 | MochiKit.Base.bind(function () { | 283 | MochiKit.Base.bind(function () { |
292 | delete this._directLogins[aDirectLogin.reference()] | 284 | delete this._directLogins[aDirectLogin.reference()] |
293 | }, this) | 285 | }, this) |
294 | ], {trace:false}); | 286 | ], {trace:false}); |
295 | 287 | ||
296 | }, | 288 | }, |
297 | 289 | ||
298 | 'directLoginReferences': function () { | 290 | 'directLoginReferences': function () { |
299 | var result; | 291 | var result; |
300 | 292 | ||
301 | result = Clipperz.Async.callbacks("Record.directLoginReferences", [ | 293 | result = Clipperz.Async.callbacks("Record.directLoginReferences", [ |
302 | MochiKit.Base.method(this, 'directLogins'), | 294 | MochiKit.Base.method(this, 'directLogins'), |
303 | MochiKit.Base.values, | 295 | MochiKit.Base.values, |
304 | function (someDirectLogins) { | 296 | function (someDirectLogins) { |
305 | var result; | 297 | var result; |
306 | var i,c; | 298 | var i,c; |
307 | 299 | ||
308 | result = []; | 300 | result = []; |
309 | c = someDirectLogins.length; | 301 | c = someDirectLogins.length; |
310 | for (i=0; i<c; i++) { | 302 | for (i=0; i<c; i++) { |
311 | result.push(Clipperz.Async.collectResults("Record.directLoginReferences - collectResults", { | 303 | result.push(Clipperz.Async.collectResults("Record.directLoginReferences - collectResults", { |
312 | '_rowObject': MochiKit.Async.succeed, | 304 | '_rowObject': MochiKit.Async.succeed, |
313 | '_reference': MochiKit.Base.methodcaller('reference'), | 305 | '_reference': MochiKit.Base.methodcaller('reference'), |
314 | 'label': MochiKit.Base.methodcaller('label'), | 306 | 'label': MochiKit.Base.methodcaller('label'), |
315 | 'favicon': MochiKit.Base.methodcaller('favicon') | 307 | 'favicon': MochiKit.Base.methodcaller('favicon') |
316 | }, {trace:false})(someDirectLogins[i])); | 308 | }, {trace:false})(someDirectLogins[i])); |
317 | }; | 309 | }; |
318 | 310 | ||
319 | return result; | 311 | return result; |
320 | }, | 312 | }, |
321 | Clipperz.Async.collectAll | 313 | Clipperz.Async.collectAll |
322 | ], {trace:false}); | 314 | ], {trace:false}); |
323 | 315 | ||
324 | return result; | 316 | return result; |
325 | }, | 317 | }, |
326 | 318 | ||
327 | //========================================================================= | 319 | //========================================================================= |
328 | 320 | ||
329 | 'unpackRemoteData': function (someData) { | 321 | 'unpackRemoteData': function (someData) { |
330 | var result; | 322 | var result; |
331 | 323 | ||
332 | //console.log("new Clipperz.PM.DataModel.Record.Version [2]"); | ||
333 | /* | 324 | /* |
334 | this._currentRecordVersion = new Clipperz.PM.DataModel.Record.Version({ | 325 | this._currentRecordVersion = new Clipperz.PM.DataModel.Record.Version({ |
335 | 'reference': someData['currentVersion']['reference'], | 326 | 'reference': someData['currentVersion']['reference'], |
336 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getCurrentRecordVersionKey'), | 327 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getCurrentRecordVersionKey'), |
337 | 'remoteData': someData['currentVersion'], | 328 | 'remoteData': someData['currentVersion'], |
338 | }); | 329 | }); |
339 | */ | 330 | */ |
340 | var versionKey; | 331 | var versionKey; |
341 | 332 | ||
342 | for (versionKey in someData['versions']) { | 333 | for (versionKey in someData['versions']) { |
343 | //console.log("### versionKey", versionKey); | ||
344 | this._versions[versionKey] = new Clipperz.PM.DataModel.Record.Version({ | 334 | this._versions[versionKey] = new Clipperz.PM.DataModel.Record.Version({ |
345 | 'reference': versionKey, | 335 | 'reference': versionKey, |
346 | 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'), | 336 | 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'), |
347 | 'remoteData': someData['versions'][versionKey], | 337 | 'remoteData': someData['versions'][versionKey], |
348 | 'getVersion': MochiKit.Base.method(this, 'getVersion') | 338 | 'getVersion': MochiKit.Base.method(this, 'getVersion') |
349 | }) | 339 | }) |
350 | } | 340 | } |
351 | 341 | ||
352 | // this._currentVersionReference = someData['currentVersion']['reference']; | 342 | // this._currentVersionReference = someData['currentVersion']['reference']; |
353 | this._currentVersionReference = someData['currentVersion']; | 343 | this._currentVersionReference = someData['currentVersion']; |
354 | //console.log("=== currentVersionReference", this._currentVersionReference, someData); | ||
355 | 344 | ||
356 | result = Clipperz.PM.DataModel.Record.superclass.unpackRemoteData.apply(this, arguments); | 345 | result = Clipperz.PM.DataModel.Record.superclass.unpackRemoteData.apply(this, arguments); |
357 | 346 | ||
358 | return result; | 347 | return result; |
359 | }, | 348 | }, |
360 | 349 | ||
361 | //------------------------------------------------------------------------- | 350 | //------------------------------------------------------------------------- |
362 | 351 | ||
363 | 'unpackData': function (someData) { | 352 | 'unpackData': function (someData) { |
364 | var result; | 353 | var result; |
365 | 354 | ||
366 | result = Clipperz.PM.DataModel.Record.superclass.unpackData.apply(this, arguments); | 355 | result = Clipperz.PM.DataModel.Record.superclass.unpackData.apply(this, arguments); |
367 | 356 | ||
368 | if (MochiKit.Base.isUndefinedOrNull(result['notes'])) { | 357 | if (MochiKit.Base.isUndefinedOrNull(result['notes'])) { |
369 | result['notes'] = '' | 358 | result['notes'] = '' |
370 | } | 359 | } |
371 | 360 | ||
372 | return result; | 361 | return result; |
373 | }, | 362 | }, |
374 | 363 | ||
375 | //------------------------------------------------------------------------- | 364 | //------------------------------------------------------------------------- |
376 | 365 | ||
377 | 'prepareRemoteDataWithKey': function (aKey) { | 366 | 'prepareRemoteDataWithKey': function (aKey) { |
378 | var deferredResult; | 367 | var deferredResult; |
379 | varnewVersionKey; | 368 | varnewVersionKey; |
380 | var result; | 369 | var result; |
381 | 370 | ||
382 | newVersionKey = Clipperz.PM.Crypto.randomKey(); | 371 | newVersionKey = Clipperz.PM.Crypto.randomKey(); |
383 | result = {}; | 372 | result = {}; |
384 | 373 | ||
385 | deferredResult = new Clipperz.Async.Deferred("Record.prepareRemoteDataWithKey", {trace:false}); | 374 | deferredResult = new Clipperz.Async.Deferred("Record.prepareRemoteDataWithKey", {trace:false}); |
386 | deferredResult.addCallbackList([ | 375 | deferredResult.addCallbackList([ |
387 | Clipperz.Async.collectResults("Record.prepareRemoteDataWithKey - collect results", { | 376 | Clipperz.Async.collectResults("Record.prepareRemoteDataWithKey - collect results", { |
388 | 'isBrandNew': MochiKit.Base.method(this, 'isBrandNew'), | 377 | 'isBrandNew': MochiKit.Base.method(this, 'isBrandNew'), |
389 | 'versionHasPendingChanges':[ | 378 | 'versionHasPendingChanges':[ |
390 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 379 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
391 | // MochiKit.Base.methodcaller('hasPendingChanges') | 380 | // MochiKit.Base.methodcaller('hasPendingChanges') |
392 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'hasPendingChanges') | 381 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'hasPendingChanges') |
393 | ] | 382 | ] |
394 | }), | 383 | }), |
395 | Clipperz.Async.or, | 384 | Clipperz.Async.or, |
396 | 385 | ||
397 | Clipperz.Async.deferredIf("Current Version has pending changes", [ | 386 | Clipperz.Async.deferredIf("Current Version has pending changes", [ |
398 | MochiKit.Base.method(this, 'createNewRecordVersion'), | 387 | MochiKit.Base.method(this, 'createNewRecordVersion'), |
399 | MochiKit.Base.methodcaller('prepareRemoteDataWithKey', newVersionKey), | 388 | MochiKit.Base.methodcaller('prepareRemoteDataWithKey', newVersionKey), |
400 | MochiKit.Base.partial(Clipperz.Async.setItem, result, 'currentRecordVersion'), | 389 | MochiKit.Base.partial(Clipperz.Async.setItem, result, 'currentRecordVersion'), |
401 | MochiKit.Base.method(this, 'setCurrentRecordVersionKey', newVersionKey) | 390 | MochiKit.Base.method(this, 'setCurrentRecordVersionKey', newVersionKey) |
402 | ], []), | 391 | ], []), |
403 | 392 | ||
404 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.prepareRemoteDataWithKey, this, aKey), | 393 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.prepareRemoteDataWithKey, this, aKey), |
405 | MochiKit.Base.partial(Clipperz.Async.setItem, result, 'record'), | 394 | MochiKit.Base.partial(Clipperz.Async.setItem, result, 'record'), |
406 | 395 | ||
407 | MochiKit.Base.partial(MochiKit.Async.succeed, result) | 396 | MochiKit.Base.partial(MochiKit.Async.succeed, result) |
408 | ]); | 397 | ]); |
409 | 398 | ||
410 | deferredResult.callback(); | 399 | deferredResult.callback(); |
411 | 400 | ||
412 | return deferredResult; | 401 | return deferredResult; |
413 | }, | 402 | }, |
414 | 403 | ||
415 | //========================================================================= | 404 | //========================================================================= |
416 | 405 | ||
417 | 'fields': function () { | 406 | 'fields': function () { |
418 | return this.invokeCurrentRecordVersionMethod('fields'); | 407 | return this.invokeCurrentRecordVersionMethod('fields'); |
419 | }, | 408 | }, |
420 | 409 | ||
421 | 'addField': function (someParameters) { | 410 | 'addField': function (someParameters) { |
422 | return this.invokeCurrentRecordVersionMethod('addField', someParameters); | 411 | return this.invokeCurrentRecordVersionMethod('addField', someParameters); |
423 | }, | 412 | }, |
424 | 413 | ||
425 | 'removeField': function (someParameters) { | 414 | 'removeField': function (someParameters) { |
426 | return this.invokeCurrentRecordVersionMethod('removeField', someParameters); | 415 | return this.invokeCurrentRecordVersionMethod('removeField', someParameters); |
427 | }, | 416 | }, |
428 | 417 | ||
429 | //'sortFieldReference': function (someSortedFieldReferences) { | 418 | //'sortFieldReference': function (someSortedFieldReferences) { |
430 | // return this.invokeCurrentRecordVersionMethod('sortFieldReference', someSortedFieldReferences); | 419 | // return this.invokeCurrentRecordVersionMethod('sortFieldReference', someSortedFieldReferences); |
431 | //}, | 420 | //}, |
432 | 421 | ||
433 | 'getFieldsValues': function () { | 422 | 'getFieldsValues': function () { |
434 | return this.invokeCurrentRecordVersionMethod('getFieldsValues'); | 423 | return this.invokeCurrentRecordVersionMethod('getFieldsValues'); |
435 | }, | 424 | }, |
436 | 425 | ||
437 | 'fieldWithLabel': function (aLabel) { | 426 | 'fieldWithLabel': function (aLabel) { |
438 | return Clipperz.Async.callbacks("Record.fieldWithLabel", [ | 427 | return Clipperz.Async.callbacks("Record.fieldWithLabel", [ |
439 | MochiKit.Base.method(this, 'fields'), | 428 | MochiKit.Base.method(this, 'fields'), |
440 | MochiKit.Base.values, | 429 | MochiKit.Base.values, |
441 | MochiKit.Base.partial(Clipperz.Async.deferredFilter, function (aField) { | 430 | MochiKit.Base.partial(Clipperz.Async.deferredFilter, function (aField) { |
442 | return Clipperz.Async.callbacks("Record.fieldWithLabel - check field label", [ | 431 | return Clipperz.Async.callbacks("Record.fieldWithLabel - check field label", [ |
443 | MochiKit.Base.methodcaller('label'), | 432 | MochiKit.Base.methodcaller('label'), |
444 | MochiKit.Base.partial(MochiKit.Base.operator.eq, aLabel) | 433 | MochiKit.Base.partial(MochiKit.Base.operator.eq, aLabel) |
445 | ], {trace:false}, aField); | 434 | ], {trace:false}, aField); |
446 | }), | 435 | }), |
447 | function (someFilteredResults) { | 436 | function (someFilteredResults) { |
448 | var result; | 437 | var result; |
449 | 438 | ||
450 | switch (someFilteredResults.length) { | 439 | switch (someFilteredResults.length) { |
451 | case 0: | 440 | case 0: |
452 | result = null; | 441 | result = null; |
453 | break; | 442 | break; |
454 | case 1: | 443 | case 1: |
455 | result = someFilteredResults[0]; | 444 | result = someFilteredResults[0]; |
456 | break; | 445 | break; |
457 | default: | 446 | default: |
458 | WTF = TODO; | 447 | WTF = TODO; |
459 | break; | 448 | break; |
460 | } | 449 | } |
461 | 450 | ||
462 | return result; | 451 | return result; |
463 | } | 452 | } |
464 | ], {trace:false}); | 453 | ], {trace:false}); |
465 | }, | 454 | }, |
466 | 455 | ||
467 | //========================================================================= | 456 | //========================================================================= |
468 | 457 | ||
469 | 'getVersion': function (aVersionReference) { | 458 | 'getVersion': function (aVersionReference) { |
470 | return Clipperz.Async.callbacks("Record.getVersion", [ | 459 | return Clipperz.Async.callbacks("Record.getVersion", [ |
471 | MochiKit.Base.method(this, 'getVersions'), | 460 | MochiKit.Base.method(this, 'getVersions'), |
472 | MochiKit.Base.itemgetter(aVersionReference) | 461 | MochiKit.Base.itemgetter(aVersionReference) |
473 | ], {trace:false}); | 462 | ], {trace:false}); |
474 | }, | 463 | }, |
475 | 464 | ||
476 | //------------------------------------------------------------------------- | 465 | //------------------------------------------------------------------------- |
477 | 466 | ||
478 | 'getVersionKey': function (aVersionReference) { | 467 | 'getVersionKey': function (aVersionReference) { |
479 | vardeferredResult; | 468 | vardeferredResult; |
480 | var transientStateKey; | 469 | var transientStateKey; |
481 | 470 | ||
482 | transientStateKey = 'versionKeys' + '.' + aVersionReference; | 471 | transientStateKey = 'versionKeys' + '.' + aVersionReference; |
483 | if (this.transientState().getValue(transientStateKey) != null) { | 472 | if (this.transientState().getValue(transientStateKey) != null) { |
484 | deferredResult = MochiKit.Async.succeed(this.transientState().getValue(transientStateKey)); | 473 | deferredResult = MochiKit.Async.succeed(this.transientState().getValue(transientStateKey)); |
485 | } else { | 474 | } else { |
486 | deferredResult = Clipperz.Async.callbacks("Record.getVersionKey", [ | 475 | deferredResult = Clipperz.Async.callbacks("Record.getVersionKey", [ |
487 | MochiKit.Base.method(this, 'getVersions'), | 476 | MochiKit.Base.method(this, 'getVersions'), |
488 | MochiKit.Base.partial(MochiKit.Base.operator.eq, aVersionReference, this.currentVersionReference()), | 477 | MochiKit.Base.partial(MochiKit.Base.operator.eq, aVersionReference, this.currentVersionReference()), |
489 | Clipperz.Async.deferredIf("getVersionKey for current version", [ | 478 | Clipperz.Async.deferredIf("getVersionKey for current version", [ |
490 | MochiKit.Base.method(this, 'getCurrentRecordVersionKey'), | 479 | MochiKit.Base.method(this, 'getCurrentRecordVersionKey'), |
491 | MochiKit.Base.method(this.transientState(), 'setValue', transientStateKey) | 480 | MochiKit.Base.method(this.transientState(), 'setValue', transientStateKey) |
492 | ],[ | 481 | ],[ |
493 | MochiKit.Async.fail | 482 | MochiKit.Async.fail |
494 | ]) | 483 | ]) |
495 | ], {trace:false}); | 484 | ], {trace:false}); |
496 | } | 485 | } |
497 | 486 | ||
498 | return deferredResult; | 487 | return deferredResult; |
499 | }, | 488 | }, |
500 | 489 | ||
501 | //------------------------------------------------------------------------- | 490 | //------------------------------------------------------------------------- |
502 | 491 | ||
503 | 'versions': function () { | 492 | 'versions': function () { |
504 | return this._versions; | 493 | return this._versions; |
505 | }, | 494 | }, |
506 | 495 | ||
507 | 'getVersions': function () { | 496 | 'getVersions': function () { |
508 | return Clipperz.Async.callbacks("Record.versions", [ | 497 | return Clipperz.Async.callbacks("Record.versions", [ |
509 | MochiKit.Base.method(this, 'getValue', 'fakeKey, just to trigger unpackRemoteData'), | 498 | MochiKit.Base.method(this, 'getValue', 'fakeKey, just to trigger unpackRemoteData'), |
510 | MochiKit.Base.bind(function () { return this._versions; }, this) | 499 | MochiKit.Base.bind(function () { return this._versions; }, this) |
511 | ], {trace:false}); | 500 | ], {trace:false}); |
512 | }, | 501 | }, |
513 | 502 | ||
514 | //------------------------------------------------------------------------- | 503 | //------------------------------------------------------------------------- |
515 | 504 | ||
516 | 'getCurrentRecordVersion': function () { | 505 | 'getCurrentRecordVersion': function () { |
517 | return Clipperz.Async.callbacks("Record.getCurrentRecordVersion", [ | 506 | return Clipperz.Async.callbacks("Record.getCurrentRecordVersion", [ |
518 | // MochiKit.Base.method(this, 'getValue', 'fakeKey, just to trigger unpackRemoteData'), | 507 | // MochiKit.Base.method(this, 'getValue', 'fakeKey, just to trigger unpackRemoteData'), |
519 | // MochiKit.Base.bind(function () { return this._currentRecordVersion; }, this) | 508 | // MochiKit.Base.bind(function () { return this._currentRecordVersion; }, this) |
520 | 509 | ||
521 | MochiKit.Base.method(this, 'versions'), | 510 | MochiKit.Base.method(this, 'versions'), |
522 | MochiKit.Base.itemgetter(this.currentVersionReference()), | 511 | MochiKit.Base.itemgetter(this.currentVersionReference()), |
523 | Clipperz.Async.deferredIf("The current version is available", [ | 512 | Clipperz.Async.deferredIf("The current version is available", [ |
524 | MochiKit.Async.succeed | 513 | MochiKit.Async.succeed |
525 | ], [ | 514 | ], [ |
526 | MochiKit.Base.method(this, 'getVersions'), | 515 | MochiKit.Base.method(this, 'getVersions'), |
527 | MochiKit.Base.bind(function (someVersions) { return someVersions[this.currentVersionReference()]}, this) | 516 | MochiKit.Base.bind(function (someVersions) { return someVersions[this.currentVersionReference()]}, this) |
528 | ]) | 517 | ]) |
529 | ], {trace:false}); | 518 | ], {trace:false}); |
530 | }, | 519 | }, |
531 | 520 | ||
532 | 'setCurrentRecordVersion': function (aRecordVersion) { | 521 | 'setCurrentRecordVersion': function (aRecordVersion) { |
533 | this._currentVersionReference = aRecordVersion.reference(); | 522 | this._currentVersionReference = aRecordVersion.reference(); |
534 | }, | 523 | }, |
535 | 524 | ||
536 | //......................................................................... | 525 | //......................................................................... |
537 | 526 | ||
538 | 'currentVersionReference': function () { | 527 | 'currentVersionReference': function () { |
539 | //console.log("currentVersionReference"); | ||
540 | return this._currentVersionReference; | 528 | return this._currentVersionReference; |
541 | }, | 529 | }, |
542 | 530 | ||
543 | //------------------------------------------------------------------------- | 531 | //------------------------------------------------------------------------- |
544 | 532 | ||
545 | 'createNewRecordVersion': function () { | 533 | 'createNewRecordVersion': function () { |
546 | var deferredResult; | 534 | var deferredResult; |
547 | 535 | ||
548 | if (this.isBrandNew()) { | 536 | if (this.isBrandNew()) { |
549 | deferredResult = this.getCurrentRecordVersion(); | 537 | deferredResult = this.getCurrentRecordVersion(); |
550 | } else { | 538 | } else { |
551 | var newVersion; | 539 | var newVersion; |
552 | 540 | ||
553 | newVersion = new Clipperz.PM.DataModel.Record.Version({ | 541 | newVersion = new Clipperz.PM.DataModel.Record.Version({ |
554 | // 'reference': versionKey, | 542 | // 'reference': versionKey, |
555 | 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'), | 543 | 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'), |
556 | // 'remoteData': {}, | 544 | // 'remoteData': {}, |
557 | 'getVersion': MochiKit.Base.method(this, 'getVersion') | 545 | 'getVersion': MochiKit.Base.method(this, 'getVersion') |
558 | }) | 546 | }) |
559 | this._versions[newVersion.reference()] = newVersion; | 547 | this._versions[newVersion.reference()] = newVersion; |
560 | 548 | ||
561 | deferredResult = Clipperz.Async.callbacks("Record.createNewRecordVersion", [ | 549 | deferredResult = Clipperz.Async.callbacks("Record.createNewRecordVersion", [ |
562 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 550 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
563 | // MochiKit.Base.methodcaller('values'), | 551 | // MochiKit.Base.methodcaller('values'), |
564 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'values'), | 552 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'values'), |
565 | MochiKit.Base.method(newVersion, 'setValues'), | 553 | MochiKit.Base.method(newVersion, 'setValues'), |
566 | 554 | ||
567 | Clipperz.Async.collectResults("Record.createNewRecordVersion [collect results]", { | 555 | Clipperz.Async.collectResults("Record.createNewRecordVersion [collect results]", { |
568 | 'reference':MochiKit.Base.method(this, 'currentVersionReference'), | 556 | 'reference':MochiKit.Base.method(this, 'currentVersionReference'), |
569 | 'key': MochiKit.Base.method(this, 'getCurrentRecordVersionKey') | 557 | 'key': MochiKit.Base.method(this, 'getCurrentRecordVersionKey') |
570 | }, {trace:false}), | 558 | }, {trace:false}), |
571 | MochiKit.Base.method(newVersion, 'setPreviousVersionReferenceAndKey'), | 559 | MochiKit.Base.method(newVersion, 'setPreviousVersionReferenceAndKey'), |
572 | 560 | ||
573 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 561 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
574 | // MochiKit.Base.method(this, 'revertChanges'), | 562 | // MochiKit.Base.method(this, 'revertChanges'), |
575 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'revertChanges'), | 563 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'revertChanges'), |
576 | 564 | ||
577 | MochiKit.Base.method(this, 'setCurrentRecordVersion', newVersion), | 565 | MochiKit.Base.method(this, 'setCurrentRecordVersion', newVersion), |
578 | MochiKit.Base.partial(MochiKit.Async.succeed, newVersion) | 566 | MochiKit.Base.partial(MochiKit.Async.succeed, newVersion) |
579 | ], {trace:false}); | 567 | ], {trace:false}); |
580 | } | 568 | } |
581 | 569 | ||
582 | return deferredResult; | 570 | return deferredResult; |
583 | }, | 571 | }, |
584 | 572 | ||
585 | //------------------------------------------------------------------------- | 573 | //------------------------------------------------------------------------- |
586 | 574 | ||
587 | 'getCurrentRecordVersionKey': function () { | 575 | 'getCurrentRecordVersionKey': function () { |
588 | //console.log("getCurrentRecordVersionKey"); | ||
589 | return Clipperz.Async.callbacks("Record.getCurrentRecordVersionKey", [ | 576 | return Clipperz.Async.callbacks("Record.getCurrentRecordVersionKey", [ |
590 | MochiKit.Base.method(this, 'getValue', 'currentVersionKey'), | 577 | MochiKit.Base.method(this, 'getValue', 'currentVersionKey'), |
591 | Clipperz.Async.deferredIf("currentVersionKey is NOT null", [ | 578 | Clipperz.Async.deferredIf("currentVersionKey is NOT null", [ |
592 | MochiKit.Async.succeed | 579 | MochiKit.Async.succeed |
593 | ], [ | 580 | ], [ |
594 | MochiKit.Base.method(this, 'getKey') | 581 | MochiKit.Base.method(this, 'getKey') |
595 | ]) | 582 | ]) |
596 | ], {trace:false}); | 583 | ], {trace:false}); |
597 | }, | 584 | }, |
598 | 585 | ||
599 | 'setCurrentRecordVersionKey': function (aValue) { | 586 | 'setCurrentRecordVersionKey': function (aValue) { |
600 | //TODO: triple check this method! | 587 | //TODO: triple check this method! |
601 | return Clipperz.Async.callbacks("Record.setCurrentRecordVersionKey", [ | 588 | return Clipperz.Async.callbacks("Record.setCurrentRecordVersionKey", [ |
602 | MochiKit.Base.method(this, 'setValue', 'currentVersionKey', aValue) | 589 | MochiKit.Base.method(this, 'setValue', 'currentVersionKey', aValue) |
603 | ], {trace:false}); | 590 | ], {trace:false}); |
604 | }, | 591 | }, |
605 | 592 | ||
606 | //------------------------------------------------------------------------- | 593 | //------------------------------------------------------------------------- |
607 | 594 | ||
608 | 'invokeCurrentRecordVersionMethod': function (aMethodName, someValues) { | 595 | 'invokeCurrentRecordVersionMethod': function (aMethodName, someValues) { |
609 | //console.log(">>> invokeCurrentRecordVersionMethod", aMethodName); | ||
610 | return Clipperz.Async.callbacks("Record.invokeCurrentRecordVersionMethod", [ | 596 | return Clipperz.Async.callbacks("Record.invokeCurrentRecordVersionMethod", [ |
611 | MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 597 | MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
612 | //function (aValue) { console.log("=== getCurrentRecordVersion", aValue); return aValue}, | ||
613 | MochiKit.Base.methodcaller(aMethodName, someValues) | 598 | MochiKit.Base.methodcaller(aMethodName, someValues) |
614 | ], {trace:false}); | 599 | ], {trace:false}); |
615 | }, | 600 | }, |
616 | 601 | ||
617 | 602 | ||
618 | 'lazilyinvokeCurrentRecordVersionMethod': function (aMethodName, someValues, defaultResult) { | 603 | 'lazilyinvokeCurrentRecordVersionMethod': function (aMethodName, someValues, defaultResult) { |
619 | return Clipperz.Async.callbacks("Record.lazilyinvokeCurrentRecordVersionMethod", [ | 604 | return Clipperz.Async.callbacks("Record.lazilyinvokeCurrentRecordVersionMethod", [ |
620 | MochiKit.Base.method(this, 'currentVersionReference'), | 605 | MochiKit.Base.method(this, 'currentVersionReference'), |
621 | //function (aValue) { console.log("LAZY -> versions", aValue); return aValue; }, | ||
622 | Clipperz.Async.deferredIf("versions has been loaded", [ | 606 | Clipperz.Async.deferredIf("versions has been loaded", [ |
623 | //function (aValue) { console.log("LAZY -> then"); return aValue; }, | ||
624 | MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 607 | MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
625 | MochiKit.Base.methodcaller(aMethodName, someValues), | 608 | MochiKit.Base.methodcaller(aMethodName, someValues), |
626 | //function (aValue) { console.log("LAZY <- then"); return aValue; } | ||
627 | ], [ | 609 | ], [ |
628 | //function (aValue) { console.log("LAZY -> else"); return aValue; }, | ||
629 | MochiKit.Base.partial(MochiKit.Async.succeed, defaultResult), | 610 | MochiKit.Base.partial(MochiKit.Async.succeed, defaultResult), |
630 | //function (aValue) { console.log("LAZY <- else"); return aValue; } | ||
631 | ]) | 611 | ]) |
632 | ], {trace:false}); | 612 | ], {trace:false}); |
633 | }, | 613 | }, |
634 | 614 | ||
635 | //========================================================================= | 615 | //========================================================================= |
636 | 616 | ||
637 | 'hasPendingChanges': function () { | 617 | 'hasPendingChanges': function () { |
638 | var deferredResult; | 618 | var deferredResult; |
639 | 619 | ||
640 | if (this.hasInitiatedObjectDataStore()) { | 620 | if (this.hasInitiatedObjectDataStore()) { |
641 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.hasPendingChanges", {trace:false}); | 621 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.hasPendingChanges", {trace:false}); |
642 | deferredResult.collectResults({ | 622 | deferredResult.collectResults({ |
643 | 'super': MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.hasPendingChanges, this), | 623 | 'super': MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.hasPendingChanges, this), |
644 | 'currentVersion': [ | 624 | 'currentVersion': [ |
645 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 625 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
646 | // MochiKit.Base.methodcaller('hasPendingChanges') | 626 | // MochiKit.Base.methodcaller('hasPendingChanges') |
647 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'hasPendingChanges') | 627 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'hasPendingChanges') |
648 | ], | 628 | ], |
649 | 'directLogins': [ | 629 | 'directLogins': [ |
650 | MochiKit.Base.method(this, 'directLogins'), | 630 | MochiKit.Base.method(this, 'directLogins'), |
651 | //function (aValue) { console.log("Record.directLogins", aValue); return aValue; }, | ||
652 | MochiKit.Base.values, | 631 | MochiKit.Base.values, |
653 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasPendingChanges')), | 632 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasPendingChanges')), |
654 | Clipperz.Async.collectAll, | 633 | Clipperz.Async.collectAll, |
655 | Clipperz.Async.or | 634 | Clipperz.Async.or |
656 | // function(someValues) { | 635 | // function(someValues) { |
657 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); | 636 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); |
658 | // } | 637 | // } |
659 | ] | 638 | ] |
660 | }); | 639 | }); |
661 | //deferredResult.addCallback(function (aValue) { console.log("Record.hasPendingResults", aValue); return aValue; }); | ||
662 | deferredResult.addCallback(MochiKit.Base.values); | 640 | deferredResult.addCallback(MochiKit.Base.values); |
663 | deferredResult.addCallback(MochiKit.Base.bind(function(someValues) { | 641 | deferredResult.addCallback(MochiKit.Base.bind(function(someValues) { |
664 | var result; | 642 | var result; |
665 | result = MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); | 643 | result = MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); |
666 | 644 | ||
667 | if ((result == false) && (this.isBrandNew() == false)) { | 645 | if ((result == false) && (this.isBrandNew() == false)) { |
668 | result = MochiKit.Iter.some(MochiKit.Base.values(this.transientState().getValue('hasPendingChanges.indexData')), MochiKit.Base.operator.identity); | 646 | result = MochiKit.Iter.some(MochiKit.Base.values(this.transientState().getValue('hasPendingChanges.indexData')), MochiKit.Base.operator.identity); |
669 | } | 647 | } |
670 | 648 | ||
671 | return result; | 649 | return result; |
672 | }, this)); | 650 | }, this)); |
673 | 651 | ||
674 | deferredResult.callback(); | 652 | deferredResult.callback(); |
675 | } else { | 653 | } else { |
676 | deferredResult = Clipperz.Async.callbacks("Recrod.hasPendingChanges [hasInitiatedObjectDataStore == false]", [ | 654 | deferredResult = Clipperz.Async.callbacks("Recrod.hasPendingChanges [hasInitiatedObjectDataStore == false]", [ |
677 | MochiKit.Base.method(this, 'directLogins'), | 655 | MochiKit.Base.method(this, 'directLogins'), |
678 | MochiKit.Base.values, | 656 | MochiKit.Base.values, |
679 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasPendingChanges')), | 657 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasPendingChanges')), |
680 | Clipperz.Async.collectAll, | 658 | Clipperz.Async.collectAll, |
681 | Clipperz.Async.or | 659 | Clipperz.Async.or |
682 | // function(someValues) { | 660 | // function(someValues) { |
683 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); | 661 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); |
684 | // } | 662 | // } |
685 | ], {trace:false}) | 663 | ], {trace:false}) |
686 | } | 664 | } |
687 | 665 | ||
688 | return deferredResult; | 666 | return deferredResult; |
689 | }, | 667 | }, |
690 | 668 | ||
691 | //------------------------------------------------------------------------- | 669 | //------------------------------------------------------------------------- |
692 | 670 | ||
693 | 'hasPendingChangesWhenBrandNew': function () { | 671 | 'hasPendingChangesWhenBrandNew': function () { |
694 | var deferredResult; | 672 | var deferredResult; |
695 | 673 | ||
696 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.hasPendingChangesWhenBrandNew", {trace:false}); | 674 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.hasPendingChangesWhenBrandNew", {trace:false}); |
697 | deferredResult.collectResults({ | 675 | deferredResult.collectResults({ |
698 | 'label': [ | 676 | 'label': [ |
699 | MochiKit.Base.method(this, 'label'), | 677 | MochiKit.Base.method(this, 'label'), |
700 | MochiKit.Base.partial(MochiKit.Base.operator.ne, '') | 678 | MochiKit.Base.partial(MochiKit.Base.operator.ne, '') |
701 | ], | 679 | ], |
702 | 'notes': [ | 680 | 'notes': [ |
703 | MochiKit.Base.method(this, 'notes'), | 681 | MochiKit.Base.method(this, 'notes'), |
704 | MochiKit.Base.partial(MochiKit.Base.operator.ne, '') | 682 | MochiKit.Base.partial(MochiKit.Base.operator.ne, '') |
705 | ] | 683 | ] |
706 | }); | 684 | }); |
707 | // deferredResult.addCallback(MochiKit.Base.values); | 685 | // deferredResult.addCallback(MochiKit.Base.values); |
708 | // deferredResult.addCallback(function(someValues) { | 686 | // deferredResult.addCallback(function(someValues) { |
709 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); | 687 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); |
710 | // }); | 688 | // }); |
711 | deferredResult.addCallback(Clipperz.Async.or); | 689 | deferredResult.addCallback(Clipperz.Async.or); |
712 | 690 | ||
713 | deferredResult.callback(); | 691 | deferredResult.callback(); |
714 | 692 | ||
715 | return deferredResult; | 693 | return deferredResult; |
716 | }, | 694 | }, |
717 | 695 | ||
718 | //------------------------------------------------------------------------- | 696 | //------------------------------------------------------------------------- |
719 | 697 | ||
720 | 'isBrandNewWithNoPendingChanges': function () { | 698 | 'isBrandNewWithNoPendingChanges': function () { |
721 | vardeferredResult; | 699 | vardeferredResult; |
722 | 700 | ||
723 | if (this.isBrandNew() == false) { | 701 | if (this.isBrandNew() == false) { |
724 | deferredResult = MochiKit.Async.succeed(false); | 702 | deferredResult = MochiKit.Async.succeed(false); |
725 | } else { | 703 | } else { |
726 | deferredResult = Clipperz.Async.callbacks("Record.isBrandNewWithNoPendingChanges", [ | 704 | deferredResult = Clipperz.Async.callbacks("Record.isBrandNewWithNoPendingChanges", [ |
727 | MochiKit.Base.method(this, 'hasPendingChanges'), | 705 | MochiKit.Base.method(this, 'hasPendingChanges'), |
728 | MochiKit.Base.operator.lognot | 706 | MochiKit.Base.operator.lognot |
729 | ], {trace:false}); | 707 | ], {trace:false}); |
730 | } | 708 | } |
731 | 709 | ||
732 | return deferredResult; | 710 | return deferredResult; |
733 | }, | 711 | }, |
734 | 712 | ||
735 | //========================================================================= | 713 | //========================================================================= |
736 | 714 | ||
737 | 'revertChanges': function () { | 715 | 'revertChanges': function () { |
738 | var deferredResult; | 716 | var deferredResult; |
739 | 717 | ||
740 | if (this.isBrandNew() == false) { | 718 | if (this.isBrandNew() == false) { |
741 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.revertChanges", {trace:false}); | 719 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.revertChanges", {trace:false}); |
742 | deferredResult.addMethod(this, 'hasPendingChanges'); | 720 | deferredResult.addMethod(this, 'hasPendingChanges'); |
743 | deferredResult.addIf([ | 721 | deferredResult.addIf([ |
744 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 722 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
745 | // MochiKit.Base.methodcaller('revertChanges'), | 723 | // MochiKit.Base.methodcaller('revertChanges'), |
746 | MochiKit.Base.method(this,'invokeCurrentRecordVersionMethod', 'revertChanges'), | 724 | MochiKit.Base.method(this,'invokeCurrentRecordVersionMethod', 'revertChanges'), |
747 | 725 | ||
748 | MochiKit.Base.method(this, 'directLogins'), | 726 | MochiKit.Base.method(this, 'directLogins'), |
749 | MochiKit.Base.values, | 727 | MochiKit.Base.values, |
750 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('revertChanges')), | 728 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('revertChanges')), |
751 | 729 | ||
752 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.revertChanges, this) | 730 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.revertChanges, this) |
753 | ], [ | 731 | ], [ |
754 | MochiKit.Async.succeed | 732 | MochiKit.Async.succeed |
755 | ]); | 733 | ]); |
756 | deferredResult.callback(); | 734 | deferredResult.callback(); |
757 | } else { | 735 | } else { |
758 | // this.deleteAllCleanTextData(); | 736 | // this.deleteAllCleanTextData(); |
759 | deferredResult = MochiKit.Async.succeed(); | 737 | deferredResult = MochiKit.Async.succeed(); |
760 | } | 738 | } |
761 | 739 | ||
762 | return deferredResult; | 740 | return deferredResult; |
763 | }, | 741 | }, |
764 | 742 | ||
765 | //------------------------------------------------------------------------- | 743 | //------------------------------------------------------------------------- |
766 | 744 | ||
767 | 'resetTransientState': function (isCommitting) { | 745 | 'resetTransientState': function (isCommitting) { |
768 | // if ((isCommitting == false) && (this.transientState().getValue('directLogins') != null)) { | 746 | // if ((isCommitting == false) && (this.transientState().getValue('directLogins') != null)) { |
769 | // this._directLogins = this.transientState().getValue('directLogins'); | 747 | // this._directLogins = this.transientState().getValue('directLogins'); |
770 | // } | 748 | // } |
771 | 749 | ||
772 | return Clipperz.Async.callbacks("Record.resetTransientState", [ | 750 | return Clipperz.Async.callbacks("Record.resetTransientState", [ |
773 | //- MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 751 | //- MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
774 | //- MochiKit.Base.methodcaller('resetTransientState'), | 752 | //- MochiKit.Base.methodcaller('resetTransientState'), |
775 | // MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'resetTransientState'), | 753 | // MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'resetTransientState'), |
776 | MochiKit.Base.method(this, 'lazilyinvokeCurrentRecordVersionMethod', 'resetTransientState'), | 754 | MochiKit.Base.method(this, 'lazilyinvokeCurrentRecordVersionMethod', 'resetTransientState'), |
777 | 755 | ||
778 | MochiKit.Base.method(this, 'directLogins'), | 756 | MochiKit.Base.method(this, 'directLogins'), |
779 | //function (aValue) { console.log("resetTransientState - directLogins", aValue); return aValue; }, | ||
780 | MochiKit.Base.values, | 757 | MochiKit.Base.values, |
781 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('resetTransientState')), | 758 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('resetTransientState')), |
782 | 759 | ||
783 | MochiKit.Base.bind(function () { | 760 | MochiKit.Base.bind(function () { |
784 | if ((isCommitting == false) && (this.transientState().getValue('directLogins') != null)) { | 761 | if ((isCommitting == false) && (this.transientState().getValue('directLogins') != null)) { |
785 | this._directLogins = this.transientState().getValue('directLogins'); | 762 | this._directLogins = this.transientState().getValue('directLogins'); |
786 | } | 763 | } |
787 | }, this), | 764 | }, this), |
788 | 765 | ||
789 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.resetTransientState, this, isCommitting) | 766 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.resetTransientState, this, isCommitting) |
790 | ], {trace:false}) | 767 | ], {trace:false}) |
791 | }, | 768 | }, |
792 | 769 | ||
793 | //------------------------------------------------------------------------- | 770 | //------------------------------------------------------------------------- |
794 | 771 | ||
795 | 'commitTransientState': function () { | 772 | 'commitTransientState': function () { |
796 | var deferredResult; | 773 | var deferredResult; |
797 | 774 | ||
798 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.commitTransientState", {trace:false}); | 775 | deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.commitTransientState", {trace:false}); |
799 | deferredResult.addMethod(this, 'hasPendingChanges'); | 776 | deferredResult.addMethod(this, 'hasPendingChanges'); |
800 | deferredResult.addIf([ | 777 | deferredResult.addIf([ |
801 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.commitTransientState, this), | 778 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.commitTransientState, this), |
802 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), | 779 | // MochiKit.Base.method(this, 'getCurrentRecordVersion'), |
803 | // MochiKit.Base.methodcaller('commitTransientState'), | 780 | // MochiKit.Base.methodcaller('commitTransientState'), |
804 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'commitTransientState'), | 781 | MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'commitTransientState'), |
805 | MochiKit.Base.method(this, 'directLogins'), | 782 | MochiKit.Base.method(this, 'directLogins'), |
806 | MochiKit.Base.values, | 783 | MochiKit.Base.values, |
807 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('commitTransientState')) | 784 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('commitTransientState')) |
808 | ], [ | 785 | ], [ |
809 | MochiKit.Async.succeed | 786 | MochiKit.Async.succeed |
810 | ]); | 787 | ]); |
811 | deferredResult.callback(); | 788 | deferredResult.callback(); |
812 | 789 | ||
813 | return deferredResult; | 790 | return deferredResult; |
814 | }, | 791 | }, |
815 | 792 | ||
816 | //========================================================================= | 793 | //========================================================================= |
817 | 794 | ||
818 | 'retrieveDirectLoginIndexDataFunction': function () { | 795 | 'retrieveDirectLoginIndexDataFunction': function () { |
819 | //console.log("Record.retrieveDirectLoginIndexDataFunction", this._retrieveDirectLoginIndexDataFunction); | ||
820 | return this._retrieveDirectLoginIndexDataFunction; | 796 | return this._retrieveDirectLoginIndexDataFunction; |
821 | }, | 797 | }, |
822 | 798 | ||
823 | 'setDirectLoginIndexDataFunction': function () { | 799 | 'setDirectLoginIndexDataFunction': function () { |
824 | return this._setDirectLoginIndexDataFunction; | 800 | return this._setDirectLoginIndexDataFunction; |
825 | }, | 801 | }, |
826 | 802 | ||
827 | 'removeDirectLoginIndexDataFunction': function () { | 803 | 'removeDirectLoginIndexDataFunction': function () { |
828 | return this._removeDirectLoginIndexDataFunction; | 804 | return this._removeDirectLoginIndexDataFunction; |
829 | }, | 805 | }, |
830 | 806 | ||
831 | //========================================================================= | 807 | //========================================================================= |
832 | 808 | ||
833 | 'deleteAllCleanTextData': function () { | 809 | 'deleteAllCleanTextData': function () { |
834 | // return Clipperz.PM.DataModel.Record.superclass.deleteAllCleanTextData.apply(this, arguments); | 810 | // return Clipperz.PM.DataModel.Record.superclass.deleteAllCleanTextData.apply(this, arguments); |
835 | 811 | ||
836 | return Clipperz.Async.callbacks("Record.deleteAllCleanTextData", [ | 812 | return Clipperz.Async.callbacks("Record.deleteAllCleanTextData", [ |
837 | MochiKit.Base.method(this, 'versions'), | 813 | MochiKit.Base.method(this, 'versions'), |
838 | MochiKit.Base.values, | 814 | MochiKit.Base.values, |
839 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), | 815 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), |
840 | 816 | ||
841 | MochiKit.Base.method(this, 'directLogins'), | 817 | MochiKit.Base.method(this, 'directLogins'), |
842 | MochiKit.Base.values, | 818 | MochiKit.Base.values, |
843 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), | 819 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), |
844 | 820 | ||
845 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.deleteAllCleanTextData, this) | 821 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.deleteAllCleanTextData, this) |
846 | ], {trace:false}); | 822 | ], {trace:false}); |
847 | }, | 823 | }, |
848 | 824 | ||
849 | 'hasAnyCleanTextData': function () { | 825 | 'hasAnyCleanTextData': function () { |
850 | // return Clipperz.PM.DataModel.Record.superclass.hasAnyCleanTextData.apply(this, arguments); | 826 | // return Clipperz.PM.DataModel.Record.superclass.hasAnyCleanTextData.apply(this, arguments); |
851 | 827 | ||
852 | return Clipperz.Async.callbacks("Record.hasAnyCleanTextData", [ | 828 | return Clipperz.Async.callbacks("Record.hasAnyCleanTextData", [ |
853 | Clipperz.Async.collectResults("Record.hasAnyCleanTextData [collect results]", { | 829 | Clipperz.Async.collectResults("Record.hasAnyCleanTextData [collect results]", { |
854 | 'versions':[ | 830 | 'versions':[ |
855 | MochiKit.Base.method(this, 'versions'), | 831 | MochiKit.Base.method(this, 'versions'), |
856 | MochiKit.Base.values, | 832 | MochiKit.Base.values, |
857 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')), | 833 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')), |
858 | Clipperz.Async.collectAll | 834 | Clipperz.Async.collectAll |
859 | ], | 835 | ], |
860 | 'directLogins': [ | 836 | 'directLogins': [ |
861 | MochiKit.Base.method(this, 'directLogins'), | 837 | MochiKit.Base.method(this, 'directLogins'), |
862 | MochiKit.Base.values, | 838 | MochiKit.Base.values, |
863 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')), | 839 | MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')), |
864 | Clipperz.Async.collectAll | 840 | Clipperz.Async.collectAll |
865 | ], | 841 | ], |
866 | 'super': [ | 842 | 'super': [ |
867 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.hasAnyCleanTextData, this) | 843 | MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.hasAnyCleanTextData, this) |
868 | ] | 844 | ] |
869 | }, {trace:false}), | 845 | }, {trace:false}), |
870 | Clipperz.Async.or | 846 | Clipperz.Async.or |
871 | ]) | 847 | ]) |
872 | }, | 848 | }, |
873 | 849 | ||
874 | //========================================================================= | 850 | //========================================================================= |
875 | __syntaxFix__: "syntax fix" | 851 | __syntaxFix__: "syntax fix" |
876 | }); | 852 | }); |
877 | 853 | ||
878 | 854 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Legacy.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Legacy.js index d6202ff..cda5a41 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Legacy.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Legacy.js | |||
@@ -1,118 +1,116 @@ | |||
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 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.DataModel.User.Header.Legacy depends on Clipperz.PM.DataModel.User!"; | 25 | throw "Clipperz.PM.DataModel.User.Header.Legacy depends on Clipperz.PM.DataModel.User!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } | 28 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } |
31 | 29 | ||
32 | Clipperz.PM.DataModel.User.Header.Legacy = function(args) { | 30 | Clipperz.PM.DataModel.User.Header.Legacy = function(args) { |
33 | //args = args || {}; | 31 | //args = args || {}; |
34 | Clipperz.PM.DataModel.User.Header.Legacy.superclass.constructor.apply(this, arguments); | 32 | Clipperz.PM.DataModel.User.Header.Legacy.superclass.constructor.apply(this, arguments); |
35 | 33 | ||
36 | this._retrieveRecordDetailFunction = args.retrieveRecordDetailFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); | 34 | this._retrieveRecordDetailFunction = args.retrieveRecordDetailFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); |
37 | this._records = null; | 35 | this._records = null; |
38 | //this._directLogins = null; | 36 | //this._directLogins = null; |
39 | 37 | ||
40 | return this; | 38 | return this; |
41 | } | 39 | } |
42 | 40 | ||
43 | 41 | ||
44 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.Legacy, Clipperz.PM.DataModel.EncryptedRemoteObject, { | 42 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.Legacy, Clipperz.PM.DataModel.EncryptedRemoteObject, { |
45 | 43 | ||
46 | 'toString': function() { | 44 | 'toString': function() { |
47 | return "Clipperz.PM.DataModel.User.Header.Legacy"; | 45 | return "Clipperz.PM.DataModel.User.Header.Legacy"; |
48 | }, | 46 | }, |
49 | 47 | ||
50 | //------------------------------------------------------------------------- | 48 | //------------------------------------------------------------------------- |
51 | 49 | ||
52 | 'retrieveRecordDetailFunction': function () { | 50 | 'retrieveRecordDetailFunction': function () { |
53 | return this._retrieveRecordDetailFunction; | 51 | return this._retrieveRecordDetailFunction; |
54 | }, | 52 | }, |
55 | 53 | ||
56 | //------------------------------------------------------------------------- | 54 | //------------------------------------------------------------------------- |
57 | 55 | ||
58 | 'getRecordKey': function (aRecordReference) { | 56 | 'getRecordKey': function (aRecordReference) { |
59 | var deferredResult; | 57 | var deferredResult; |
60 | 58 | ||
61 | deferredResult = new Clipperz.Async.Deferred("User.Header.Legacy.getRecordKey", {trace:false}); | 59 | deferredResult = new Clipperz.Async.Deferred("User.Header.Legacy.getRecordKey", {trace:false}); |
62 | deferredResult.addMethod(this, 'getRecordIndexData'); | 60 | deferredResult.addMethod(this, 'getRecordIndexData'); |
63 | deferredResult.addCallback(MochiKit.Base.itemgetter('key')) | 61 | deferredResult.addCallback(MochiKit.Base.itemgetter('key')) |
64 | deferredResult.callback(); | 62 | deferredResult.callback(); |
65 | 63 | ||
66 | return deferredResult; | 64 | return deferredResult; |
67 | }, | 65 | }, |
68 | 66 | ||
69 | //========================================================================= | 67 | //========================================================================= |
70 | 68 | ||
71 | 'getRecordIndexData': function (aRecordReference) { | 69 | 'getRecordIndexData': function (aRecordReference) { |
72 | return this.getValue('records.' + aRecordReference); | 70 | return this.getValue('records.' + aRecordReference); |
73 | }, | 71 | }, |
74 | 72 | ||
75 | 'updateRecordIndexData': function (aRecordReference, aKey, aValue) { | 73 | 'updateRecordIndexData': function (aRecordReference, aKey, aValue) { |
76 | return this.setValue('records.' + aRecordReference + "." + aKey, aValue); | 74 | return this.setValue('records.' + aRecordReference + "." + aKey, aValue); |
77 | }, | 75 | }, |
78 | 76 | ||
79 | //------------------------------------------------------------------------- | 77 | //------------------------------------------------------------------------- |
80 | 78 | ||
81 | 'getDirectLoginIndexData': function (aDirectLoginReference) { | 79 | 'getDirectLoginIndexData': function (aDirectLoginReference) { |
82 | return this.getValue('directLogins.' + aDirectLoginReference); | 80 | return this.getValue('directLogins.' + aDirectLoginReference); |
83 | }, | 81 | }, |
84 | 82 | ||
85 | 'setDirectLoginIndexData': function (aDirectLoginReference, aKey, aValue) { | 83 | 'setDirectLoginIndexData': function (aDirectLoginReference, aKey, aValue) { |
86 | return this.setValue('directLogins.' + aDirectLoginReference + '.' + aKey, aValue); | 84 | return this.setValue('directLogins.' + aDirectLoginReference + '.' + aKey, aValue); |
87 | }, | 85 | }, |
88 | 86 | ||
89 | 'removeDirectLoginIndexData': function (aDirectLoginReference) { | 87 | 'removeDirectLoginIndexData': function (aDirectLoginReference) { |
90 | return this.removeValue('directLogins.' + aDirectLoginReference); | 88 | return this.removeValue('directLogins.' + aDirectLoginReference); |
91 | }, | 89 | }, |
92 | 90 | ||
93 | //========================================================================= | 91 | //========================================================================= |
94 | 92 | ||
95 | 'records': function () { | 93 | 'records': function () { |
96 | vardeferredResult; | 94 | vardeferredResult; |
97 | var deferredLock; | 95 | var deferredLock; |
98 | 96 | ||
99 | deferredLock = this.getDeferredLockForKey('records'); | 97 | deferredLock = this.getDeferredLockForKey('records'); |
100 | 98 | ||
101 | deferredResult = new Clipperz.Async.Deferred("User.Header.Legacy.records", {trace:false}); | 99 | deferredResult = new Clipperz.Async.Deferred("User.Header.Legacy.records", {trace:false}); |
102 | deferredResult.acquireLock(deferredLock); | 100 | deferredResult.acquireLock(deferredLock); |
103 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 101 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
104 | var innerDeferredResult; | 102 | var innerDeferredResult; |
105 | 103 | ||
106 | if (this._records == null) { | 104 | if (this._records == null) { |
107 | innerDeferredResult = new Clipperz.Async.Deferred("User.Header.Legacy.records <inner deferred>", {trace:false}); | 105 | innerDeferredResult = new Clipperz.Async.Deferred("User.Header.Legacy.records <inner deferred>", {trace:false}); |
108 | innerDeferredResult.collectResults({ | 106 | innerDeferredResult.collectResults({ |
109 | 'header': [ | 107 | 'header': [ |
110 | // MochiKit.Base.method(this, 'getObjectDataStore'), | 108 | // MochiKit.Base.method(this, 'getObjectDataStore'), |
111 | // MochiKit.Base.methodcaller('values') | 109 | // MochiKit.Base.methodcaller('values') |
112 | MochiKit.Base.method(this, 'values') | 110 | MochiKit.Base.method(this, 'values') |
113 | ], | 111 | ], |
114 | 'recordsStats': [ | 112 | 'recordsStats': [ |
115 | MochiKit.Base.method(this, 'getRemoteData'), | 113 | MochiKit.Base.method(this, 'getRemoteData'), |
116 | MochiKit.Base.itemgetter('recordsStats') | 114 | MochiKit.Base.itemgetter('recordsStats') |
117 | ] | 115 | ] |
118 | }); | 116 | }); |
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.OneTimePasswords.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.OneTimePasswords.js index 3528db6..e82da47 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.OneTimePasswords.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.OneTimePasswords.js | |||
@@ -1,125 +1,117 @@ | |||
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 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.DataModel.User.Header.OneTimePasswords depends on Clipperz.PM.DataModel.User!"; | 25 | throw "Clipperz.PM.DataModel.User.Header.OneTimePasswords depends on Clipperz.PM.DataModel.User!"; |
28 | } | 26 | } |
29 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } | 27 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } |
30 | 28 | ||
31 | //----------------------------------------------------------------------------- | 29 | //----------------------------------------------------------------------------- |
32 | 30 | ||
33 | Clipperz.PM.DataModel.User.Header.OneTimePasswords = function(args) { | 31 | Clipperz.PM.DataModel.User.Header.OneTimePasswords = function(args) { |
34 | Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.constructor.apply(this, arguments); | 32 | Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.constructor.apply(this, arguments); |
35 | 33 | ||
36 | this._oneTimePasswords = null; | 34 | this._oneTimePasswords = null; |
37 | 35 | ||
38 | return this; | 36 | return this; |
39 | } | 37 | } |
40 | 38 | ||
41 | //----------------------------------------------------------------------------- | 39 | //----------------------------------------------------------------------------- |
42 | 40 | ||
43 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.OneTimePasswords, Clipperz.PM.DataModel.EncryptedRemoteObject, { | 41 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.OneTimePasswords, Clipperz.PM.DataModel.EncryptedRemoteObject, { |
44 | 42 | ||
45 | 'toString': function() { | 43 | 'toString': function() { |
46 | return "Clipperz.PM.DataModel.User.Header.OneTimePasswords"; | 44 | return "Clipperz.PM.DataModel.User.Header.OneTimePasswords"; |
47 | }, | 45 | }, |
48 | 46 | ||
49 | //------------------------------------------------------------------------- | 47 | //------------------------------------------------------------------------- |
50 | /* | 48 | /* |
51 | 'packData': function (someData) { //++ | 49 | 'packData': function (someData) { //++ |
52 | var result; | 50 | var result; |
53 | 51 | ||
54 | console.log(">>> OneTimePasswords.packData", someData); | ||
55 | result = Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.packData.apply(this, arguments); | 52 | result = Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.packData.apply(this, arguments); |
56 | console.log("<<< OneTimePasswords.packData"); | ||
57 | 53 | ||
58 | return result; | 54 | return result; |
59 | }, | 55 | }, |
60 | */ | 56 | */ |
61 | //------------------------------------------------------------------------- | 57 | //------------------------------------------------------------------------- |
62 | /* | 58 | /* |
63 | 'packRemoteData': function (someData) { | 59 | 'packRemoteData': function (someData) { |
64 | var result; | 60 | var result; |
65 | 61 | ||
66 | console.log(">>> OneTimePasswords.packRemoteData", someData); | ||
67 | result = Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.packRemoteData.apply(this, arguments); | 62 | result = Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.packRemoteData.apply(this, arguments); |
68 | console.log("<<< OneTimePasswords.packRemoteData"); | ||
69 | 63 | ||
70 | return result; | 64 | return result; |
71 | }, | 65 | }, |
72 | */ | 66 | */ |
73 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
74 | /* | 68 | /* |
75 | 'prepareRemoteDataWithKey': function (aKey) { | 69 | 'prepareRemoteDataWithKey': function (aKey) { |
76 | var result; | 70 | var result; |
77 | 71 | ||
78 | console.log(">>> OneTimePasswords.prepareRemoteDataWithKey"); | ||
79 | result = Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.prepareRemoteDataWithKey.apply(this, arguments); | 72 | result = Clipperz.PM.DataModel.User.Header.OneTimePasswords.superclass.prepareRemoteDataWithKey.apply(this, arguments); |
80 | console.log("<<< OneTimePasswords.prepareRemoteDataWithKey"); | ||
81 | 73 | ||
82 | return result; | 74 | return result; |
83 | }, | 75 | }, |
84 | */ | 76 | */ |
85 | //========================================================================= | 77 | //========================================================================= |
86 | 78 | ||
87 | 'oneTimePasswords': function () { | 79 | 'oneTimePasswords': function () { |
88 | vardeferredResult; | 80 | vardeferredResult; |
89 | 81 | ||
90 | deferredResult = new Clipperz.Async.Deferred("User.Header.OneTimePasswords.oneTimePasswords", {trace:false}); | 82 | deferredResult = new Clipperz.Async.Deferred("User.Header.OneTimePasswords.oneTimePasswords", {trace:false}); |
91 | if (this._oneTimePasswords == null) { | 83 | if (this._oneTimePasswords == null) { |
92 | deferredResult.addMethod(this, 'values') | 84 | deferredResult.addMethod(this, 'values') |
93 | deferredResult.addCallback(MochiKit.Base.bind(function (someData) { | 85 | deferredResult.addCallback(MochiKit.Base.bind(function (someData) { |
94 | varotpKey; | 86 | varotpKey; |
95 | 87 | ||
96 | this._oneTimePasswords = {}; | 88 | this._oneTimePasswords = {}; |
97 | 89 | ||
98 | for (otpKey in someData) { | 90 | for (otpKey in someData) { |
99 | var otp; | 91 | var otp; |
100 | var otpParameters; | 92 | var otpParameters; |
101 | 93 | ||
102 | otpParameters = Clipperz.Base.deepClone(someData[otpKey]); | 94 | otpParameters = Clipperz.Base.deepClone(someData[otpKey]); |
103 | otpParameters['reference'] = otpKey; | 95 | otpParameters['reference'] = otpKey; |
104 | 96 | ||
105 | otp = new Clipperz.PM.DataModel.OneTimePassword(otpParameters); | 97 | otp = new Clipperz.PM.DataModel.OneTimePassword(otpParameters); |
106 | this._oneTimePasswords[otpKey] = otp; | 98 | this._oneTimePasswords[otpKey] = otp; |
107 | } | 99 | } |
108 | 100 | ||
109 | return this._oneTimePasswords; | 101 | return this._oneTimePasswords; |
110 | 102 | ||
111 | }, this)); | 103 | }, this)); |
112 | deferredResult.callback(); | 104 | deferredResult.callback(); |
113 | } else { | 105 | } else { |
114 | deferredResult = MochiKit.Async.succeed(this._oneTimePasswords); | 106 | deferredResult = MochiKit.Async.succeed(this._oneTimePasswords); |
115 | } | 107 | } |
116 | 108 | ||
117 | return deferredResult; | 109 | return deferredResult; |
118 | }, | 110 | }, |
119 | 111 | ||
120 | //========================================================================= | 112 | //========================================================================= |
121 | __syntaxFix__: "syntax fix" | 113 | __syntaxFix__: "syntax fix" |
122 | }); | 114 | }); |
123 | 115 | ||
124 | //----------------------------------------------------------------------------- | 116 | //----------------------------------------------------------------------------- |
125 | 117 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Preferences.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Preferences.js index b164889..f1f95e8 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Preferences.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.Preferences.js | |||
@@ -1,50 +1,48 @@ | |||
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 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.DataModel.User.Header.Preferences depends on Clipperz.PM.DataModel.User!"; | 25 | throw "Clipperz.PM.DataModel.User.Header.Preferences depends on Clipperz.PM.DataModel.User!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } | 28 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } |
31 | 29 | ||
32 | Clipperz.PM.DataModel.User.Header.Preferences = function(args) { | 30 | Clipperz.PM.DataModel.User.Header.Preferences = function(args) { |
33 | Clipperz.PM.DataModel.User.Header.Preferences.superclass.constructor.apply(this, arguments); | 31 | Clipperz.PM.DataModel.User.Header.Preferences.superclass.constructor.apply(this, arguments); |
34 | 32 | ||
35 | return this; | 33 | return this; |
36 | } | 34 | } |
37 | 35 | ||
38 | 36 | ||
39 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.Preferences, Clipperz.PM.DataModel.EncryptedRemoteObject, { | 37 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.Preferences, Clipperz.PM.DataModel.EncryptedRemoteObject, { |
40 | 38 | ||
41 | 'toString': function() { | 39 | 'toString': function() { |
42 | return "Clipperz.PM.DataModel.User.Header.Preferences"; | 40 | return "Clipperz.PM.DataModel.User.Header.Preferences"; |
43 | }, | 41 | }, |
44 | 42 | ||
45 | //------------------------------------------------------------------------- | 43 | //------------------------------------------------------------------------- |
46 | //========================================================================= | 44 | //========================================================================= |
47 | __syntaxFix__: "syntax fix" | 45 | __syntaxFix__: "syntax fix" |
48 | }); | 46 | }); |
49 | 47 | ||
50 | 48 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js index f77ea80..5681f70 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js | |||
@@ -1,669 +1,652 @@ | |||
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 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.DataModel.User.Header.RecordIndex depends on Clipperz.PM.DataModel.User!"; | 25 | throw "Clipperz.PM.DataModel.User.Header.RecordIndex depends on Clipperz.PM.DataModel.User!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } | 28 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } |
31 | 29 | ||
32 | Clipperz.PM.DataModel.User.Header.RecordIndex = function(args) { | 30 | Clipperz.PM.DataModel.User.Header.RecordIndex = function(args) { |
33 | Clipperz.PM.DataModel.User.Header.RecordIndex.superclass.constructor.apply(this, arguments); | 31 | Clipperz.PM.DataModel.User.Header.RecordIndex.superclass.constructor.apply(this, arguments); |
34 | 32 | ||
35 | //console.log("NEW Clipperz.PM.DataModel.User.Header.RecordIndex", args); | ||
36 | this._recordsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ | 33 | this._recordsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ |
37 | 'name':'recordsData', | 34 | 'name':'recordsData', |
38 | 'retrieveKeyFunction': args.retrieveKeyFunction, | 35 | 'retrieveKeyFunction': args.retrieveKeyFunction, |
39 | 'remoteData': { | 36 | 'remoteData': { |
40 | 'data': args.recordsData['data'], | 37 | 'data': args.recordsData['data'], |
41 | 'version': args.encryptedDataVersion, | 38 | 'version': args.encryptedDataVersion, |
42 | 'recordsStats': args.recordsStats | 39 | 'recordsStats': args.recordsStats |
43 | }//, | 40 | }//, |
44 | // 'encryptedDataKeypath': 'data', | 41 | // 'encryptedDataKeypath': 'data', |
45 | // 'encryptedVersionKeypath': 'version' | 42 | // 'encryptedVersionKeypath': 'version' |
46 | }); | 43 | }); |
47 | 44 | ||
48 | this._directLoginsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ | 45 | this._directLoginsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ |
49 | 'name':'directLoginsData', | 46 | 'name':'directLoginsData', |
50 | 'retrieveKeyFunction': args.retrieveKeyFunction, | 47 | 'retrieveKeyFunction': args.retrieveKeyFunction, |
51 | 'remoteData': { | 48 | 'remoteData': { |
52 | 'data': args.directLoginsData['data'], | 49 | 'data': args.directLoginsData['data'], |
53 | 'version': args.encryptedDataVersion | 50 | 'version': args.encryptedDataVersion |
54 | }//, | 51 | }//, |
55 | // 'encryptedDataKeypath': 'data', | 52 | // 'encryptedDataKeypath': 'data', |
56 | // 'encryptedVersionKeypath': 'version' | 53 | // 'encryptedVersionKeypath': 'version' |
57 | }); | 54 | }); |
58 | 55 | ||
59 | this._lock = new MochiKit.Async.DeferredLock(); | 56 | this._lock = new MochiKit.Async.DeferredLock(); |
60 | this._transientState = null; | 57 | this._transientState = null; |
61 | 58 | ||
62 | this._retrieveRecordDetailFunction = args.retrieveRecordDetailFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); | 59 | this._retrieveRecordDetailFunction = args.retrieveRecordDetailFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); |
63 | this._recordsIndex = args.recordsData['index'] || Clipperz.Base.exception.raise('MandatoryParameter'); | 60 | this._recordsIndex = args.recordsData['index'] || Clipperz.Base.exception.raise('MandatoryParameter'); |
64 | this._directLoginsIndex = args.directLoginsData['index']|| Clipperz.Base.exception.raise('MandatoryParameter'); | 61 | this._directLoginsIndex = args.directLoginsData['index']|| Clipperz.Base.exception.raise('MandatoryParameter'); |
65 | 62 | ||
66 | this._records = null; | 63 | this._records = null; |
67 | 64 | ||
68 | return this; | 65 | return this; |
69 | } | 66 | } |
70 | 67 | ||
71 | 68 | ||
72 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.RecordIndex, Object, { | 69 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.RecordIndex, Object, { |
73 | 70 | ||
74 | 'toString': function() { | 71 | 'toString': function() { |
75 | return "Clipperz.PM.DataModel.User.Header.RecordIndex"; | 72 | return "Clipperz.PM.DataModel.User.Header.RecordIndex"; |
76 | }, | 73 | }, |
77 | 74 | ||
78 | //------------------------------------------------------------------------- | 75 | //------------------------------------------------------------------------- |
79 | 76 | ||
80 | 'retrieveRecordDetailFunction': function () { | 77 | 'retrieveRecordDetailFunction': function () { |
81 | return this._retrieveRecordDetailFunction; | 78 | return this._retrieveRecordDetailFunction; |
82 | }, | 79 | }, |
83 | 80 | ||
84 | //------------------------------------------------------------------------- | 81 | //------------------------------------------------------------------------- |
85 | 82 | ||
86 | 'recordsIndex': function () { | 83 | 'recordsIndex': function () { |
87 | return this._recordsIndex; | 84 | return this._recordsIndex; |
88 | }, | 85 | }, |
89 | 86 | ||
90 | 'recordsData': function () { | 87 | 'recordsData': function () { |
91 | return this._recordsData; | 88 | return this._recordsData; |
92 | }, | 89 | }, |
93 | 90 | ||
94 | //------------------------------------------------------------------------- | 91 | //------------------------------------------------------------------------- |
95 | 92 | ||
96 | 'directLoginsIndex': function () { | 93 | 'directLoginsIndex': function () { |
97 | return this._directLoginsIndex; | 94 | return this._directLoginsIndex; |
98 | }, | 95 | }, |
99 | 96 | ||
100 | 'directLoginsData': function () { | 97 | 'directLoginsData': function () { |
101 | return this._directLoginsData; | 98 | return this._directLoginsData; |
102 | }, | 99 | }, |
103 | 100 | ||
104 | //------------------------------------------------------------------------- | 101 | //------------------------------------------------------------------------- |
105 | 102 | ||
106 | 'lock': function () { | 103 | 'lock': function () { |
107 | return this._lock; | 104 | return this._lock; |
108 | }, | 105 | }, |
109 | 106 | ||
110 | //------------------------------------------------------------------------- | 107 | //------------------------------------------------------------------------- |
111 | 108 | ||
112 | 'transientState': function () { | 109 | 'transientState': function () { |
113 | if (this._transientState == null) { | 110 | if (this._transientState == null) { |
114 | this._transientState = new Clipperz.KeyValueObjectStore(/*{'name':'User.Header.RecordIndex.transientState [1]'}*/); | 111 | this._transientState = new Clipperz.KeyValueObjectStore(/*{'name':'User.Header.RecordIndex.transientState [1]'}*/); |
115 | } | 112 | } |
116 | 113 | ||
117 | return this._transientState; | 114 | return this._transientState; |
118 | }, | 115 | }, |
119 | 116 | ||
120 | 'resetTransientState': function (isCommitting) { | 117 | 'resetTransientState': function (isCommitting) { |
121 | //console.log("######## UserHeaderRecordIndex - resetTransientState", Clipperz.Base.deepClone(this._transientState)); | ||
122 | if (this._transientState != null) { | 118 | if (this._transientState != null) { |
123 | this._transientState.removeAllData(); | 119 | this._transientState.removeAllData(); |
124 | } | 120 | } |
125 | 121 | ||
126 | this._transientState = null; | 122 | this._transientState = null; |
127 | }, | 123 | }, |
128 | 124 | ||
129 | //------------------------------------------------------------------------- | 125 | //------------------------------------------------------------------------- |
130 | 126 | ||
131 | 'getRecordKey': function (aRecordReference) { | 127 | 'getRecordKey': function (aRecordReference) { |
132 | return Clipperz.Async.callbacks("User.Header.RecordIndex.getRecordKey", [ | 128 | return Clipperz.Async.callbacks("User.Header.RecordIndex.getRecordKey", [ |
133 | MochiKit.Base.method(this, 'getRecordIndexData', aRecordReference), | 129 | MochiKit.Base.method(this, 'getRecordIndexData', aRecordReference), |
134 | MochiKit.Base.itemgetter('key') | 130 | MochiKit.Base.itemgetter('key') |
135 | ], {trace:false}); | 131 | ], {trace:false}); |
136 | }, | 132 | }, |
137 | 133 | ||
138 | 'setRecordKey': function (aRecordReference, aValue) { | 134 | 'setRecordKey': function (aRecordReference, aValue) { |
139 | return this.updateRecordIndexData(aRecordReference, 'key', aValue); | 135 | return this.updateRecordIndexData(aRecordReference, 'key', aValue); |
140 | }, | 136 | }, |
141 | 137 | ||
142 | //------------------------------------------------------------------------- | 138 | //------------------------------------------------------------------------- |
143 | 139 | ||
144 | 'getRecordIndexData': function (aRecordReference) { | 140 | 'getRecordIndexData': function (aRecordReference) { |
145 | return this.recordsData().getValue(this.recordsIndex()[aRecordReference]); | 141 | return this.recordsData().getValue(this.recordsIndex()[aRecordReference]); |
146 | }, | 142 | }, |
147 | 143 | ||
148 | //......................................................................... | 144 | //......................................................................... |
149 | 145 | ||
150 | 'updateRecordIndexData': function (aRecordReference, aKey, aValue) { | 146 | 'updateRecordIndexData': function (aRecordReference, aKey, aValue) { |
151 | return this.recordsData().setValue(this.recordsIndex()[aRecordReference]+'.'+aKey, aValue); | 147 | return this.recordsData().setValue(this.recordsIndex()[aRecordReference]+'.'+aKey, aValue); |
152 | }, | 148 | }, |
153 | 149 | ||
154 | //------------------------------------------------------------------------- | 150 | //------------------------------------------------------------------------- |
155 | 151 | ||
156 | 'getDirectLoginIndexData': function (aDirectLoginReference) { | 152 | 'getDirectLoginIndexData': function (aDirectLoginReference) { |
157 | return this.directLoginsData().getValue(this.directLoginsIndex()[aDirectLoginReference]); | 153 | return this.directLoginsData().getValue(this.directLoginsIndex()[aDirectLoginReference]); |
158 | }, | 154 | }, |
159 | 155 | ||
160 | 'setDirectLoginIndexData': function (aDirectLoginReference, aKey, aValue) { | 156 | 'setDirectLoginIndexData': function (aDirectLoginReference, aKey, aValue) { |
161 | //console.log("UserHeaderRecordIndex.setDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference], aKey); | ||
162 | //if (MochiKit.Base.isUndefinedOrNull(this.directLoginsIndex()[aDirectLoginReference])) { | 157 | //if (MochiKit.Base.isUndefinedOrNull(this.directLoginsIndex()[aDirectLoginReference])) { |
163 | //throw "PIPPO"; | 158 | //throw "PIPPO"; |
164 | //} | 159 | //} |
165 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference] + '.' + aKey, aValue); | 160 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference] + '.' + aKey, aValue); |
166 | }, | 161 | }, |
167 | 162 | ||
168 | 'addDirectLoginIndexData': function (aDirectLoginReference) { | 163 | 'addDirectLoginIndexData': function (aDirectLoginReference) { |
169 | //console.log("UserHeaderRecordIndex.addDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference]); | ||
170 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference], {}); | 164 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference], {}); |
171 | }, | 165 | }, |
172 | 166 | ||
173 | 'removeDirectLoginIndexData': function (aDirectLoginReference) { | 167 | 'removeDirectLoginIndexData': function (aDirectLoginReference) { |
174 | return this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLoginReference]) | 168 | return this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLoginReference]) |
175 | }, | 169 | }, |
176 | 170 | ||
177 | //------------------------------------------------------------------------- | 171 | //------------------------------------------------------------------------- |
178 | 172 | ||
179 | 'records': function () { | 173 | 'records': function () { |
180 | vardeferredResult; | 174 | vardeferredResult; |
181 | 175 | ||
182 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records", {trace:false}); | 176 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records", {trace:false}); |
183 | deferredResult.acquireLock(this.lock()); | 177 | deferredResult.acquireLock(this.lock()); |
184 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 178 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
185 | var innerDeferredResult; | 179 | var innerDeferredResult; |
186 | 180 | ||
187 | if (this._records == null) { | 181 | if (this._records == null) { |
188 | innerDeferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records <inner deferred>", {trace:false}); | 182 | innerDeferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records <inner deferred>", {trace:false}); |
189 | innerDeferredResult.collectResults({ | 183 | innerDeferredResult.collectResults({ |
190 | 'records': [ | 184 | 'records': [ |
191 | // MochiKit.Base.method(this.recordsData(), 'getObjectDataStore'), | 185 | // MochiKit.Base.method(this.recordsData(), 'getObjectDataStore'), |
192 | // MochiKit.Base.methodcaller('values') | 186 | // MochiKit.Base.methodcaller('values') |
193 | MochiKit.Base.method(this.recordsData(), 'values') | 187 | MochiKit.Base.method(this.recordsData(), 'values') |
194 | ], | 188 | ], |
195 | 'recordsStats': [ | 189 | 'recordsStats': [ |
196 | MochiKit.Base.method(this.recordsData(), 'getRemoteData'), | 190 | MochiKit.Base.method(this.recordsData(), 'getRemoteData'), |
197 | MochiKit.Base.itemgetter('recordsStats') | 191 | MochiKit.Base.itemgetter('recordsStats') |
198 | ], | 192 | ], |
199 | 'directLogins': [ | 193 | 'directLogins': [ |
200 | // MochiKit.Base.method(this.directLoginsData(), 'getObjectDataStore'), | 194 | // MochiKit.Base.method(this.directLoginsData(), 'getObjectDataStore'), |
201 | // MochiKit.Base.methodcaller('values') | 195 | // MochiKit.Base.methodcaller('values') |
202 | MochiKit.Base.method(this.directLoginsData(), 'values') | 196 | MochiKit.Base.method(this.directLoginsData(), 'values') |
203 | ] | 197 | ] |
204 | }) | 198 | }) |
205 | innerDeferredResult.addCallback(MochiKit.Base.bind(function (someData) { | 199 | innerDeferredResult.addCallback(MochiKit.Base.bind(function (someData) { |
206 | var indexReference; | 200 | var indexReference; |
207 | var recordsInvertedIndex; | 201 | var recordsInvertedIndex; |
208 | var directLoginsInvertedIndex; | 202 | var directLoginsInvertedIndex; |
209 | 203 | ||
210 | recordsInvertedIndex = Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.recordsIndex()); | 204 | recordsInvertedIndex = Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.recordsIndex()); |
211 | directLoginsInvertedIndex= Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.directLoginsIndex()); | 205 | directLoginsInvertedIndex= Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.directLoginsIndex()); |
212 | 206 | ||
213 | this._records = {}; | 207 | this._records = {}; |
214 | 208 | ||
215 | for (indexReference in someData['records']) { | 209 | for (indexReference in someData['records']) { |
216 | varrecord; | 210 | varrecord; |
217 | var reference; | 211 | var reference; |
218 | var updateDate; | 212 | var updateDate; |
219 | 213 | ||
220 | reference = recordsInvertedIndex[indexReference]; | 214 | reference = recordsInvertedIndex[indexReference]; |
221 | 215 | ||
222 | if (typeof(someData['recordsStats'][reference]) != 'undefined') { | 216 | if (typeof(someData['recordsStats'][reference]) != 'undefined') { |
223 | updateDate = someData['recordsStats'][reference]['updateDate']; | 217 | updateDate = someData['recordsStats'][reference]['updateDate']; |
224 | 218 | ||
225 | record = new Clipperz.PM.DataModel.Record({ | 219 | record = new Clipperz.PM.DataModel.Record({ |
226 | 'reference': reference, | 220 | 'reference': reference, |
227 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), | 221 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), |
228 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), | 222 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), |
229 | 223 | ||
230 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), | 224 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), |
231 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), | 225 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), |
232 | 'updateDate': updateDate, | 226 | 'updateDate': updateDate, |
233 | 227 | ||
234 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), | 228 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), |
235 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), | 229 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), |
236 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), | 230 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), |
237 | 231 | ||
238 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') | 232 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') |
239 | }); | 233 | }); |
240 | 234 | ||
241 | this._records[reference] = record; | 235 | this._records[reference] = record; |
242 | } else { | 236 | } else { |
243 | Clipperz.log("SKIPPING record " + reference + " as there are no stas associated - " + Clipperz.Base.serializeJSON(someData['records'][reference])); | 237 | Clipperz.log("SKIPPING record " + reference + " as there are no stas associated - " + Clipperz.Base.serializeJSON(someData['records'][reference])); |
244 | //# skip the record, as it seems it is not present in the DB | 238 | //# skip the record, as it seems it is not present in the DB |
245 | //updateDate = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 239 | //updateDate = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
246 | } | 240 | } |
247 | } | 241 | } |
248 | 242 | ||
249 | for (indexReference in someData['directLogins']) { | 243 | for (indexReference in someData['directLogins']) { |
250 | // vardirectLogin; | 244 | // vardirectLogin; |
251 | var reference; | 245 | var reference; |
252 | var record; | 246 | var record; |
253 | 247 | ||
254 | reference = directLoginsInvertedIndex[indexReference]; | 248 | reference = directLoginsInvertedIndex[indexReference]; |
255 | record = this._records[recordsInvertedIndex[someData['directLogins'][indexReference]['record']]]; | 249 | record = this._records[recordsInvertedIndex[someData['directLogins'][indexReference]['record']]]; |
256 | 250 | ||
257 | if (record != null) { | 251 | if (record != null) { |
258 | // directLogin = new Clipperz.PM.DataModel.DirectLogin({ | 252 | // directLogin = new Clipperz.PM.DataModel.DirectLogin({ |
259 | new Clipperz.PM.DataModel.DirectLogin({ | 253 | new Clipperz.PM.DataModel.DirectLogin({ |
260 | 'reference': reference, | 254 | 'reference': reference, |
261 | 'record': record | 255 | 'record': record |
262 | }); | 256 | }); |
263 | } else { | 257 | } else { |
264 | Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!"); | 258 | Clipperz.logWarning("WARNING: DIRECT LOGIN without a matching RECORD!!"); |
265 | //console.log("direct login data", someData['directLogins']); | ||
266 | //console.log("current direct login data", someData['directLogins'][indexReference]) | ||
267 | //console.log("reference", reference); | ||
268 | //console.log("record index", this.recordsIndex()); | ||
269 | //console.log("record inverted index", recordsInvertedIndex); | ||
270 | } | 259 | } |
271 | } | 260 | } |
272 | 261 | ||
273 | return this._records; | 262 | return this._records; |
274 | }, this)); | 263 | }, this)); |
275 | innerDeferredResult.callback(); | 264 | innerDeferredResult.callback(); |
276 | } else { | 265 | } else { |
277 | innerDeferredResult = MochiKit.Async.succeed(this._records); | 266 | innerDeferredResult = MochiKit.Async.succeed(this._records); |
278 | } | 267 | } |
279 | 268 | ||
280 | return innerDeferredResult; | 269 | return innerDeferredResult; |
281 | }, this)); | 270 | }, this)); |
282 | deferredResult.releaseLock(this.lock()); | 271 | deferredResult.releaseLock(this.lock()); |
283 | deferredResult.callback(); | 272 | deferredResult.callback(); |
284 | 273 | ||
285 | return deferredResult; | 274 | return deferredResult; |
286 | }, | 275 | }, |
287 | 276 | ||
288 | //------------------------------------------------------------------------- | 277 | //------------------------------------------------------------------------- |
289 | 278 | ||
290 | 'updateRecordIndexForNewRecord': function (aNewRecord) { | 279 | 'updateRecordIndexForNewRecord': function (aNewRecord) { |
291 | var newRecordIndex; | 280 | var newRecordIndex; |
292 | var recordReference; | 281 | var recordReference; |
293 | 282 | ||
294 | recordReference = aNewRecord.reference(); | 283 | recordReference = aNewRecord.reference(); |
295 | newRecordIndex = (MochiKit.Base.listMax(MochiKit.Base.map(MochiKit.Base.partial(MochiKit.Base.operator.mul, 1), MochiKit.Base.values(this.recordsIndex()))) + 1) + ''; | 284 | newRecordIndex = (MochiKit.Base.listMax(MochiKit.Base.map(MochiKit.Base.partial(MochiKit.Base.operator.mul, 1), MochiKit.Base.values(this.recordsIndex()))) + 1) + ''; |
296 | this.recordsIndex()[recordReference] = newRecordIndex; | 285 | this.recordsIndex()[recordReference] = newRecordIndex; |
297 | 286 | ||
298 | this.transientState().setValue('newlyCreatedRecordsIndex' + '.' + recordReference, newRecordIndex); | 287 | this.transientState().setValue('newlyCreatedRecordsIndex' + '.' + recordReference, newRecordIndex); |
299 | this.transientState().setValue('newlyCreatedRecordsReferences'+ '.' + recordReference, aNewRecord); | 288 | this.transientState().setValue('newlyCreatedRecordsReferences'+ '.' + recordReference, aNewRecord); |
300 | }, | 289 | }, |
301 | 290 | ||
302 | //......................................................................... | 291 | //......................................................................... |
303 | 292 | ||
304 | 'createNewRecord': function () { | 293 | 'createNewRecord': function () { |
305 | var deferredResult; | 294 | var deferredResult; |
306 | var newRecord; | 295 | var newRecord; |
307 | 296 | ||
308 | //console.log("#### new Clipperz.PM.DataModel.Record [4]"); | ||
309 | newRecord = new Clipperz.PM.DataModel.Record({ | 297 | newRecord = new Clipperz.PM.DataModel.Record({ |
310 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), | 298 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), |
311 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), | 299 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), |
312 | 300 | ||
313 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), | 301 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), |
314 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), | 302 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), |
315 | 'updateDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), | 303 | 'updateDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), |
316 | 304 | ||
317 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), | 305 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), |
318 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), | 306 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), |
319 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), | 307 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), |
320 | 308 | ||
321 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') | 309 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') |
322 | }); | 310 | }); |
323 | 311 | ||
324 | this.transientState().setValue('newRecordsReferences' + '.' + newRecord.reference(), newRecord); | 312 | this.transientState().setValue('newRecordsReferences' + '.' + newRecord.reference(), newRecord); |
325 | this.updateRecordIndexForNewRecord(newRecord); | 313 | this.updateRecordIndexForNewRecord(newRecord); |
326 | 314 | ||
327 | deferredResult = Clipperz.Async.callbacks("User.Header.RecordIndex.createNewRecord", [ | 315 | deferredResult = Clipperz.Async.callbacks("User.Header.RecordIndex.createNewRecord", [ |
328 | MochiKit.Base.method(this, 'records'), | 316 | MochiKit.Base.method(this, 'records'), |
329 | MochiKit.Base.partial(Clipperz.Async.setItemOnObject, newRecord.reference(), newRecord), | 317 | MochiKit.Base.partial(Clipperz.Async.setItemOnObject, newRecord.reference(), newRecord), |
330 | MochiKit.Base.method(this, 'setRecordKey', newRecord.reference(), Clipperz.PM.Crypto.randomKey()), | 318 | MochiKit.Base.method(this, 'setRecordKey', newRecord.reference(), Clipperz.PM.Crypto.randomKey()), |
331 | MochiKit.Base.method(newRecord, 'setLabel', ''), | 319 | MochiKit.Base.method(newRecord, 'setLabel', ''), |
332 | MochiKit.Base.partial(MochiKit.Async.succeed, newRecord) | 320 | MochiKit.Base.partial(MochiKit.Async.succeed, newRecord) |
333 | ], {trace:false}); | 321 | ], {trace:false}); |
334 | 322 | ||
335 | 323 | ||
336 | return deferredResult; | 324 | return deferredResult; |
337 | }, | 325 | }, |
338 | 326 | ||
339 | //------------------------------------------------------------------------- | 327 | //------------------------------------------------------------------------- |
340 | 328 | ||
341 | 'deleteRecord': function (aRecord) { | 329 | 'deleteRecord': function (aRecord) { |
342 | var deferredResult; | 330 | var deferredResult; |
343 | var recordReference; | 331 | var recordReference; |
344 | 332 | ||
345 | recordReference = aRecord.reference(); | 333 | recordReference = aRecord.reference(); |
346 | 334 | ||
347 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.deleteRecord", {trace:false}); | 335 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.deleteRecord", {trace:false}); |
348 | 336 | ||
349 | deferredResult.addMethod(aRecord, 'directLogins'); | 337 | deferredResult.addMethod(aRecord, 'directLogins'); |
350 | deferredResult.addCallback(MochiKit.Base.values); | 338 | deferredResult.addCallback(MochiKit.Base.values); |
351 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'removeDirectLogin')); | 339 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'removeDirectLogin')); |
352 | 340 | ||
353 | deferredResult.addMethod(this.recordsData(), 'removeValue', this.recordsIndex()[recordReference]); | 341 | deferredResult.addMethod(this.recordsData(), 'removeValue', this.recordsIndex()[recordReference]); |
354 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 342 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
355 | this.transientState().setValue('deleteRecordsIndex' + '.' + recordReference, this.recordsIndex()[recordReference]); | 343 | this.transientState().setValue('deleteRecordsIndex' + '.' + recordReference, this.recordsIndex()[recordReference]); |
356 | delete this.recordsIndex()[recordReference]; | 344 | delete this.recordsIndex()[recordReference]; |
357 | }, this)); | 345 | }, this)); |
358 | 346 | ||
359 | deferredResult.addMethod(this, 'records'); | 347 | deferredResult.addMethod(this, 'records'); |
360 | deferredResult.addCallback(MochiKit.Base.itemgetter(recordReference)); | 348 | deferredResult.addCallback(MochiKit.Base.itemgetter(recordReference)); |
361 | deferredResult.addMethod(this.transientState(), 'setValue', 'deleteRecordsReferences' + '.' + recordReference); | 349 | deferredResult.addMethod(this.transientState(), 'setValue', 'deleteRecordsReferences' + '.' + recordReference); |
362 | 350 | ||
363 | deferredResult.addMethod(this, 'records'); | 351 | deferredResult.addMethod(this, 'records'); |
364 | deferredResult.addCallback(MochiKit.Base.bind(function (someRecords) { | 352 | deferredResult.addCallback(MochiKit.Base.bind(function (someRecords) { |
365 | delete someRecords[recordReference]; | 353 | delete someRecords[recordReference]; |
366 | }, this)); | 354 | }, this)); |
367 | deferredResult.callback(); | 355 | deferredResult.callback(); |
368 | 356 | ||
369 | return deferredResult; | 357 | return deferredResult; |
370 | }, | 358 | }, |
371 | 359 | ||
372 | //========================================================================= | 360 | //========================================================================= |
373 | 361 | ||
374 | 'removeDirectLogin': function (aDirectLogin) { | 362 | 'removeDirectLogin': function (aDirectLogin) { |
375 | this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLogin.reference()]); | 363 | this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLogin.reference()]); |
376 | }, | 364 | }, |
377 | 365 | ||
378 | //------------------------------------------------------------------------- | 366 | //------------------------------------------------------------------------- |
379 | 367 | ||
380 | 'createNewDirectLogin': function (aRecord) { | 368 | 'createNewDirectLogin': function (aRecord) { |
381 | var newDirectLogin; | 369 | var newDirectLogin; |
382 | varnewDirectLoginIndexValue; | 370 | varnewDirectLoginIndexValue; |
383 | 371 | ||
384 | newDirectLogin = new Clipperz.PM.DataModel.DirectLogin({record:aRecord}); | 372 | newDirectLogin = new Clipperz.PM.DataModel.DirectLogin({record:aRecord}); |
385 | newDirectLoginIndexValue = MochiKit.Base.listMax(MochiKit.Base.map(function (aValue) { return aValue * 1; }, MochiKit.Base.values(this.directLoginsIndex()))) + 1; | 373 | newDirectLoginIndexValue = MochiKit.Base.listMax(MochiKit.Base.map(function (aValue) { return aValue * 1; }, MochiKit.Base.values(this.directLoginsIndex()))) + 1; |
386 | 374 | ||
387 | this.transientState().setValue('newDirectLoginReferences' + '.' + newDirectLogin.reference(), newDirectLogin); | 375 | this.transientState().setValue('newDirectLoginReferences' + '.' + newDirectLogin.reference(), newDirectLogin); |
388 | 376 | ||
389 | //console.log("UserHeaderRecordIndex.createNewDirectLogin [1]", newDirectLogin.reference(), newDirectLoginIndexValue); | ||
390 | this.directLoginsIndex()[newDirectLogin.reference()] = newDirectLoginIndexValue; | 377 | this.directLoginsIndex()[newDirectLogin.reference()] = newDirectLoginIndexValue; |
391 | //console.log("UserHeaderRecordIndex.createNewDirectLogin [2]", newDirectLogin.reference(), this.directLoginsIndex()[newDirectLogin.reference()]); | ||
392 | this.directLoginsData().setValue(this.directLoginsIndex()[newDirectLogin.reference()], {'record': this.recordsIndex()[aRecord.reference()]}); | 378 | this.directLoginsData().setValue(this.directLoginsIndex()[newDirectLogin.reference()], {'record': this.recordsIndex()[aRecord.reference()]}); |
393 | 379 | ||
394 | return newDirectLogin; | 380 | return newDirectLogin; |
395 | }, | 381 | }, |
396 | 382 | ||
397 | //========================================================================= | 383 | //========================================================================= |
398 | 384 | ||
399 | 'deleteAllCleanTextData': function () { | 385 | 'deleteAllCleanTextData': function () { |
400 | return Clipperz.Async.callbacks("User.Header.RecordIndex.deleteAllCleanTextData", [ | 386 | return Clipperz.Async.callbacks("User.Header.RecordIndex.deleteAllCleanTextData", [ |
401 | // MochiKit.Base.method(this, 'records'), | 387 | // MochiKit.Base.method(this, 'records'), |
402 | // MochiKit.Base.values, | 388 | // MochiKit.Base.values, |
403 | // MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), | 389 | // MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), |
404 | 390 | ||
405 | MochiKit.Base.method(this, 'recordsData'), | 391 | MochiKit.Base.method(this, 'recordsData'), |
406 | MochiKit.Base.methodcaller('deleteAllCleanTextData'), | 392 | MochiKit.Base.methodcaller('deleteAllCleanTextData'), |
407 | MochiKit.Base.method(this, 'directLoginsData'), | 393 | MochiKit.Base.method(this, 'directLoginsData'), |
408 | MochiKit.Base.methodcaller('deleteAllCleanTextData') | 394 | MochiKit.Base.methodcaller('deleteAllCleanTextData') |
409 | ], {trace:false}); | 395 | ], {trace:false}); |
410 | }, | 396 | }, |
411 | 397 | ||
412 | //------------------------------------------------------------------------- | 398 | //------------------------------------------------------------------------- |
413 | 399 | ||
414 | 'hasAnyCleanTextData': function () { | 400 | 'hasAnyCleanTextData': function () { |
415 | var deferredResult; | 401 | var deferredResult; |
416 | 402 | ||
417 | deferredResult = new Clipperz.Async.Deferred({trace:false}); | 403 | deferredResult = new Clipperz.Async.Deferred({trace:false}); |
418 | deferredResult.collectResults({ | 404 | deferredResult.collectResults({ |
419 | 'recordsData': [ | 405 | 'recordsData': [ |
420 | MochiKit.Base.method(this, 'recordsData'), | 406 | MochiKit.Base.method(this, 'recordsData'), |
421 | MochiKit.Base.methodcaller('hasAnyCleanTextData') | 407 | MochiKit.Base.methodcaller('hasAnyCleanTextData') |
422 | ], | 408 | ], |
423 | 'directLoginsData':[ | 409 | 'directLoginsData':[ |
424 | MochiKit.Base.method(this, 'directLoginsData'), | 410 | MochiKit.Base.method(this, 'directLoginsData'), |
425 | MochiKit.Base.methodcaller('hasAnyCleanTextData') | 411 | MochiKit.Base.methodcaller('hasAnyCleanTextData') |
426 | ], | 412 | ], |
427 | // 'records': [ | 413 | // 'records': [ |
428 | // MochiKit.Base.method(this, 'records'), | 414 | // MochiKit.Base.method(this, 'records'), |
429 | // MochiKit.Base.values, | 415 | // MochiKit.Base.values, |
430 | // MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')), | 416 | // MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')), |
431 | // Clipperz.Async.collectAll | 417 | // Clipperz.Async.collectAll |
432 | // ] | 418 | // ] |
433 | }); | 419 | }); |
434 | //deferredResult.addCallback(function (aValue) { console.log("USER.Header.RecordIndex.hasAnyCleanTextData", aValue); return aValue}); | ||
435 | 420 | ||
436 | // deferredResult.addCallback(MochiKit.Base.values); | 421 | // deferredResult.addCallback(MochiKit.Base.values); |
437 | // deferredResult.addCallback(MochiKit.Base.flattenArguments); | 422 | // deferredResult.addCallback(MochiKit.Base.flattenArguments); |
438 | // deferredResult.addCallback(function(someValues) { | 423 | // deferredResult.addCallback(function(someValues) { |
439 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); | 424 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); |
440 | // }); | 425 | // }); |
441 | deferredResult.addCallback(Clipperz.Async.or); | 426 | deferredResult.addCallback(Clipperz.Async.or); |
442 | 427 | ||
443 | deferredResult.callback(); | 428 | deferredResult.callback(); |
444 | 429 | ||
445 | return deferredResult; | 430 | return deferredResult; |
446 | }, | 431 | }, |
447 | 432 | ||
448 | //------------------------------------------------------------------------- | 433 | //------------------------------------------------------------------------- |
449 | 434 | ||
450 | 'hasPendingChanges': function () { | 435 | 'hasPendingChanges': function () { |
451 | vardeferredResult; | 436 | vardeferredResult; |
452 | 437 | ||
453 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.hasPendingChanges", {trace:false}); | 438 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.hasPendingChanges", {trace:false}); |
454 | deferredResult.collectResults({ | 439 | deferredResult.collectResults({ |
455 | 'recordsData': [ | 440 | 'recordsData': [ |
456 | MochiKit.Base.method(this, 'recordsData'), | 441 | MochiKit.Base.method(this, 'recordsData'), |
457 | MochiKit.Base.methodcaller('hasPendingChanges') | 442 | MochiKit.Base.methodcaller('hasPendingChanges') |
458 | ], | 443 | ], |
459 | 'directLoginsData': [ | 444 | 'directLoginsData': [ |
460 | MochiKit.Base.method(this, 'directLoginsData'), | 445 | MochiKit.Base.method(this, 'directLoginsData'), |
461 | MochiKit.Base.methodcaller('hasPendingChanges') | 446 | MochiKit.Base.methodcaller('hasPendingChanges') |
462 | ] | 447 | ] |
463 | }); | 448 | }); |
464 | //deferredResult.addCallback(function (aValue) { console.log("UserHeaderIndex.hasPendingResults", aValue); return aValue; }); | ||
465 | deferredResult.addCallback(Clipperz.Async.or); | 449 | deferredResult.addCallback(Clipperz.Async.or); |
466 | // deferredResult.addCallback(MochiKit.Base.values); | 450 | // deferredResult.addCallback(MochiKit.Base.values); |
467 | // deferredResult.addCallback(MochiKit.Base.flattenArguments); | 451 | // deferredResult.addCallback(MochiKit.Base.flattenArguments); |
468 | // deferredResult.addCallback(function(someValues) { | 452 | // deferredResult.addCallback(function(someValues) { |
469 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); | 453 | // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity); |
470 | // }); | 454 | // }); |
471 | deferredResult.callback(); | 455 | deferredResult.callback(); |
472 | 456 | ||
473 | return deferredResult; | 457 | return deferredResult; |
474 | }, | 458 | }, |
475 | 459 | ||
476 | //------------------------------------------------------------------------- | 460 | //------------------------------------------------------------------------- |
477 | 461 | ||
478 | 'commitTransientState': function () { | 462 | 'commitTransientState': function () { |
479 | var deferredResult; | 463 | var deferredResult; |
480 | 464 | ||
481 | deferredResut = Clipperz.Async.callbacks("User.Header.RecordIndex.commitTransientState", [ | 465 | deferredResut = Clipperz.Async.callbacks("User.Header.RecordIndex.commitTransientState", [ |
482 | MochiKit.Base.method(this, 'recordsData'), | 466 | MochiKit.Base.method(this, 'recordsData'), |
483 | MochiKit.Base.methodcaller('commitTransientState'), | 467 | MochiKit.Base.methodcaller('commitTransientState'), |
484 | 468 | ||
485 | MochiKit.Base.method(this, 'directLoginsData'), | 469 | MochiKit.Base.method(this, 'directLoginsData'), |
486 | MochiKit.Base.methodcaller('commitTransientState'), | 470 | MochiKit.Base.methodcaller('commitTransientState'), |
487 | 471 | ||
488 | MochiKit.Base.method(this, 'resetTransientState', true) | 472 | MochiKit.Base.method(this, 'resetTransientState', true) |
489 | ], {trace:false}); | 473 | ], {trace:false}); |
490 | 474 | ||
491 | return deferredResult; | 475 | return deferredResult; |
492 | }, | 476 | }, |
493 | 477 | ||
494 | //------------------------------------------------------------------------- | 478 | //------------------------------------------------------------------------- |
495 | 479 | ||
496 | 'revertChanges': function () { | 480 | 'revertChanges': function () { |
497 | return Clipperz.Async.callbacks("User.Header.RecordIndex.revertChanges", [ | 481 | return Clipperz.Async.callbacks("User.Header.RecordIndex.revertChanges", [ |
498 | MochiKit.Base.method(this, 'recordsData'), | 482 | MochiKit.Base.method(this, 'recordsData'), |
499 | MochiKit.Base.methodcaller('revertChanges'), | 483 | MochiKit.Base.methodcaller('revertChanges'), |
500 | 484 | ||
501 | // MochiKit.Base.method(this, 'directLoginsData'), | 485 | // MochiKit.Base.method(this, 'directLoginsData'), |
502 | // MochiKit.Base.methodcaller('revertChanges'), | 486 | // MochiKit.Base.methodcaller('revertChanges'), |
503 | 487 | ||
504 | MochiKit.Base.method(this, 'records'), | 488 | MochiKit.Base.method(this, 'records'), |
505 | MochiKit.Base.bind(function (someRecords) { | 489 | MochiKit.Base.bind(function (someRecords) { |
506 | varrecordReference; | 490 | varrecordReference; |
507 | 491 | ||
508 | for (recordReference in this.transientState().getValue('deleteRecordsReferences')) { | 492 | for (recordReference in this.transientState().getValue('deleteRecordsReferences')) { |
509 | this.recordsIndex()[recordReference] = this.transientState().getValue('deleteRecordsIndex' + '.' + recordReference); | 493 | this.recordsIndex()[recordReference] = this.transientState().getValue('deleteRecordsIndex' + '.' + recordReference); |
510 | someRecords[recordReference] = this.transientState().getValue('deleteRecordsReferences' + '.' + recordReference); | 494 | someRecords[recordReference] = this.transientState().getValue('deleteRecordsReferences' + '.' + recordReference); |
511 | } | 495 | } |
512 | 496 | ||
513 | for (recordReference in this.transientState().getValue('newRecordsReferences')) { | 497 | for (recordReference in this.transientState().getValue('newRecordsReferences')) { |
514 | delete this.recordsIndex()[recordReference]; | 498 | delete this.recordsIndex()[recordReference]; |
515 | delete someRecords[recordReference]; | 499 | delete someRecords[recordReference]; |
516 | } | 500 | } |
517 | }, this), | 501 | }, this), |
518 | 502 | ||
519 | // MochiKit.Base.method(this, 'directLogins'), | 503 | // MochiKit.Base.method(this, 'directLogins'), |
520 | MochiKit.Base.bind(function () { | 504 | MochiKit.Base.bind(function () { |
521 | vardirectLoginReference; | 505 | vardirectLoginReference; |
522 | 506 | ||
523 | //this.transientState().setValue('newDirectLoginReferences' + '.' + newDirectLogin.reference(), newDirectLogin); | 507 | //this.transientState().setValue('newDirectLoginReferences' + '.' + newDirectLogin.reference(), newDirectLogin); |
524 | // | 508 | // |
525 | //this.directLoginsIndex()[newDirectLogin.reference()] = newDirectLoginIndexValue; | 509 | //this.directLoginsIndex()[newDirectLogin.reference()] = newDirectLoginIndexValue; |
526 | //this.directLoginsData().setValue(this.directLoginsIndex()[newDirectLogin.reference()], {'record': this.recordsIndex()[aRecord.reference()]}); | 510 | //this.directLoginsData().setValue(this.directLoginsIndex()[newDirectLogin.reference()], {'record': this.recordsIndex()[aRecord.reference()]}); |
527 | 511 | ||
528 | 512 | ||
529 | // for (directLoginReference in this.transientState().getValue('deleteDirectLoginReferences')) { | 513 | // for (directLoginReference in this.transientState().getValue('deleteDirectLoginReferences')) { |
530 | // someDirectLogins[directLoginReference] = this.transientState().getValue('deleteDirectLoginReferences' + '.' + recordReference); | 514 | // someDirectLogins[directLoginReference] = this.transientState().getValue('deleteDirectLoginReferences' + '.' + recordReference); |
531 | // } | 515 | // } |
532 | 516 | ||
533 | for (directLoginReference in this.transientState().getValue('newDirectLoginReferences')) { | 517 | for (directLoginReference in this.transientState().getValue('newDirectLoginReferences')) { |
534 | // this.directLoginsData().removeValue(this.directLoginsIndex()[directLoginReference]); | 518 | // this.directLoginsData().removeValue(this.directLoginsIndex()[directLoginReference]); |
535 | delete this.directLoginsIndex()[directLoginReference]; | 519 | delete this.directLoginsIndex()[directLoginReference]; |
536 | } | 520 | } |
537 | }, this), | 521 | }, this), |
538 | 522 | ||
539 | MochiKit.Base.method(this, 'directLoginsData'), | 523 | MochiKit.Base.method(this, 'directLoginsData'), |
540 | MochiKit.Base.methodcaller('revertChanges'), | 524 | MochiKit.Base.methodcaller('revertChanges'), |
541 | 525 | ||
542 | MochiKit.Base.method(this, 'resetTransientState', false) | 526 | MochiKit.Base.method(this, 'resetTransientState', false) |
543 | ], {trace:false}); | 527 | ], {trace:false}); |
544 | }, | 528 | }, |
545 | 529 | ||
546 | //------------------------------------------------------------------------- | 530 | //------------------------------------------------------------------------- |
547 | 531 | ||
548 | 'prepareRemoteDataWithKey': function (aKey) { | 532 | 'prepareRemoteDataWithKey': function (aKey) { |
549 | // "records": { | 533 | // "records": { |
550 | // "index": { | 534 | // "index": { |
551 | // "eeda70e0392261967bda71c3764da78989c45bbd2bb7be6b941b90f81d9b81b5": "0", | 535 | // "eeda70e0392261967bda71c3764da78989c45bbd2bb7be6b941b90f81d9b81b5": "0", |
552 | // "13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551": "1", | 536 | // "13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551": "1", |
553 | // ... | 537 | // ... |
554 | // "465a067a0bd2b470fa834de5397e38494de0c7707938262fae3427932e219744": "18", | 538 | // "465a067a0bd2b470fa834de5397e38494de0c7707938262fae3427932e219744": "18", |
555 | // "4fd1dc2ca860b7fb47cef10a84edb3270da05510b0a30a6b0b083898712d4b9e": "19" | 539 | // "4fd1dc2ca860b7fb47cef10a84edb3270da05510b0a30a6b0b083898712d4b9e": "19" |
556 | // }, | 540 | // }, |
557 | // "data": "n+AzGEEQXaSRSY4d ... BDypotrXgPo94uHfoXvGFzwCn8w=" | 541 | // "data": "n+AzGEEQXaSRSY4d ... BDypotrXgPo94uHfoXvGFzwCn8w=" |
558 | // }, | 542 | // }, |
559 | // "directLogins": { | 543 | // "directLogins": { |
560 | // "index": { | 544 | // "index": { |
561 | // "61e87fdc4f1d9112e3b30c1f6812d095dcdb24f014c83319091eb6c9899ec348":"0", | 545 | // "61e87fdc4f1d9112e3b30c1f6812d095dcdb24f014c83319091eb6c9899ec348":"0", |
562 | // "989593d4c48929f0c8f1581aa96969c622807e99619ed4732026e967530a68ad":"1", | 546 | // "989593d4c48929f0c8f1581aa96969c622807e99619ed4732026e967530a68ad":"1", |
563 | // ... | 547 | // ... |
564 | // "cb9ae0bba1957075ccdbfd3b3481704d62087687a2ac7c411a4f07d444bde0f7":"17", | 548 | // "cb9ae0bba1957075ccdbfd3b3481704d62087687a2ac7c411a4f07d444bde0f7":"17", |
565 | // "7e1d069b7fa57c03bd7bf48807520feb953157834503aaff8c9d493f37dea69d":"18" | 549 | // "7e1d069b7fa57c03bd7bf48807520feb953157834503aaff8c9d493f37dea69d":"18" |
566 | // }, | 550 | // }, |
567 | // "data":"5YG9KKU/OZ5guUgFlms6k1 ... ZG/5Fn0uN+LoAsNfHm+EE62x" | 551 | // "data":"5YG9KKU/OZ5guUgFlms6k1 ... ZG/5Fn0uN+LoAsNfHm+EE62x" |
568 | // }, | 552 | // }, |
569 | 553 | ||
570 | var deferredResult; | 554 | var deferredResult; |
571 | var result; | 555 | var result; |
572 | 556 | ||
573 | //console.log("recordsIndex", this.recordsIndex()); | ||
574 | result = {}; | 557 | result = {}; |
575 | 558 | ||
576 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.prepareRemoteDataWithKey", {trace:false}); | 559 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.prepareRemoteDataWithKey", {trace:false}); |
577 | deferredResult.collectResults({ | 560 | deferredResult.collectResults({ |
578 | 'index':MochiKit.Base.partial(MochiKit.Async.succeed, this.recordsIndex()), | 561 | 'index':MochiKit.Base.partial(MochiKit.Async.succeed, this.recordsIndex()), |
579 | 'data': [ | 562 | 'data': [ |
580 | MochiKit.Base.method(this.recordsData(), 'prepareRemoteDataWithKey', aKey), | 563 | MochiKit.Base.method(this.recordsData(), 'prepareRemoteDataWithKey', aKey), |
581 | MochiKit.Base.itemgetter('data') | 564 | MochiKit.Base.itemgetter('data') |
582 | ] | 565 | ] |
583 | }); | 566 | }); |
584 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'records'); | 567 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'records'); |
585 | 568 | ||
586 | deferredResult.collectResults({ | 569 | deferredResult.collectResults({ |
587 | 'index':MochiKit.Base.partial(MochiKit.Async.succeed, this.directLoginsIndex()), | 570 | 'index':MochiKit.Base.partial(MochiKit.Async.succeed, this.directLoginsIndex()), |
588 | 'data': [ | 571 | 'data': [ |
589 | MochiKit.Base.method(this.directLoginsData(), 'prepareRemoteDataWithKey', aKey), | 572 | MochiKit.Base.method(this.directLoginsData(), 'prepareRemoteDataWithKey', aKey), |
590 | MochiKit.Base.itemgetter('data') | 573 | MochiKit.Base.itemgetter('data') |
591 | ] | 574 | ] |
592 | }); | 575 | }); |
593 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'directLogins'); | 576 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'directLogins'); |
594 | 577 | ||
595 | deferredResult.addCallback(MochiKit.Async.succeed, result); | 578 | deferredResult.addCallback(MochiKit.Async.succeed, result); |
596 | 579 | ||
597 | deferredResult.callback(); | 580 | deferredResult.callback(); |
598 | 581 | ||
599 | return deferredResult; | 582 | return deferredResult; |
600 | }, | 583 | }, |
601 | 584 | ||
602 | //------------------------------------------------------------------------- | 585 | //------------------------------------------------------------------------- |
603 | 586 | ||
604 | 'updateRecordKeyAndPrepareRemoteData': function (aRecord) { | 587 | 'updateRecordKeyAndPrepareRemoteData': function (aRecord) { |
605 | varnewRecordKey; | 588 | varnewRecordKey; |
606 | var deferredResult; | 589 | var deferredResult; |
607 | 590 | ||
608 | newRecordKey = Clipperz.PM.Crypto.randomKey(); | 591 | newRecordKey = Clipperz.PM.Crypto.randomKey(); |
609 | 592 | ||
610 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.updateRecordKeyAndPrepareRemoteData", {trace:false}); | 593 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.updateRecordKeyAndPrepareRemoteData", {trace:false}); |
611 | deferredResult.addCallback(MochiKit.Base.method(aRecord, 'prepareRemoteDataWithKey', newRecordKey)); | 594 | deferredResult.addCallback(MochiKit.Base.method(aRecord, 'prepareRemoteDataWithKey', newRecordKey)); |
612 | deferredResult.addCallbackPass(MochiKit.Base.method(this, 'setRecordKey', aRecord.reference(), newRecordKey)); | 595 | deferredResult.addCallbackPass(MochiKit.Base.method(this, 'setRecordKey', aRecord.reference(), newRecordKey)); |
613 | deferredResult.callback(); | 596 | deferredResult.callback(); |
614 | 597 | ||
615 | return deferredResult; | 598 | return deferredResult; |
616 | }, | 599 | }, |
617 | 600 | ||
618 | //......................................................................... | 601 | //......................................................................... |
619 | 602 | ||
620 | 'removeNewRecordWithNoChanges': function (aRecord) { | 603 | 'removeNewRecordWithNoChanges': function (aRecord) { |
621 | var deferredResult; | 604 | var deferredResult; |
622 | var recordReference; | 605 | var recordReference; |
623 | 606 | ||
624 | recordReference = aRecord.reference(); | 607 | recordReference = aRecord.reference(); |
625 | 608 | ||
626 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.removeNewRecordWithNoChanges", {trace:false}); | 609 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.removeNewRecordWithNoChanges", {trace:false}); |
627 | 610 | ||
628 | deferredResult.addMethod(this.recordsData(), 'removeValue', this.recordsIndex()[recordReference]); | 611 | deferredResult.addMethod(this.recordsData(), 'removeValue', this.recordsIndex()[recordReference]); |
629 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 612 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
630 | delete this.recordsIndex()[recordReference]; | 613 | delete this.recordsIndex()[recordReference]; |
631 | }, this)); | 614 | }, this)); |
632 | 615 | ||
633 | deferredResult.addMethod(this, 'records'); | 616 | deferredResult.addMethod(this, 'records'); |
634 | deferredResult.addCallback(MochiKit.Base.bind(function (someRecords) { | 617 | deferredResult.addCallback(MochiKit.Base.bind(function (someRecords) { |
635 | delete someRecords[recordReference]; | 618 | delete someRecords[recordReference]; |
636 | }, this)); | 619 | }, this)); |
637 | deferredResult.callback(); | 620 | deferredResult.callback(); |
638 | 621 | ||
639 | return deferredResult; | 622 | return deferredResult; |
640 | }, | 623 | }, |
641 | 624 | ||
642 | //......................................................................... | 625 | //......................................................................... |
643 | 626 | ||
644 | 'prepareRemoteDataForChangedRecords': function () { | 627 | 'prepareRemoteDataForChangedRecords': function () { |
645 | vardeferredResult; | 628 | vardeferredResult; |
646 | varresult; | 629 | varresult; |
647 | 630 | ||
648 | result = {}; | 631 | result = {}; |
649 | 632 | ||
650 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.prepareRemoteDataForChangedRecords", {trace:false}); | 633 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.prepareRemoteDataForChangedRecords", {trace:false}); |
651 | 634 | ||
652 | deferredResult.addMethod(this, 'records'); | 635 | deferredResult.addMethod(this, 'records'); |
653 | deferredResult.addCallback(MochiKit.Base.values); | 636 | deferredResult.addCallback(MochiKit.Base.values); |
654 | deferredResult.addCallback(Clipperz.Async.deferredFilter, MochiKit.Base.methodcaller('isBrandNewWithNoPendingChanges')); | 637 | deferredResult.addCallback(Clipperz.Async.deferredFilter, MochiKit.Base.methodcaller('isBrandNewWithNoPendingChanges')); |
655 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'removeNewRecordWithNoChanges')); | 638 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'removeNewRecordWithNoChanges')); |
656 | 639 | ||
657 | deferredResult.addMethod(this, 'records'); | 640 | deferredResult.addMethod(this, 'records'); |
658 | deferredResult.addCallback(MochiKit.Base.values); | 641 | deferredResult.addCallback(MochiKit.Base.values); |
659 | deferredResult.addCallback(Clipperz.Async.deferredFilter, MochiKit.Base.methodcaller('hasPendingChanges')); | 642 | deferredResult.addCallback(Clipperz.Async.deferredFilter, MochiKit.Base.methodcaller('hasPendingChanges')); |
660 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'updateRecordKeyAndPrepareRemoteData')); | 643 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'updateRecordKeyAndPrepareRemoteData')); |
661 | deferredResult.addCallback(Clipperz.Async.collectAll); | 644 | deferredResult.addCallback(Clipperz.Async.collectAll); |
662 | 645 | ||
663 | deferredResult.addCallback(Clipperz.Async.deferredIf("updated records != null", [ | 646 | deferredResult.addCallback(Clipperz.Async.deferredIf("updated records != null", [ |
664 | MochiKit.Base.operator.identity | 647 | MochiKit.Base.operator.identity |
665 | ], [ | 648 | ], [ |
666 | MochiKit.Base.partial(MochiKit.Async.succeed, []) | 649 | MochiKit.Base.partial(MochiKit.Async.succeed, []) |
667 | ])); | 650 | ])); |
668 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'updated'); | 651 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'updated'); |
669 | 652 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.js index 646ce21..fd18faf 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.js | |||
@@ -1,118 +1,116 @@ | |||
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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | 28 | ||
31 | //############################################################################# | 29 | //############################################################################# |
32 | 30 | ||
33 | Clipperz.PM.DataModel.User = function (args) { | 31 | Clipperz.PM.DataModel.User = function (args) { |
34 | args = args || {}; | 32 | args = args || {}; |
35 | 33 | ||
36 | Clipperz.PM.DataModel.User.superclass.constructor.apply(this, arguments); | 34 | Clipperz.PM.DataModel.User.superclass.constructor.apply(this, arguments); |
37 | 35 | ||
38 | this._username = args.username || null; | 36 | this._username = args.username || null; |
39 | this._getPassphraseFunction = args.getPassphraseFunction || null; | 37 | this._getPassphraseFunction = args.getPassphraseFunction || null; |
40 | 38 | ||
41 | this._data = null; | 39 | this._data = null; |
42 | 40 | ||
43 | this._connection = null; | 41 | this._connection = null; |
44 | this._connectionVersion = 'current'; | 42 | this._connectionVersion = 'current'; |
45 | 43 | ||
46 | this._serverData = null; | 44 | this._serverData = null; |
47 | //this._serverLockValue = null; | 45 | //this._serverLockValue = null; |
48 | this._transientState = null; | 46 | this._transientState = null; |
49 | 47 | ||
50 | this._deferredLocks = { | 48 | this._deferredLocks = { |
51 | 'passphrase': new MochiKit.Async.DeferredLock(), | 49 | 'passphrase': new MochiKit.Async.DeferredLock(), |
52 | 'serverData': new MochiKit.Async.DeferredLock(), | 50 | 'serverData': new MochiKit.Async.DeferredLock(), |
53 | // 'recordsIndex': new MochiKit.Async.DeferredLock(), | 51 | // 'recordsIndex': new MochiKit.Async.DeferredLock(), |
54 | // 'directLoginsIndex':new MochiKit.Async.DeferredLock() | 52 | // 'directLoginsIndex':new MochiKit.Async.DeferredLock() |
55 | // 'preferences': new MochiKit.Async.DeferredLock() | 53 | // 'preferences': new MochiKit.Async.DeferredLock() |
56 | // 'oneTimePasswords': new MochiKit.Async.DeferredLock() | 54 | // 'oneTimePasswords': new MochiKit.Async.DeferredLock() |
57 | '__syntaxFix__': 'syntax fix' | 55 | '__syntaxFix__': 'syntax fix' |
58 | }; | 56 | }; |
59 | 57 | ||
60 | return this; | 58 | return this; |
61 | } | 59 | } |
62 | 60 | ||
63 | Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { | 61 | Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { |
64 | 62 | ||
65 | 'toString': function () { | 63 | 'toString': function () { |
66 | return "Clipperz.PM.DataModel.User - " + this.username(); | 64 | return "Clipperz.PM.DataModel.User - " + this.username(); |
67 | }, | 65 | }, |
68 | 66 | ||
69 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
70 | 68 | ||
71 | 'username': function () { | 69 | 'username': function () { |
72 | return this._username; | 70 | return this._username; |
73 | }, | 71 | }, |
74 | 72 | ||
75 | 'setUsername': function (aValue) { | 73 | 'setUsername': function (aValue) { |
76 | this._username = aValue; | 74 | this._username = aValue; |
77 | }, | 75 | }, |
78 | 76 | ||
79 | //------------------------------------------------------------------------- | 77 | //------------------------------------------------------------------------- |
80 | 78 | ||
81 | 'displayName': function() { | 79 | 'displayName': function() { |
82 | return "" + this.username() + ""; | 80 | return "" + this.username() + ""; |
83 | }, | 81 | }, |
84 | 82 | ||
85 | //------------------------------------------------------------------------- | 83 | //------------------------------------------------------------------------- |
86 | 84 | ||
87 | 'data': function () { | 85 | 'data': function () { |
88 | if (this._data == null) { | 86 | if (this._data == null) { |
89 | this._data = new Clipperz.KeyValueObjectStore(/*{'name':'User.data [1]'}*/); | 87 | this._data = new Clipperz.KeyValueObjectStore(/*{'name':'User.data [1]'}*/); |
90 | }; | 88 | }; |
91 | 89 | ||
92 | return this._data; | 90 | return this._data; |
93 | }, | 91 | }, |
94 | 92 | ||
95 | //------------------------------------------------------------------------- | 93 | //------------------------------------------------------------------------- |
96 | /* | 94 | /* |
97 | 'serverLockValue': function () { | 95 | 'serverLockValue': function () { |
98 | return this._serverLockValue; | 96 | return this._serverLockValue; |
99 | }, | 97 | }, |
100 | 98 | ||
101 | 'setServerLockValue': function (aValue) { | 99 | 'setServerLockValue': function (aValue) { |
102 | this._serverLockValue = aValue; | 100 | this._serverLockValue = aValue; |
103 | }, | 101 | }, |
104 | */ | 102 | */ |
105 | //------------------------------------------------------------------------- | 103 | //------------------------------------------------------------------------- |
106 | 104 | ||
107 | 'transientState': function () { | 105 | 'transientState': function () { |
108 | if (this._transientState == null) { | 106 | if (this._transientState == null) { |
109 | this._transientState = {} | 107 | this._transientState = {} |
110 | } | 108 | } |
111 | 109 | ||
112 | return this._transientState; | 110 | return this._transientState; |
113 | }, | 111 | }, |
114 | 112 | ||
115 | 'resetTransientState': function (isCommitting) { | 113 | 'resetTransientState': function (isCommitting) { |
116 | this._transientState = null; | 114 | this._transientState = null; |
117 | }, | 115 | }, |
118 | 116 | ||
@@ -235,282 +233,280 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { | |||
235 | 233 | ||
236 | 'login': function () { | 234 | 'login': function () { |
237 | var deferredResult; | 235 | var deferredResult; |
238 | 236 | ||
239 | deferredResult = new Clipperz.Async.Deferred("User.login", {trace:false}); | 237 | deferredResult = new Clipperz.Async.Deferred("User.login", {trace:false}); |
240 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'updateProgress', {'extraSteps':3}); | 238 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'updateProgress', {'extraSteps':3}); |
241 | deferredResult.addMethod(this, 'getPassphrase'); | 239 | deferredResult.addMethod(this, 'getPassphrase'); |
242 | deferredResult.addCallback(Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue); | 240 | deferredResult.addCallback(Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue); |
243 | deferredResult.addCallback(Clipperz.Async.deferredIf("Is the passphrase an OTP", [ | 241 | deferredResult.addCallback(Clipperz.Async.deferredIf("Is the passphrase an OTP", [ |
244 | MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'updateProgress', {'extraSteps':1}), | 242 | MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'updateProgress', {'extraSteps':1}), |
245 | MochiKit.Base.method(this, 'getCredentials'), | 243 | MochiKit.Base.method(this, 'getCredentials'), |
246 | MochiKit.Base.method(this.connection(), 'redeemOneTimePassword'), | 244 | MochiKit.Base.method(this.connection(), 'redeemOneTimePassword'), |
247 | MochiKit.Base.method(this.data(), 'setValue', 'passphrase') | 245 | MochiKit.Base.method(this.data(), 'setValue', 'passphrase') |
248 | ], [])); | 246 | ], [])); |
249 | deferredResult.addErrback(MochiKit.Base.method(this, 'getPassphrase')); | 247 | deferredResult.addErrback(MochiKit.Base.method(this, 'getPassphrase')); |
250 | deferredResult.addMethod(this.connection(), 'login', false); | 248 | deferredResult.addMethod(this.connection(), 'login', false); |
251 | deferredResult.addCallbackPass(MochiKit.Signal.signal,Clipperz.Signal.NotificationCenter, 'userSuccessfullyLoggedIn'); | 249 | deferredResult.addCallbackPass(MochiKit.Signal.signal,Clipperz.Signal.NotificationCenter, 'userSuccessfullyLoggedIn'); |
252 | deferredResult.addErrback (MochiKit.Base.method(this, 'handleConnectionFallback')); | 250 | deferredResult.addErrback (MochiKit.Base.method(this, 'handleConnectionFallback')); |
253 | 251 | ||
254 | deferredResult.callback(); | 252 | deferredResult.callback(); |
255 | 253 | ||
256 | return deferredResult; | 254 | return deferredResult; |
257 | }, | 255 | }, |
258 | 256 | ||
259 | //......................................................................... | 257 | //......................................................................... |
260 | 258 | ||
261 | 'handleConnectionFallback': function(aValue) { | 259 | 'handleConnectionFallback': function(aValue) { |
262 | var result; | 260 | var result; |
263 | 261 | ||
264 | if (aValue instanceof MochiKit.Async.CancelledError) { | 262 | if (aValue instanceof MochiKit.Async.CancelledError) { |
265 | result = aValue; | 263 | result = aValue; |
266 | } else { | 264 | } else { |
267 | this.setConnectionVersion(Clipperz.PM.Connection.communicationProtocol.fallbackVersions[this.connectionVersion()]); | 265 | this.setConnectionVersion(Clipperz.PM.Connection.communicationProtocol.fallbackVersions[this.connectionVersion()]); |
268 | 266 | ||
269 | if (this.connectionVersion() != null) { | 267 | if (this.connectionVersion() != null) { |
270 | result = new Clipperz.Async.Deferred("User.handleConnectionFallback - retry"); | 268 | result = new Clipperz.Async.Deferred("User.handleConnectionFallback - retry"); |
271 | 269 | ||
272 | result.addMethod(this, 'login'); | 270 | result.addMethod(this, 'login'); |
273 | result.callback(); | 271 | result.callback(); |
274 | } else { | 272 | } else { |
275 | result = Clipperz.Async.callbacks("User.handleConnectionFallback - failed", [ | 273 | result = Clipperz.Async.callbacks("User.handleConnectionFallback - failed", [ |
276 | MochiKit.Base.method(this.data(), 'removeValue', 'passphrase'), | 274 | MochiKit.Base.method(this.data(), 'removeValue', 'passphrase'), |
277 | MochiKit.Base.method(this, 'setConnectionVersion', 'current'), | 275 | MochiKit.Base.method(this, 'setConnectionVersion', 'current'), |
278 | MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'userLoginFailed'), | 276 | MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'userLoginFailed'), |
279 | MochiKit.Base.partial(MochiKit.Async.fail, Clipperz.PM.DataModel.User.exception.LoginFailed) | 277 | MochiKit.Base.partial(MochiKit.Async.fail, Clipperz.PM.DataModel.User.exception.LoginFailed) |
280 | ], {trace:false}); | 278 | ], {trace:false}); |
281 | } | 279 | } |
282 | } | 280 | } |
283 | 281 | ||
284 | return result; | 282 | return result; |
285 | }, | 283 | }, |
286 | 284 | ||
287 | //------------------------------------------------------------------------- | 285 | //------------------------------------------------------------------------- |
288 | 286 | ||
289 | 'lock': function () { | 287 | 'lock': function () { |
290 | return Clipperz.Async.callbacks("User.lock", [ | 288 | return Clipperz.Async.callbacks("User.lock", [ |
291 | MochiKit.Base.method(this, 'deleteAllCleanTextData') | 289 | MochiKit.Base.method(this, 'deleteAllCleanTextData') |
292 | ], {trace:false}); | 290 | ], {trace:false}); |
293 | }, | 291 | }, |
294 | 292 | ||
295 | //------------------------------------------------------------------------- | 293 | //------------------------------------------------------------------------- |
296 | 294 | ||
297 | 'logout': function () { | 295 | 'logout': function () { |
298 | return Clipperz.Async.callbacks("User.logout", [ | 296 | return Clipperz.Async.callbacks("User.logout", [ |
299 | MochiKit.Base.method(this, 'deleteAllCleanTextData'), | 297 | MochiKit.Base.method(this, 'deleteAllCleanTextData'), |
300 | MochiKit.Base.method(this.connection(), 'logout') | 298 | MochiKit.Base.method(this.connection(), 'logout') |
301 | ], {trace:false}); | 299 | ], {trace:false}); |
302 | }, | 300 | }, |
303 | 301 | ||
304 | //------------------------------------------------------------------------- | 302 | //------------------------------------------------------------------------- |
305 | 303 | ||
306 | 'headerFormatVersion': function(anHeader) { | 304 | 'headerFormatVersion': function(anHeader) { |
307 | var result; | 305 | var result; |
308 | 306 | ||
309 | if (anHeader.charAt(0) == '{') { | 307 | if (anHeader.charAt(0) == '{') { |
310 | varheaderData; | 308 | varheaderData; |
311 | 309 | ||
312 | headerData = Clipperz.Base.evalJSON(anHeader); | 310 | headerData = Clipperz.Base.evalJSON(anHeader); |
313 | result = headerData['version']; | 311 | result = headerData['version']; |
314 | } else { | 312 | } else { |
315 | result = 'LEGACY'; | 313 | result = 'LEGACY'; |
316 | } | 314 | } |
317 | 315 | ||
318 | return result; | 316 | return result; |
319 | }, | 317 | }, |
320 | 318 | ||
321 | //------------------------------------------------------------------------- | 319 | //------------------------------------------------------------------------- |
322 | 320 | ||
323 | 'unpackServerData': function (someServerData) { | 321 | 'unpackServerData': function (someServerData) { |
324 | var unpackedData; | 322 | var unpackedData; |
325 | var headerVersion; | 323 | var headerVersion; |
326 | 324 | ||
327 | varrecordsIndex; | 325 | varrecordsIndex; |
328 | var preferences; | 326 | var preferences; |
329 | var oneTimePasswords; | 327 | var oneTimePasswords; |
330 | 328 | ||
331 | //console.log(">>> ***************** user.unpackServerData", someServerData); | ||
332 | // this.setServerLockValue(someServerData['lock']); | 329 | // this.setServerLockValue(someServerData['lock']); |
333 | 330 | ||
334 | headerVersion = this.headerFormatVersion(someServerData['header']); | 331 | headerVersion = this.headerFormatVersion(someServerData['header']); |
335 | 332 | ||
336 | switch (headerVersion) { | 333 | switch (headerVersion) { |
337 | case 'LEGACY': | 334 | case 'LEGACY': |
338 | varlegacyHeader; | 335 | varlegacyHeader; |
339 | 336 | ||
340 | legacyHeader = new Clipperz.PM.DataModel.User.Header.Legacy({ | 337 | legacyHeader = new Clipperz.PM.DataModel.User.Header.Legacy({ |
341 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), | 338 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), |
342 | 'remoteData': { | 339 | 'remoteData': { |
343 | 'data': someServerData['header'], | 340 | 'data': someServerData['header'], |
344 | 'version': someServerData['version'], | 341 | 'version': someServerData['version'], |
345 | 'recordsStats': someServerData['recordsStats'] | 342 | 'recordsStats': someServerData['recordsStats'] |
346 | }, | 343 | }, |
347 | // 'encryptedDataKeypath': 'data', | 344 | // 'encryptedDataKeypath': 'data', |
348 | // 'encryptedVersionKeypath': 'version', | 345 | // 'encryptedVersionKeypath': 'version', |
349 | 'retrieveRecordDetailFunction':MochiKit.Base.method(this, 'getRecordDetail') | 346 | 'retrieveRecordDetailFunction':MochiKit.Base.method(this, 'getRecordDetail') |
350 | }); | 347 | }); |
351 | 348 | ||
352 | recordsIndex = legacyHeader; | 349 | recordsIndex = legacyHeader; |
353 | preferences = legacyHeader; | 350 | preferences = legacyHeader; |
354 | oneTimePasswords= legacyHeader; | 351 | oneTimePasswords= legacyHeader; |
355 | break; | 352 | break; |
356 | case '0.1': | 353 | case '0.1': |
357 | varheaderData; | 354 | varheaderData; |
358 | 355 | ||
359 | headerData = Clipperz.Base.evalJSON(someServerData['header']); | 356 | headerData = Clipperz.Base.evalJSON(someServerData['header']); |
360 | 357 | ||
361 | recordsIndex = new Clipperz.PM.DataModel.User.Header.RecordIndex({ | 358 | recordsIndex = new Clipperz.PM.DataModel.User.Header.RecordIndex({ |
362 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), | 359 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), |
363 | 'recordsData': headerData['records'], | 360 | 'recordsData': headerData['records'], |
364 | 'recordsStats': someServerData['recordsStats'], | 361 | 'recordsStats': someServerData['recordsStats'], |
365 | 'directLoginsData': headerData['directLogins'], | 362 | 'directLoginsData': headerData['directLogins'], |
366 | 'encryptedDataVersion': someServerData['version'], | 363 | 'encryptedDataVersion': someServerData['version'], |
367 | 'retrieveRecordDetailFunction':MochiKit.Base.method(this, 'getRecordDetail') | 364 | 'retrieveRecordDetailFunction':MochiKit.Base.method(this, 'getRecordDetail') |
368 | }); | 365 | }); |
369 | 366 | ||
370 | //Still missing a test case that actually fais with the old version of the code, where the check for undefined was missing | 367 | //Still missing a test case that actually fais with the old version of the code, where the check for undefined was missing |
371 | if (typeof(headerData['preferences']) != 'undefined') { | 368 | if (typeof(headerData['preferences']) != 'undefined') { |
372 | preferences= new Clipperz.PM.DataModel.User.Header.Preferences({ | 369 | preferences= new Clipperz.PM.DataModel.User.Header.Preferences({ |
373 | 'name':'preferences', | 370 | 'name':'preferences', |
374 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), | 371 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), |
375 | 'remoteData': { | 372 | 'remoteData': { |
376 | 'data': headerData['preferences']['data'], | 373 | 'data': headerData['preferences']['data'], |
377 | 'version': someServerData['version'] | 374 | 'version': someServerData['version'] |
378 | } | 375 | } |
379 | }); | 376 | }); |
380 | } else { | 377 | } else { |
381 | preferences= new Clipperz.PM.DataModel.User.Header.Preferences({ | 378 | preferences= new Clipperz.PM.DataModel.User.Header.Preferences({ |
382 | 'name':'preferences', | 379 | 'name':'preferences', |
383 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') | 380 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') |
384 | }); | 381 | }); |
385 | } | 382 | } |
386 | 383 | ||
387 | if (typeof(headerData['oneTimePasswords']) != 'undefined') { | 384 | if (typeof(headerData['oneTimePasswords']) != 'undefined') { |
388 | oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({ | 385 | oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({ |
389 | 'name':'preferences', | 386 | 'name':'preferences', |
390 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), | 387 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), |
391 | 'remoteData': { | 388 | 'remoteData': { |
392 | 'data': headerData['oneTimePasswords']['data'], | 389 | 'data': headerData['oneTimePasswords']['data'], |
393 | 'version': someServerData['version'] | 390 | 'version': someServerData['version'] |
394 | } | 391 | } |
395 | }); | 392 | }); |
396 | } else { | 393 | } else { |
397 | oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({ | 394 | oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({ |
398 | 'name':'preferences', | 395 | 'name':'preferences', |
399 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') | 396 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') |
400 | }); | 397 | }); |
401 | } | 398 | } |
402 | 399 | ||
403 | break; | 400 | break; |
404 | } | 401 | } |
405 | 402 | ||
406 | unpackedData = { | 403 | unpackedData = { |
407 | 'version': someServerData['version'], | 404 | 'version': someServerData['version'], |
408 | 'statistics': someServerData['statistics'], | 405 | 'statistics': someServerData['statistics'], |
409 | 'header': { | 406 | 'header': { |
410 | 'data': someServerData['header'], | 407 | 'data': someServerData['header'], |
411 | 'version': headerVersion, | 408 | 'version': headerVersion, |
412 | 409 | ||
413 | 'recordsIndex': recordsIndex, | 410 | 'recordsIndex': recordsIndex, |
414 | 'preferences': preferences, | 411 | 'preferences': preferences, |
415 | 'oneTimePasswords': oneTimePasswords | 412 | 'oneTimePasswords': oneTimePasswords |
416 | } | 413 | } |
417 | }; | 414 | }; |
418 | 415 | ||
419 | this._serverData = unpackedData; | 416 | this._serverData = unpackedData; |
420 | //console.log("<<< ***************** user.unpackServerData", this._serverData); | ||
421 | 417 | ||
422 | return this._serverData; | 418 | return this._serverData; |
423 | }, | 419 | }, |
424 | 420 | ||
425 | //------------------------------------------------------------------------- | 421 | //------------------------------------------------------------------------- |
426 | 422 | ||
427 | 'getServerData': function() { | 423 | 'getServerData': function() { |
428 | var deferredResult; | 424 | var deferredResult; |
429 | 425 | ||
430 | deferredResult = new Clipperz.Async.Deferred("User.getServerData", {trace:false}); | 426 | deferredResult = new Clipperz.Async.Deferred("User.getServerData", {trace:false}); |
431 | deferredResult.acquireLock(this.deferredLockForSection('serverData')); | 427 | deferredResult.acquireLock(this.deferredLockForSection('serverData')); |
432 | deferredResult.addCallback(MochiKit.Base.bind(function(aResult) { | 428 | deferredResult.addCallback(MochiKit.Base.bind(function(aResult) { |
433 | var innerDeferredResult; | 429 | var innerDeferredResult; |
434 | 430 | ||
435 | innerDeferredResult = new Clipperz.Async.Deferred("User.getUserDetails.innerDeferred", {trace:false}); | 431 | innerDeferredResult = new Clipperz.Async.Deferred("User.getUserDetails.innerDeferred", {trace:false}); |
436 | if (this._serverData == null) { | 432 | if (this._serverData == null) { |
437 | innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadingUserDetails'); | 433 | innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadingUserDetails'); |
438 | innerDeferredResult.addMethod(this.connection(), 'message', 'getUserDetails'); | 434 | innerDeferredResult.addMethod(this.connection(), 'message', 'getUserDetails'); |
439 | innerDeferredResult.addMethod(this, 'unpackServerData'); | 435 | innerDeferredResult.addMethod(this, 'unpackServerData'); |
440 | innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadedUserDetails'); | 436 | innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadedUserDetails'); |
441 | } | 437 | } |
442 | 438 | ||
443 | innerDeferredResult.addCallback(MochiKit.Base.bind(function () { | 439 | innerDeferredResult.addCallback(MochiKit.Base.bind(function () { |
444 | return this._serverData; | 440 | return this._serverData; |
445 | },this)); | 441 | },this)); |
446 | innerDeferredResult.callback(); | 442 | innerDeferredResult.callback(); |
447 | 443 | ||
448 | return innerDeferredResult; | 444 | return innerDeferredResult; |
449 | }, this)); | 445 | }, this)); |
450 | deferredResult.releaseLock(this.deferredLockForSection('serverData')); | 446 | deferredResult.releaseLock(this.deferredLockForSection('serverData')); |
451 | deferredResult.callback(); | 447 | deferredResult.callback(); |
452 | 448 | ||
453 | return deferredResult; | 449 | return deferredResult; |
454 | }, | 450 | }, |
455 | 451 | ||
456 | //------------------------------------------------------------------------- | 452 | //------------------------------------------------------------------------- |
457 | 453 | ||
458 | 'connectionVersion': function() { | 454 | 'connectionVersion': function() { |
459 | return this._connectionVersion; | 455 | return this._connectionVersion; |
460 | }, | 456 | }, |
461 | 457 | ||
462 | 'setConnectionVersion': function(aValue) { | 458 | 'setConnectionVersion': function(aValue) { |
463 | if (this._connectionVersion != aValue) { | 459 | if (this._connectionVersion != aValue) { |
464 | this.resetConnection(); | 460 | this.resetConnection(); |
465 | } | 461 | } |
466 | this._connectionVersion = aValue; | 462 | this._connectionVersion = aValue; |
467 | }, | 463 | }, |
468 | 464 | ||
469 | //------------------------------------------------------------------------- | 465 | //------------------------------------------------------------------------- |
470 | 466 | ||
471 | 'connection': function() { | 467 | 'connection': function() { |
472 | if ((this._connection == null) && (this.connectionVersion() != null) ){ | 468 | if ((this._connection == null) && (this.connectionVersion() != null) ){ |
473 | this._connection = new Clipperz.PM.Connection.communicationProtocol.versions[this.connectionVersion()]({ | 469 | this._connection = new Clipperz.PM.Connection.communicationProtocol.versions[this.connectionVersion()]({ |
474 | getCredentialsFunction: MochiKit.Base.method(this, 'getCredentials') | 470 | getCredentialsFunction: MochiKit.Base.method(this, 'getCredentials') |
475 | }); | 471 | }); |
476 | } | 472 | } |
477 | 473 | ||
478 | return this._connection; | 474 | return this._connection; |
479 | }, | 475 | }, |
480 | 476 | ||
481 | 'resetConnection': function(aValue) { | 477 | 'resetConnection': function(aValue) { |
482 | if (this._connection != null) { | 478 | if (this._connection != null) { |
483 | this._connection.reset(); | 479 | this._connection.reset(); |
484 | } | 480 | } |
485 | 481 | ||
486 | this._connection = null; | 482 | this._connection = null; |
487 | }, | 483 | }, |
488 | 484 | ||
489 | //========================================================================= | 485 | //========================================================================= |
490 | 486 | ||
491 | 'getHeaderIndex': function (aKey) { | 487 | 'getHeaderIndex': function (aKey) { |
492 | return Clipperz.Async.callbacks("User.getHeaderIndex", [ | 488 | return Clipperz.Async.callbacks("User.getHeaderIndex", [ |
493 | MochiKit.Base.method(this, 'getServerData'), | 489 | MochiKit.Base.method(this, 'getServerData'), |
494 | MochiKit.Base.itemgetter('header'), | 490 | MochiKit.Base.itemgetter('header'), |
495 | MochiKit.Base.itemgetter(aKey) | 491 | MochiKit.Base.itemgetter(aKey) |
496 | ], {trace:false}) | 492 | ], {trace:false}) |
497 | }, | 493 | }, |
498 | 494 | ||
499 | //========================================================================= | 495 | //========================================================================= |
500 | 496 | ||
501 | 'getRecords': function () { | 497 | 'getRecords': function () { |
502 | return Clipperz.Async.callbacks("User.getRecords", [ | 498 | return Clipperz.Async.callbacks("User.getRecords", [ |
503 | MochiKit.Base.method(this, 'getHeaderIndex', 'recordsIndex'), | 499 | MochiKit.Base.method(this, 'getHeaderIndex', 'recordsIndex'), |
504 | MochiKit.Base.methodcaller('records'), | 500 | MochiKit.Base.methodcaller('records'), |
505 | MochiKit.Base.values | 501 | MochiKit.Base.values |
506 | ], {trace:false}); | 502 | ], {trace:false}); |
507 | }, | 503 | }, |
508 | 504 | ||
509 | 'recordWithLabel': function (aLabel) { | 505 | 'recordWithLabel': function (aLabel) { |
510 | return Clipperz.Async.callbacks("User.recordWithLabel", [ | 506 | return Clipperz.Async.callbacks("User.recordWithLabel", [ |
511 | MochiKit.Base.method(this, 'getRecords'), | 507 | MochiKit.Base.method(this, 'getRecords'), |
512 | MochiKit.Base.partial(Clipperz.Async.deferredFilter, function (aRecord) { | 508 | MochiKit.Base.partial(Clipperz.Async.deferredFilter, function (aRecord) { |
513 | return Clipperz.Async.callbacks("User.recordWithLabel - check record label", [ | 509 | return Clipperz.Async.callbacks("User.recordWithLabel - check record label", [ |
514 | MochiKit.Base.methodcaller('label'), | 510 | MochiKit.Base.methodcaller('label'), |
515 | MochiKit.Base.partial(MochiKit.Base.operator.eq, aLabel) | 511 | MochiKit.Base.partial(MochiKit.Base.operator.eq, aLabel) |
516 | ], {trace:false}, aRecord); | 512 | ], {trace:false}, aRecord); |