summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js39
1 files changed, 11 insertions, 28 deletions
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,47 +1,44 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer 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
26try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { 24try { 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
30if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } 28if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; }
31 29
32Clipperz.PM.DataModel.User.Header.RecordIndex = function(args) { 30Clipperz.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
@@ -109,25 +106,24 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.RecordIndex, Object, {
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),
@@ -149,33 +145,31 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.RecordIndex, Object, {
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
@@ -252,30 +246,25 @@ Clipperz.log("SKIPPING record " + reference + " as there are no stas associated
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 {
264Clipperz.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));
@@ -296,25 +285,24 @@ Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!");
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
@@ -377,27 +365,25 @@ Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!");
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')),
@@ -422,25 +408,24 @@ Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!");
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 },
@@ -452,25 +437,24 @@ Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!");
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 //-------------------------------------------------------------------------
@@ -561,25 +545,24 @@ Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!");
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