summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/Record.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/Record.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/Record.js881
1 files changed, 881 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/Record.js b/frontend/gamma/js/Clipperz/PM/DataModel/Record.js
new file mode 100644
index 0000000..85dd06b
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/Record.js
@@ -0,0 +1,881 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
32
33
34Clipperz.PM.DataModel.Record = function(args) {
35//console.log(">>> new Clipperz.PM.DataModel.Record", args);
36 Clipperz.PM.DataModel.Record.superclass.constructor.apply(this, arguments);
37
38 this._updateDate = (args.updateDate ? Clipperz.PM.Date.parse(args.updateDate) : Clipperz.Base.exception.raise('MandatoryParameter'));
39
40 this._retrieveIndexDataFunction = args.retrieveIndexDataFunction|| Clipperz.Base.exception.raise('MandatoryParameter');
41 this._updateIndexDataFunction = args.updateIndexDataFunction || Clipperz.Base.exception.raise('MandatoryParameter');
42
43 this._retrieveDirectLoginIndexDataFunction = args.retrieveDirectLoginIndexDataFunction|| null;
44 this._setDirectLoginIndexDataFunction = args.setDirectLoginIndexDataFunction || null;
45 this._removeDirectLoginIndexDataFunction = args.removeDirectLoginIndexDataFunction|| null;
46
47 this._createNewDirectLoginFunction = args.createNewDirectLoginFunction || null;
48
49 this._directLogins = {};
50
51 this._versions = {};
52
53 this._currentRecordVersion = null;
54 if (this.isBrandNew()) {
55 var newVersion;
56
57 this.setNotes('');
58 newVersion = new Clipperz.PM.DataModel.Record.Version({
59 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'),
60 'getVersion': MochiKit.Base.method(this, 'getVersion')
61
62 });
63 this._versions[newVersion.reference()] = newVersion;
64 this._currentVersionReference = newVersion.reference();
65 // this.setLabel('');
66 }
67
68//console.log("<<< new Clipperz.PM.DataModel.Record", args);
69
70 return this;
71}
72
73
74Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.EncryptedRemoteObject, {
75
76 'toString': function() {
77 return "Record (" + this.reference() + ")";
78 },
79
80 //-------------------------------------------------------------------------
81
82 'reference': function () {
83 return this._reference;
84 },
85
86 //=========================================================================
87
88 'getIndexData': function () {
89 return this._retrieveIndexDataFunction(this.reference());
90 },
91
92 //.........................................................................
93
94 'getIndexDataForKey': function (aKey) {
95 return Clipperz.Async.callbacks("Record.getIndexDataForKey", [
96 MochiKit.Base.method(this, 'getIndexData'),
97 MochiKit.Base.itemgetter(aKey)
98 ], {trace:false});
99 },
100
101 //-------------------------------------------------------------------------
102
103 'setIndexDataForKey': function (aKey, aValue) {
104 // return this._updateIndexDataFunction(this.reference(), aKey, aValue);
105
106 var deferredResult;
107
108 deferredResult = new Clipperz.Async.Deferred("Record.setIndexDataForKey", {trace:false});
109 deferredResult.addMethod(this, 'getIndexDataForKey', aKey);
110 deferredResult.addCallback(MochiKit.Base.bind(function (aCurrentValue) {
111 var result;
112 var originalValue;
113
114 originalValue = this.transientState().getValue('originalValues.indexData.' + aKey);
115 if (originalValue == null) {
116 originalValue = this.transientState().setValue('originalValues.indexData.' + aKey, aCurrentValue);
117 }
118
119 if (aCurrentValue != aValue) {
120 if (originalValue != aValue) {
121 this.transientState().setValue('hasPendingChanges.indexData.' + aKey, true);
122 } else {
123 this.transientState().setValue('hasPendingChanges.indexData.' + aKey, false);
124 }
125
126 result = this._updateIndexDataFunction(this.reference(), aKey, aValue);
127 } else {
128 result = MochiKit.Async.succeed(aValue);
129 }
130
131 return result;
132 }, this));
133
134 deferredResult.callback();
135
136 return deferredResult;
137 },
138
139 //=========================================================================
140/*
141 'key': function () {
142 return this.getIndexDataForKey('key');
143 },
144*/
145 //=========================================================================
146
147 'label': function () {
148 return this.getIndexDataForKey('label');
149 },
150
151 //.........................................................................
152
153 'setLabel': function (aValue) {
154 return this.setIndexDataForKey('label', aValue);
155 },
156
157 //=========================================================================
158
159 'headerNotes': function () {
160 return this.getIndexDataForKey('notes');
161 },
162
163 //-------------------------------------------------------------------------
164
165 'notes': function () {
166 return Clipperz.Async.callbacks("Record.notes", [
167 MochiKit.Base.method(this, 'headerNotes'),
168 MochiKit.Base.bind(function (someHeaderNotes) {
169 var result;
170
171 if ((someHeaderNotes == null) || (typeof(someHeaderNotes) == 'undefined')) {
172 result = this.getValue('notes');
173 } else {
174 result = MochiKit.Async.succeed(someHeaderNotes);
175 }
176
177 return result;
178 }, this)
179 ], {trace:false});
180 },
181
182 //.........................................................................
183
184 'setNotes': function (aValue) {
185 return this.setValue('notes', aValue);
186 },
187
188 //=========================================================================
189
190 'updateDate': function () {
191 return MochiKit.Async.succeed(this._updateDate);
192 },
193
194 //=========================================================================
195
196 'favicon': function () {
197 var result;
198 var directLogins;
199
200 directLogins = MochiKit.Base.values(this.directLogins());
201 if (directLogins.length > 0) {
202 result = directLogins[0].favicon();
203 // } else if (/* is there an URL to use for searching a favicon */){
204 } else {
205 result = null; //MochiKit.Async.succeed(Clipperz.PM.Strings['defaultFaviconUrl']);
206 }
207
208 return result;
209 },
210
211 //-------------------------------------------------------------------------
212
213 'searchableContent': function () {
214 var deferredResult;
215
216//console.log(">>> searchableContent");
217 deferredResult = new Clipperz.Async.Deferred("Record.searchableContent", {trace:false});
218
219 deferredResult.collectResults({
220 'recordLabel': MochiKit.Base.method(this, 'label'),
221 'directLoginLabels': [
222 MochiKit.Base.method(this, 'directLoginReferences'),
223 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.itemgetter('label'))
224 ]
225 })
226 deferredResult.addCallback(function (someValues) {
227 return someValues['recordLabel'] + ' ' + someValues['directLoginLabels'].join(' ');
228 });
229 deferredResult.callback();
230//console.log("<<< searchableContent");
231
232 return deferredResult;
233 },
234
235 //-------------------------------------------------------------------------
236
237 'isMatching': function (aRegExp) {
238 return Clipperz.Async.callbacks("deferredFilterFunction", [
239 MochiKit.Base.method(this, 'searchableContent'),
240 MochiKit.Base.method(aRegExp, 'test'),
241 function (doesItMatch) {
242 var result;
243
244 if (doesItMatch) {
245 result = MochiKit.Async.succeed('match');
246 } else {
247 result = MochiKit.Async.fail('miss');
248 }
249
250 return result;
251 }
252 ], {trace:false});
253 },
254
255 //=========================================================================
256
257 'directLogins': function () {
258 return this._directLogins;
259 },
260
261 'addDirectLogin': function (aDirectLogin) {
262 this._directLogins[aDirectLogin.reference()] = aDirectLogin;
263 },
264
265 'directLoginWithReference': function (aDirectLoginReference) {
266 return this._directLogins[aDirectLoginReference];
267 },
268
269 'createNewDirectLoginFunction': function () {
270 return this._createNewDirectLoginFunction;
271 },
272
273 'saveOriginalDirectLoginStatusToTransientState': function () {
274 if (this.transientState().getValue('directLogins') == null) {
275 // this.transientState().setValue('directLogins', this._directLogins)
276//console.log("SET TRANSIENT STATE", Clipperz.Base.serializeJSON(MochiKit.Base.keys(this.transientState().getValue('directLogins'))))
277 MochiKit.Iter.forEach(MochiKit.Base.keys(this._directLogins), MochiKit.Base.bind(function(aKey) {
278 this.transientState().setValue('directLogins' + '.' + aKey, this._directLogins[aKey])
279 }, this))
280 }
281 },
282
283 'createNewDirectLogin': function () {
284 this.saveOriginalDirectLoginStatusToTransientState();
285
286 return this.createNewDirectLoginFunction()(this);
287 },
288
289 'removeDirectLogin': function(aDirectLogin) {
290 this.saveOriginalDirectLoginStatusToTransientState();
291
292 return Clipperz.Async.callbacks("Record.removeDirectLogin", [
293 MochiKit.Base.method(this, 'removeValue', 'directLogins' + '.' + aDirectLogin.reference()),
294 MochiKit.Base.bind(function () {
295 delete this._directLogins[aDirectLogin.reference()]
296 }, this)
297 ], {trace:false});
298
299 },
300
301 'directLoginReferences': function () {
302 var result;
303
304 result = Clipperz.Async.callbacks("Record.directLoginReferences", [
305 MochiKit.Base.method(this, 'directLogins'),
306 MochiKit.Base.values,
307 function (someDirectLogins) {
308 var result;
309 var i,c;
310
311 result = [];
312 c = someDirectLogins.length;
313 for (i=0; i<c; i++) {
314 result.push(Clipperz.Async.collectResults("Record.directLoginReferences - collectResults", {
315 '_rowObject': MochiKit.Async.succeed,
316 '_reference': MochiKit.Base.methodcaller('reference'),
317 'label': MochiKit.Base.methodcaller('label'),
318 'favicon': MochiKit.Base.methodcaller('favicon')
319 }, {trace:false})(someDirectLogins[i]));
320 };
321
322 return result;
323 },
324 Clipperz.Async.collectAll
325 ], {trace:false});
326
327 return result;
328 },
329
330 //=========================================================================
331
332 'unpackRemoteData': function (someData) {
333 var result;
334
335//console.log("new Clipperz.PM.DataModel.Record.Version [2]");
336/*
337 this._currentRecordVersion = new Clipperz.PM.DataModel.Record.Version({
338 'reference': someData['currentVersion']['reference'],
339 'retrieveKeyFunction': MochiKit.Base.method(this, 'getCurrentRecordVersionKey'),
340 'remoteData': someData['currentVersion'],
341 });
342*/
343 var versionKey;
344
345 for (versionKey in someData['versions']) {
346//console.log("### versionKey", versionKey);
347 this._versions[versionKey] = new Clipperz.PM.DataModel.Record.Version({
348 'reference': versionKey,
349 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'),
350 'remoteData': someData['versions'][versionKey],
351 'getVersion': MochiKit.Base.method(this, 'getVersion')
352 })
353 }
354
355 // this._currentVersionReference = someData['currentVersion']['reference'];
356 this._currentVersionReference = someData['currentVersion'];
357//console.log("=== currentVersionReference", this._currentVersionReference, someData);
358
359 result = Clipperz.PM.DataModel.Record.superclass.unpackRemoteData.apply(this, arguments);
360
361 return result;
362 },
363
364 //-------------------------------------------------------------------------
365
366 'unpackData': function (someData) {
367 var result;
368
369 result = Clipperz.PM.DataModel.Record.superclass.unpackData.apply(this, arguments);
370
371 if (MochiKit.Base.isUndefinedOrNull(result['notes'])) {
372 result['notes'] = ''
373 }
374
375 return result;
376 },
377
378 //-------------------------------------------------------------------------
379
380 'prepareRemoteDataWithKey': function (aKey) {
381 var deferredResult;
382 varnewVersionKey;
383 var result;
384
385 newVersionKey = Clipperz.PM.Crypto.randomKey();
386 result = {};
387
388 deferredResult = new Clipperz.Async.Deferred("Record.prepareRemoteDataWithKey", {trace:false});
389 deferredResult.addCallbackList([
390 Clipperz.Async.collectResults("Record.prepareRemoteDataWithKey - collect results", {
391 'isBrandNew': MochiKit.Base.method(this, 'isBrandNew'),
392 'versionHasPendingChanges':[
393 // MochiKit.Base.method(this, 'getCurrentRecordVersion'),
394 // MochiKit.Base.methodcaller('hasPendingChanges')
395 MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'hasPendingChanges')
396 ]
397 }),
398 Clipperz.Async.or,
399
400 Clipperz.Async.deferredIf("Current Version has pending changes", [
401 MochiKit.Base.method(this, 'createNewRecordVersion'),
402 MochiKit.Base.methodcaller('prepareRemoteDataWithKey', newVersionKey),
403 MochiKit.Base.partial(Clipperz.Async.setItem, result, 'currentRecordVersion'),
404 MochiKit.Base.method(this, 'setCurrentRecordVersionKey', newVersionKey)
405 ], []),
406
407 MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.prepareRemoteDataWithKey, this, aKey),
408 MochiKit.Base.partial(Clipperz.Async.setItem, result, 'record'),
409
410 MochiKit.Base.partial(MochiKit.Async.succeed, result)
411 ]);
412
413 deferredResult.callback();
414
415 return deferredResult;
416 },
417
418 //=========================================================================
419
420 'fields': function () {
421 return this.invokeCurrentRecordVersionMethod('fields');
422 },
423
424 'addField': function (someParameters) {
425 return this.invokeCurrentRecordVersionMethod('addField', someParameters);
426 },
427
428 'removeField': function (someParameters) {
429 return this.invokeCurrentRecordVersionMethod('removeField', someParameters);
430 },
431
432 //'sortFieldReference': function (someSortedFieldReferences) {
433 // return this.invokeCurrentRecordVersionMethod('sortFieldReference', someSortedFieldReferences);
434 //},
435
436 'getFieldsValues': function () {
437 return this.invokeCurrentRecordVersionMethod('getFieldsValues');
438 },
439
440 'fieldWithLabel': function (aLabel) {
441 return Clipperz.Async.callbacks("Record.fieldWithLabel", [
442 MochiKit.Base.method(this, 'fields'),
443 MochiKit.Base.values,
444 MochiKit.Base.partial(Clipperz.Async.deferredFilter, function (aField) {
445 return Clipperz.Async.callbacks("Record.fieldWithLabel - check field label", [
446 MochiKit.Base.methodcaller('label'),
447 MochiKit.Base.partial(MochiKit.Base.operator.eq, aLabel)
448 ], {trace:false}, aField);
449 }),
450 function (someFilteredResults) {
451 var result;
452
453 switch (someFilteredResults.length) {
454 case 0:
455 result = null;
456 break;
457 case 1:
458 result = someFilteredResults[0];
459 break;
460 default:
461 WTF = TODO;
462 break;
463 }
464
465 return result;
466 }
467 ], {trace:false});
468 },
469
470 //=========================================================================
471
472 'getVersion': function (aVersionReference) {
473 return Clipperz.Async.callbacks("Record.getVersion", [
474 MochiKit.Base.method(this, 'getVersions'),
475 MochiKit.Base.itemgetter(aVersionReference)
476 ], {trace:false});
477 },
478
479 //-------------------------------------------------------------------------
480
481 'getVersionKey': function (aVersionReference) {
482 vardeferredResult;
483 var transientStateKey;
484
485 transientStateKey = 'versionKeys' + '.' + aVersionReference;
486 if (this.transientState().getValue(transientStateKey) != null) {
487 deferredResult = MochiKit.Async.succeed(this.transientState().getValue(transientStateKey));
488 } else {
489 deferredResult = Clipperz.Async.callbacks("Record.getVersionKey", [
490 MochiKit.Base.method(this, 'getVersions'),
491 MochiKit.Base.partial(MochiKit.Base.operator.eq, aVersionReference, this.currentVersionReference()),
492 Clipperz.Async.deferredIf("getVersionKey for current version", [
493 MochiKit.Base.method(this, 'getCurrentRecordVersionKey'),
494 MochiKit.Base.method(this.transientState(), 'setValue', transientStateKey)
495 ],[
496 MochiKit.Async.fail
497 ])
498 ], {trace:false});
499 }
500
501 return deferredResult;
502 },
503
504 //-------------------------------------------------------------------------
505
506 'versions': function () {
507 return this._versions;
508 },
509
510 'getVersions': function () {
511 return Clipperz.Async.callbacks("Record.versions", [
512 MochiKit.Base.method(this, 'getValue', 'fakeKey, just to trigger unpackRemoteData'),
513 MochiKit.Base.bind(function () { return this._versions; }, this)
514 ], {trace:false});
515 },
516
517 //-------------------------------------------------------------------------
518
519 'getCurrentRecordVersion': function () {
520 return Clipperz.Async.callbacks("Record.getCurrentRecordVersion", [
521 // MochiKit.Base.method(this, 'getValue', 'fakeKey, just to trigger unpackRemoteData'),
522 // MochiKit.Base.bind(function () { return this._currentRecordVersion; }, this)
523
524 MochiKit.Base.method(this, 'versions'),
525 MochiKit.Base.itemgetter(this.currentVersionReference()),
526 Clipperz.Async.deferredIf("The current version is available", [
527 MochiKit.Async.succeed
528 ], [
529 MochiKit.Base.method(this, 'getVersions'),
530 MochiKit.Base.bind(function (someVersions) { return someVersions[this.currentVersionReference()]}, this)
531 ])
532 ], {trace:false});
533 },
534
535 'setCurrentRecordVersion': function (aRecordVersion) {
536 this._currentVersionReference = aRecordVersion.reference();
537 },
538
539 //.........................................................................
540
541 'currentVersionReference': function () {
542//console.log("currentVersionReference");
543 return this._currentVersionReference;
544 },
545
546 //-------------------------------------------------------------------------
547
548 'createNewRecordVersion': function () {
549 var deferredResult;
550
551 if (this.isBrandNew()) {
552 deferredResult = this.getCurrentRecordVersion();
553 } else {
554 var newVersion;
555
556 newVersion = new Clipperz.PM.DataModel.Record.Version({
557 // 'reference': versionKey,
558 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'),
559 // 'remoteData': {},
560 'getVersion': MochiKit.Base.method(this, 'getVersion')
561 })
562 this._versions[newVersion.reference()] = newVersion;
563
564 deferredResult = Clipperz.Async.callbacks("Record.createNewRecordVersion", [
565 // MochiKit.Base.method(this, 'getCurrentRecordVersion'),
566 // MochiKit.Base.methodcaller('values'),
567 MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'values'),
568 MochiKit.Base.method(newVersion, 'setValues'),
569
570 Clipperz.Async.collectResults("Record.createNewRecordVersion [collect results]", {
571 'reference':MochiKit.Base.method(this, 'currentVersionReference'),
572 'key': MochiKit.Base.method(this, 'getCurrentRecordVersionKey')
573 }, {trace:false}),
574 MochiKit.Base.method(newVersion, 'setPreviousVersionReferenceAndKey'),
575
576 // MochiKit.Base.method(this, 'getCurrentRecordVersion'),
577 // MochiKit.Base.method(this, 'revertChanges'),
578 MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'revertChanges'),
579
580 MochiKit.Base.method(this, 'setCurrentRecordVersion', newVersion),
581 MochiKit.Base.partial(MochiKit.Async.succeed, newVersion)
582 ], {trace:false});
583 }
584
585 return deferredResult;
586 },
587
588 //-------------------------------------------------------------------------
589
590 'getCurrentRecordVersionKey': function () {
591//console.log("getCurrentRecordVersionKey");
592 return Clipperz.Async.callbacks("Record.getCurrentRecordVersionKey", [
593 MochiKit.Base.method(this, 'getValue', 'currentVersionKey'),
594 Clipperz.Async.deferredIf("currentVersionKey is NOT null", [
595 MochiKit.Async.succeed
596 ], [
597 MochiKit.Base.method(this, 'getKey')
598 ])
599 ], {trace:false});
600 },
601
602 'setCurrentRecordVersionKey': function (aValue) {
603 //TODO: triple check this method!
604 return Clipperz.Async.callbacks("Record.setCurrentRecordVersionKey", [
605 MochiKit.Base.method(this, 'setValue', 'currentVersionKey', aValue)
606 ], {trace:false});
607 },
608
609 //-------------------------------------------------------------------------
610
611 'invokeCurrentRecordVersionMethod': function (aMethodName, someValues) {
612//console.log(">>> invokeCurrentRecordVersionMethod", aMethodName);
613 return Clipperz.Async.callbacks("Record.invokeCurrentRecordVersionMethod", [
614 MochiKit.Base.method(this, 'getCurrentRecordVersion'),
615//function (aValue) { console.log("=== getCurrentRecordVersion", aValue); return aValue},
616 MochiKit.Base.methodcaller(aMethodName, someValues)
617 ], {trace:false});
618 },
619
620
621 'lazilyinvokeCurrentRecordVersionMethod': function (aMethodName, someValues, defaultResult) {
622 return Clipperz.Async.callbacks("Record.lazilyinvokeCurrentRecordVersionMethod", [
623 MochiKit.Base.method(this, 'currentVersionReference'),
624//function (aValue) { console.log("LAZY -> versions", aValue); return aValue; },
625 Clipperz.Async.deferredIf("versions has been loaded", [
626//function (aValue) { console.log("LAZY -> then"); return aValue; },
627 MochiKit.Base.method(this, 'getCurrentRecordVersion'),
628 MochiKit.Base.methodcaller(aMethodName, someValues),
629//function (aValue) { console.log("LAZY <- then"); return aValue; }
630 ], [
631//function (aValue) { console.log("LAZY -> else"); return aValue; },
632 MochiKit.Base.partial(MochiKit.Async.succeed, defaultResult),
633//function (aValue) { console.log("LAZY <- else"); return aValue; }
634 ])
635 ], {trace:false});
636 },
637
638 //=========================================================================
639
640 'hasPendingChanges': function () {
641 var deferredResult;
642
643 if (this.hasInitiatedObjectDataStore()) {
644 deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.hasPendingChanges", {trace:false});
645 deferredResult.collectResults({
646 'super': MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.hasPendingChanges, this),
647 'currentVersion': [
648 // MochiKit.Base.method(this, 'getCurrentRecordVersion'),
649 // MochiKit.Base.methodcaller('hasPendingChanges')
650 MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'hasPendingChanges')
651 ],
652 'directLogins': [
653 MochiKit.Base.method(this, 'directLogins'),
654//function (aValue) { console.log("Record.directLogins", aValue); return aValue; },
655 MochiKit.Base.values,
656 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasPendingChanges')),
657 Clipperz.Async.collectAll,
658 Clipperz.Async.or
659 // function(someValues) {
660 // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity);
661 // }
662 ]
663 });
664//deferredResult.addCallback(function (aValue) { console.log("Record.hasPendingResults", aValue); return aValue; });
665 deferredResult.addCallback(MochiKit.Base.values);
666 deferredResult.addCallback(MochiKit.Base.bind(function(someValues) {
667 var result;
668 result = MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity);
669
670 if ((result == false) && (this.isBrandNew() == false)) {
671 result = MochiKit.Iter.some(MochiKit.Base.values(this.transientState().getValue('hasPendingChanges.indexData')), MochiKit.Base.operator.identity);
672 }
673
674 return result;
675 }, this));
676
677 deferredResult.callback();
678 } else {
679 deferredResult = Clipperz.Async.callbacks("Recrod.hasPendingChanges [hasInitiatedObjectDataStore == false]", [
680 MochiKit.Base.method(this, 'directLogins'),
681 MochiKit.Base.values,
682 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasPendingChanges')),
683 Clipperz.Async.collectAll,
684 Clipperz.Async.or
685 // function(someValues) {
686 // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity);
687 // }
688 ], {trace:false})
689 }
690
691 return deferredResult;
692 },
693
694 //-------------------------------------------------------------------------
695
696 'hasPendingChangesWhenBrandNew': function () {
697 var deferredResult;
698
699 deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.hasPendingChangesWhenBrandNew", {trace:false});
700 deferredResult.collectResults({
701 'label': [
702 MochiKit.Base.method(this, 'label'),
703 MochiKit.Base.partial(MochiKit.Base.operator.ne, '')
704 ],
705 'notes': [
706 MochiKit.Base.method(this, 'notes'),
707 MochiKit.Base.partial(MochiKit.Base.operator.ne, '')
708 ]
709 });
710 // deferredResult.addCallback(MochiKit.Base.values);
711 // deferredResult.addCallback(function(someValues) {
712 // return MochiKit.Iter.some(someValues, MochiKit.Base.operator.identity);
713 // });
714 deferredResult.addCallback(Clipperz.Async.or);
715
716 deferredResult.callback();
717
718 return deferredResult;
719 },
720
721 //-------------------------------------------------------------------------
722
723 'isBrandNewWithNoPendingChanges': function () {
724 vardeferredResult;
725
726 if (this.isBrandNew() == false) {
727 deferredResult = MochiKit.Async.succeed(false);
728 } else {
729 deferredResult = Clipperz.Async.callbacks("Record.isBrandNewWithNoPendingChanges", [
730 MochiKit.Base.method(this, 'hasPendingChanges'),
731 MochiKit.Base.operator.lognot
732 ], {trace:false});
733 }
734
735 return deferredResult;
736 },
737
738 //=========================================================================
739
740 'revertChanges': function () {
741 var deferredResult;
742
743 if (this.isBrandNew() == false) {
744 deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.revertChanges", {trace:false});
745 deferredResult.addMethod(this, 'hasPendingChanges');
746 deferredResult.addIf([
747 // MochiKit.Base.method(this, 'getCurrentRecordVersion'),
748 // MochiKit.Base.methodcaller('revertChanges'),
749 MochiKit.Base.method(this,'invokeCurrentRecordVersionMethod', 'revertChanges'),
750
751 MochiKit.Base.method(this, 'directLogins'),
752 MochiKit.Base.values,
753 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('revertChanges')),
754
755 MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.revertChanges, this)
756 ], [
757 MochiKit.Async.succeed
758 ]);
759 deferredResult.callback();
760 } else {
761 // this.deleteAllCleanTextData();
762 deferredResult = MochiKit.Async.succeed();
763 }
764
765 return deferredResult;
766 },
767
768 //-------------------------------------------------------------------------
769
770 'resetTransientState': function (isCommitting) {
771 // if ((isCommitting == false) && (this.transientState().getValue('directLogins') != null)) {
772 // this._directLogins = this.transientState().getValue('directLogins');
773 // }
774
775 return Clipperz.Async.callbacks("Record.resetTransientState", [
776 //- MochiKit.Base.method(this, 'getCurrentRecordVersion'),
777 //- MochiKit.Base.methodcaller('resetTransientState'),
778 // MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'resetTransientState'),
779 MochiKit.Base.method(this, 'lazilyinvokeCurrentRecordVersionMethod', 'resetTransientState'),
780
781 MochiKit.Base.method(this, 'directLogins'),
782//function (aValue) { console.log("resetTransientState - directLogins", aValue); return aValue; },
783 MochiKit.Base.values,
784 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('resetTransientState')),
785
786 MochiKit.Base.bind(function () {
787 if ((isCommitting == false) && (this.transientState().getValue('directLogins') != null)) {
788 this._directLogins = this.transientState().getValue('directLogins');
789 }
790 }, this),
791
792 MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.resetTransientState, this, isCommitting)
793 ], {trace:false})
794 },
795
796 //-------------------------------------------------------------------------
797
798 'commitTransientState': function () {
799 var deferredResult;
800
801 deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.commitTransientState", {trace:false});
802 deferredResult.addMethod(this, 'hasPendingChanges');
803 deferredResult.addIf([
804 MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.commitTransientState, this),
805 // MochiKit.Base.method(this, 'getCurrentRecordVersion'),
806 // MochiKit.Base.methodcaller('commitTransientState'),
807 MochiKit.Base.method(this, 'invokeCurrentRecordVersionMethod', 'commitTransientState'),
808 MochiKit.Base.method(this, 'directLogins'),
809 MochiKit.Base.values,
810 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('commitTransientState'))
811 ], [
812 MochiKit.Async.succeed
813 ]);
814 deferredResult.callback();
815
816 return deferredResult;
817 },
818
819 //=========================================================================
820
821 'retrieveDirectLoginIndexDataFunction': function () {
822//console.log("Record.retrieveDirectLoginIndexDataFunction", this._retrieveDirectLoginIndexDataFunction);
823 return this._retrieveDirectLoginIndexDataFunction;
824 },
825
826 'setDirectLoginIndexDataFunction': function () {
827 return this._setDirectLoginIndexDataFunction;
828 },
829
830 'removeDirectLoginIndexDataFunction': function () {
831 return this._removeDirectLoginIndexDataFunction;
832 },
833
834 //=========================================================================
835
836 'deleteAllCleanTextData': function () {
837 // return Clipperz.PM.DataModel.Record.superclass.deleteAllCleanTextData.apply(this, arguments);
838
839 return Clipperz.Async.callbacks("Record.deleteAllCleanTextData", [
840 MochiKit.Base.method(this, 'versions'),
841 MochiKit.Base.values,
842 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')),
843
844 MochiKit.Base.method(this, 'directLogins'),
845 MochiKit.Base.values,
846 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')),
847
848 MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.deleteAllCleanTextData, this)
849 ], {trace:false});
850 },
851
852 'hasAnyCleanTextData': function () {
853 // return Clipperz.PM.DataModel.Record.superclass.hasAnyCleanTextData.apply(this, arguments);
854
855 return Clipperz.Async.callbacks("Record.hasAnyCleanTextData", [
856 Clipperz.Async.collectResults("Record.hasAnyCleanTextData [collect results]", {
857 'versions':[
858 MochiKit.Base.method(this, 'versions'),
859 MochiKit.Base.values,
860 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')),
861 Clipperz.Async.collectAll
862 ],
863 'directLogins': [
864 MochiKit.Base.method(this, 'directLogins'),
865 MochiKit.Base.values,
866 MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('hasAnyCleanTextData')),
867 Clipperz.Async.collectAll
868 ],
869 'super': [
870 MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.hasAnyCleanTextData, this)
871 ]
872 }, {trace:false}),
873 Clipperz.Async.or
874 ])
875 },
876
877 //=========================================================================
878 __syntaxFix__: "syntax fix"
879});
880
881