summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js
Side-by-side diff
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.js15
1 files changed, 6 insertions, 9 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 6ba58a8..f77ea80 100644
--- a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js
@@ -1,408 +1,405 @@
/*
Copyright 2008-2011 Clipperz Srl
-This file is part of Clipperz's Javascript Crypto Library.
-Javascript Crypto Library provides web developers with an extensive
-and efficient set of cryptographic functions. The library aims to
-obtain maximum execution speed while preserving modularity and
-reusability.
+This file is part of Clipperz Community Edition.
+Clipperz Community Edition is an online password manager.
For further information about its features and functionalities please
-refer to http://www.clipperz.com
+refer to http://www.clipperz.com.
-* Javascript Crypto Library is free software: you can redistribute
+* Clipperz Community Edition is free software: you can redistribute
it and/or modify it under the terms of the GNU Affero General Public
License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.
-* Javascript Crypto Library is distributed in the hope that it will
+* Clipperz Community Edition is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
- License along with Javascript Crypto Library. If not, see
+ License along with Clipperz Community Edition. If not, see
<http://www.gnu.org/licenses/>.
*/
try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) {
throw "Clipperz.PM.DataModel.User.Header.RecordIndex depends on Clipperz.PM.DataModel.User!";
}
if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; }
Clipperz.PM.DataModel.User.Header.RecordIndex = function(args) {
Clipperz.PM.DataModel.User.Header.RecordIndex.superclass.constructor.apply(this, arguments);
//console.log("NEW Clipperz.PM.DataModel.User.Header.RecordIndex", args);
this._recordsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({
'name': 'recordsData',
'retrieveKeyFunction': args.retrieveKeyFunction,
'remoteData': {
'data': args.recordsData['data'],
'version': args.encryptedDataVersion,
'recordsStats': args.recordsStats
}//,
// 'encryptedDataKeypath': 'data',
// 'encryptedVersionKeypath': 'version'
});
this._directLoginsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({
'name': 'directLoginsData',
'retrieveKeyFunction': args.retrieveKeyFunction,
'remoteData': {
'data': args.directLoginsData['data'],
'version': args.encryptedDataVersion
}//,
// 'encryptedDataKeypath': 'data',
// 'encryptedVersionKeypath': 'version'
});
this._lock = new MochiKit.Async.DeferredLock();
this._transientState = null;
this._retrieveRecordDetailFunction = args.retrieveRecordDetailFunction || Clipperz.Base.exception.raise('MandatoryParameter');
this._recordsIndex = args.recordsData['index'] || Clipperz.Base.exception.raise('MandatoryParameter');
this._directLoginsIndex = args.directLoginsData['index'] || Clipperz.Base.exception.raise('MandatoryParameter');
this._records = null;
return this;
}
Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.RecordIndex, Object, {
'toString': function() {
return "Clipperz.PM.DataModel.User.Header.RecordIndex";
},
//-------------------------------------------------------------------------
'retrieveRecordDetailFunction': function () {
return this._retrieveRecordDetailFunction;
},
//-------------------------------------------------------------------------
'recordsIndex': function () {
return this._recordsIndex;
},
'recordsData': function () {
return this._recordsData;
},
//-------------------------------------------------------------------------
'directLoginsIndex': function () {
return this._directLoginsIndex;
},
'directLoginsData': function () {
return this._directLoginsData;
},
//-------------------------------------------------------------------------
'lock': function () {
return this._lock;
},
//-------------------------------------------------------------------------
'transientState': function () {
if (this._transientState == null) {
this._transientState = new Clipperz.KeyValueObjectStore(/*{'name':'User.Header.RecordIndex.transientState [1]'}*/);
}
return this._transientState;
},
'resetTransientState': function (isCommitting) {
//console.log("######## UserHeaderRecordIndex - resetTransientState", Clipperz.Base.deepClone(this._transientState));
if (this._transientState != null) {
this._transientState.removeAllData();
}
this._transientState = null;
},
//-------------------------------------------------------------------------
'getRecordKey': function (aRecordReference) {
return Clipperz.Async.callbacks("User.Header.RecordIndex.getRecordKey", [
MochiKit.Base.method(this, 'getRecordIndexData', aRecordReference),
MochiKit.Base.itemgetter('key')
], {trace:false});
},
'setRecordKey': function (aRecordReference, aValue) {
return this.updateRecordIndexData(aRecordReference, 'key', aValue);
},
//-------------------------------------------------------------------------
'getRecordIndexData': function (aRecordReference) {
return this.recordsData().getValue(this.recordsIndex()[aRecordReference]);
},
//.........................................................................
'updateRecordIndexData': function (aRecordReference, aKey, aValue) {
return this.recordsData().setValue(this.recordsIndex()[aRecordReference]+'.'+aKey, aValue);
},
//-------------------------------------------------------------------------
'getDirectLoginIndexData': function (aDirectLoginReference) {
return this.directLoginsData().getValue(this.directLoginsIndex()[aDirectLoginReference]);
},
'setDirectLoginIndexData': function (aDirectLoginReference, aKey, aValue) {
//console.log("UserHeaderRecordIndex.setDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference], aKey);
//if (MochiKit.Base.isUndefinedOrNull(this.directLoginsIndex()[aDirectLoginReference])) {
// throw "PIPPO";
//}
return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference] + '.' + aKey, aValue);
},
'addDirectLoginIndexData': function (aDirectLoginReference) {
//console.log("UserHeaderRecordIndex.addDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference]);
return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference], {});
},
'removeDirectLoginIndexData': function (aDirectLoginReference) {
return this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLoginReference])
},
//-------------------------------------------------------------------------
'records': function () {
var deferredResult;
deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records", {trace:false});
deferredResult.acquireLock(this.lock());
deferredResult.addCallback(MochiKit.Base.bind(function () {
var innerDeferredResult;
if (this._records == null) {
innerDeferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records <inner deferred>", {trace:false});
innerDeferredResult.collectResults({
'records': [
// MochiKit.Base.method(this.recordsData(), 'getObjectDataStore'),
// MochiKit.Base.methodcaller('values')
MochiKit.Base.method(this.recordsData(), 'values')
],
'recordsStats': [
MochiKit.Base.method(this.recordsData(), 'getRemoteData'),
MochiKit.Base.itemgetter('recordsStats')
],
'directLogins': [
// MochiKit.Base.method(this.directLoginsData(), 'getObjectDataStore'),
// MochiKit.Base.methodcaller('values')
MochiKit.Base.method(this.directLoginsData(), 'values')
]
})
innerDeferredResult.addCallback(MochiKit.Base.bind(function (someData) {
var indexReference;
var recordsInvertedIndex;
var directLoginsInvertedIndex;
recordsInvertedIndex = Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.recordsIndex());
directLoginsInvertedIndex = Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.directLoginsIndex());
this._records = {};
for (indexReference in someData['records']) {
var record;
var reference;
var updateDate;
reference = recordsInvertedIndex[indexReference];
if (typeof(someData['recordsStats'][reference]) != 'undefined') {
updateDate = someData['recordsStats'][reference]['updateDate'];
record = new Clipperz.PM.DataModel.Record({
'reference': reference,
'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'),
'retrieveRemoteDataFunction': this.retrieveRecordDetailFunction(),
'retrieveIndexDataFunction': MochiKit.Base.method(this, 'getRecordIndexData'),
'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'),
'updateDate': updateDate,
'retrieveDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'getDirectLoginIndexData'),
'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'),
'removeDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'removeDirectLoginIndexData'),
'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin')
});
this._records[reference] = record;
} else {
Clipperz.log("SKIPPING record " + reference + " as there are no stas associated - " + Clipperz.Base.serializeJSON(someData['records'][reference]));
// # skip the record, as it seems it is not present in the DB
// updateDate = Clipperz.PM.Date.formatDateWithUTCFormat(new Date());
}
}
for (indexReference in someData['directLogins']) {
// var directLogin;
var reference;
var record;
reference = directLoginsInvertedIndex[indexReference];
record = this._records[recordsInvertedIndex[someData['directLogins'][indexReference]['record']]];
if (record != null) {
// directLogin = new Clipperz.PM.DataModel.DirectLogin({
new Clipperz.PM.DataModel.DirectLogin({
'reference': reference,
'record': record
});
} else {
Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!");
//console.log("direct login data", someData['directLogins']);
//console.log("current direct login data", someData['directLogins'][indexReference])
//console.log("reference", reference);
//console.log("record index", this.recordsIndex());
//console.log("record inverted index", recordsInvertedIndex);
}
}
return this._records;
}, this));
innerDeferredResult.callback();
} else {
innerDeferredResult = MochiKit.Async.succeed(this._records);
}
return innerDeferredResult;
}, this));
deferredResult.releaseLock(this.lock());
deferredResult.callback();
return deferredResult;
},
//-------------------------------------------------------------------------
'updateRecordIndexForNewRecord': function (aNewRecord) {
var newRecordIndex;
var recordReference;
recordReference = aNewRecord.reference();
newRecordIndex = (MochiKit.Base.listMax(MochiKit.Base.map(MochiKit.Base.partial(MochiKit.Base.operator.mul, 1), MochiKit.Base.values(this.recordsIndex()))) + 1) + '';
this.recordsIndex()[recordReference] = newRecordIndex;
this.transientState().setValue('newlyCreatedRecordsIndex' + '.' + recordReference, newRecordIndex);
this.transientState().setValue('newlyCreatedRecordsReferences' + '.' + recordReference, aNewRecord);
},
//.........................................................................
'createNewRecord': function () {
var deferredResult;
var newRecord;
//console.log("#### new Clipperz.PM.DataModel.Record [4]");
newRecord = new Clipperz.PM.DataModel.Record({
'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'),
'retrieveRemoteDataFunction': this.retrieveRecordDetailFunction(),
'retrieveIndexDataFunction': MochiKit.Base.method(this, 'getRecordIndexData'),
'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'),
'updateDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()),
'retrieveDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'getDirectLoginIndexData'),
'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'),
'removeDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'removeDirectLoginIndexData'),
'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin')
});
this.transientState().setValue('newRecordsReferences' + '.' + newRecord.reference(), newRecord);
this.updateRecordIndexForNewRecord(newRecord);
deferredResult = Clipperz.Async.callbacks("User.Header.RecordIndex.createNewRecord", [
MochiKit.Base.method(this, 'records'),
MochiKit.Base.partial(Clipperz.Async.setItemOnObject, newRecord.reference(), newRecord),
MochiKit.Base.method(this, 'setRecordKey', newRecord.reference(), Clipperz.PM.Crypto.randomKey()),
MochiKit.Base.method(newRecord, 'setLabel', ''),
MochiKit.Base.partial(MochiKit.Async.succeed, newRecord)
], {trace:false});
return deferredResult;
},
//-------------------------------------------------------------------------
'deleteRecord': function (aRecord) {
var deferredResult;
var recordReference;
recordReference = aRecord.reference();
deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.deleteRecord", {trace:false});
deferredResult.addMethod(aRecord, 'directLogins');
deferredResult.addCallback(MochiKit.Base.values);
deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'removeDirectLogin'));
deferredResult.addMethod(this.recordsData(), 'removeValue', this.recordsIndex()[recordReference]);
deferredResult.addCallback(MochiKit.Base.bind(function () {
this.transientState().setValue('deleteRecordsIndex' + '.' + recordReference, this.recordsIndex()[recordReference]);
delete this.recordsIndex()[recordReference];
}, this));
deferredResult.addMethod(this, 'records');
deferredResult.addCallback(MochiKit.Base.itemgetter(recordReference));
deferredResult.addMethod(this.transientState(), 'setValue', 'deleteRecordsReferences' + '.' + recordReference);
deferredResult.addMethod(this, 'records');
deferredResult.addCallback(MochiKit.Base.bind(function (someRecords) {
delete someRecords[recordReference];
}, this));
deferredResult.callback();
return deferredResult;
},
//=========================================================================
'removeDirectLogin': function (aDirectLogin) {
this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLogin.reference()]);
},
//-------------------------------------------------------------------------
'createNewDirectLogin': function (aRecord) {
var newDirectLogin;
var newDirectLoginIndexValue;
newDirectLogin = new Clipperz.PM.DataModel.DirectLogin({record:aRecord});
newDirectLoginIndexValue = MochiKit.Base.listMax(MochiKit.Base.map(function (aValue) { return aValue * 1; }, MochiKit.Base.values(this.directLoginsIndex()))) + 1;
this.transientState().setValue('newDirectLoginReferences' + '.' + newDirectLogin.reference(), newDirectLogin);
//console.log("UserHeaderRecordIndex.createNewDirectLogin [1]", newDirectLogin.reference(), newDirectLoginIndexValue);
this.directLoginsIndex()[newDirectLogin.reference()] = newDirectLoginIndexValue;
//console.log("UserHeaderRecordIndex.createNewDirectLogin [2]", newDirectLogin.reference(), this.directLoginsIndex()[newDirectLogin.reference()]);
this.directLoginsData().setValue(this.directLoginsIndex()[newDirectLogin.reference()], {'record': this.recordsIndex()[aRecord.reference()]});
return newDirectLogin;
},
//=========================================================================
'deleteAllCleanTextData': function () {
return Clipperz.Async.callbacks("User.Header.RecordIndex.deleteAllCleanTextData", [
// MochiKit.Base.method(this, 'records'),
// MochiKit.Base.values,
// MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')),
MochiKit.Base.method(this, 'recordsData'),