Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/Record.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Record.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Record.js b/frontend/beta/js/Clipperz/PM/DataModel/Record.js index f89f79c..7b06f29 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Record.js @@ -1,406 +1,404 @@ /* -Copyright 2008-2011 Clipperz Srl +Copyright 2008-2013 Clipperz Srl -This file is part of Clipperz Community Edition. -Clipperz Community Edition is an online password manager. +This file is part of Clipperz, the online password manager. For further information about its features and functionalities please refer to http://www.clipperz.com. -* 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. +* Clipperz 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. -* 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. +* Clipperz 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 Clipperz Community Edition. If not, see - <http://www.gnu.org/licenses/>. + License along with Clipperz. If not, see http://www.gnu.org/licenses/. */ if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } //############################################################################# Clipperz.PM.DataModel.Record = function(args) { args = args || {}; this._user = args['user'] || null; this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey(); this._version = args['version'] || Clipperz.PM.Crypto.encryptingFunctions.currentVersion; this._key = args['key'] || Clipperz.PM.Crypto.randomKey(); this.setLabel(args['label'] || Clipperz.PM.Strings['newRecordTitleLabel']); this.setHeaderNotes(args['headerNotes'] || null); this.setNotes(args['notes'] || args['headerNotes'] || ""); //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _headerNotes: '" + this._headerNotes + "'"); //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _notes: '" + this._notes + "'"); // this._notes = args.notes || ""; this._versions = {}; this._directLogins = {}; this._removedDirectLogins = []; this.setIsBrandNew(args['reference'] == null); this.setShouldLoadData(this.isBrandNew() ? false: true); this.setShouldDecryptData(this.isBrandNew() ? false: true); this.setShouldProcessData(this.isBrandNew() ? false: true); this.setCurrentVersion(this.isBrandNew() ? new Clipperz.PM.DataModel.RecordVersion(this, null): null); this.setCurrentVersionKey(null); this._serverData = null; this._decryptedData = null; this._cachedData = null; return this; } Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, { 'toString': function() { return "Record (" + this.label() + ")"; }, //------------------------------------------------------------------------- 'isBrandNew': function() { return this._isBrandNew; }, 'setIsBrandNew': function(aValue) { this._isBrandNew = aValue; }, //------------------------------------------------------------------------- /* 'shouldRunTheRecordCreationWizard': function() { return (this.isBrandNew() && (MochiKit.Base.keys(this.currentVersion().fields()).length == 0)); }, */ //------------------------------------------------------------------------- 'user': function() { return this._user; }, //------------------------------------------------------------------------- 'reference': function() { return this._reference; }, //------------------------------------------------------------------------- 'key': function() { return this._key; }, 'updateKey': function() { this._key = Clipperz.PM.Crypto.randomKey(); }, //------------------------------------------------------------------------- 'label': function() { return this._label; }, 'setLabel': function(aValue) { this._label = aValue; }, 'lowerCaseLabel': function() { return this.label().toLowerCase(); }, //------------------------------------------------------------------------- 'versions': function() { return this._versions; }, //------------------------------------------------------------------------- 'currentVersion': function() { return this._currentVersion; }, 'setCurrentVersion': function(aValue) { this._currentVersion = aValue; }, //------------------------------------------------------------------------- 'currentVersionKey': function() { return this._currentVersionKey; }, 'setCurrentVersionKey': function(aValue) { this._currentVersionKey = aValue; }, //------------------------------------------------------------------------- 'deferredData': function() { var deferredResult; //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.deferredData - this: " + this); deferredResult = new MochiKit.Async.Deferred(); deferredResult.addCallback(MochiKit.Base.method(this, 'loadData')); deferredResult.addCallback(MochiKit.Base.method(this, 'decryptData')); deferredResult.addCallback(MochiKit.Base.method(this, 'processData')); deferredResult.addCallback(function(aRecord) { return aRecord.currentVersion().deferredData(); }); deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); deferredResult.addCallback(MochiKit.Async.succeed, this); deferredResult.callback(); //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.deferredData"); return deferredResult; }, //------------------------------------------------------------------------- 'exportedData': function() { var result; result = {}; result['label'] = this.label(); result['data'] = this.serializedData(); result['currentVersion'] = this.currentVersion().serializedData(); result['currentVersion']['reference'] = this.currentVersion().reference(); // result['versions'] = MochiKit.Base.map(MochiKit.Base.methodcaller("serializedData"), MochiKit.Base.values(this.versions())); return Clipperz.Base.serializeJSON(result); }, //------------------------------------------------------------------------- 'shouldLoadData': function() { return this._shouldLoadData; }, 'setShouldLoadData': function(aValue) { this._shouldLoadData = aValue; }, //------------------------------------------------------------------------- 'shouldDecryptData': function() { return this._shouldDecryptData; }, 'setShouldDecryptData': function(aValue) { this._shouldDecryptData = aValue; }, //------------------------------------------------------------------------- 'shouldProcessData': function() { return this._shouldProcessData; }, 'setShouldProcessData': function(aValue) { this._shouldProcessData = aValue; }, //------------------------------------------------------------------------- 'loadData': function() { var result; //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.loadData - this: " + this); if (this.shouldLoadData()) { var deferredResult; deferredResult = new MochiKit.Async.Deferred(); deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'loadingRecordData'); deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'getRecordDetail', {reference: this.reference()}); deferredResult.addCallback(MochiKit.Base.method(this,'setServerData')); deferredResult.callback(); result = deferredResult; } else { result = MochiKit.Async.succeed(this.serverData()); } //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.loadData"); return result; }, //------------------------------------------------------------------------- 'decryptData': function(anEncryptedData) { var result; //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.decryptData - this: " + this + " (" + anEncryptedData + ")"); if (this.shouldDecryptData()) { var deferredResult; deferredResult = new MochiKit.Async.Deferred(); deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'decryptingRecordData'); deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.key(), anEncryptedData['data'], anEncryptedData['version']); deferredResult.addCallback(function(anEncryptedData, someDecryptedValues) { var result; result = anEncryptedData; result['data'] = someDecryptedValues; return result; }, anEncryptedData); deferredResult.addCallback(MochiKit.Base.method(this, 'setDecryptedData')); deferredResult.callback(); result = deferredResult; } else { result = MochiKit.Async.succeed(this.decryptedData()); } //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.decryptData"); return result; }, //------------------------------------------------------------------------- 'processData': function(someValues) { //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.processData"); //MochiKit.Logging.logDebug("--- Record.processData: " + Clipperz.Base.serializeJSON(someValues)); if (this.shouldProcessData()) { var currentVersionParameters; this.processDataToExtractLegacyValues(someValues['data']); if (typeof(someValues['data']['notes']) != 'undefined') { this.setNotes(someValues['data']['notes']); } if (someValues['data']['currentVersionKey'] != null) { this.setCurrentVersionKey(someValues['data']['currentVersionKey']); } else { this.setCurrentVersionKey(this.key()); } // community edition doesn't currently pass version information if (someValues['versions'] == null) { currentVersionParameters = someValues['currentVersion']; } else { currentVersionParameters = someValues['versions'][someValues['currentVersion']]; } //- currentVersionParameters = someValues['currentVersion']; // currentVersionParameters = someValues['versions'][someValues['currentVersion']]; currentVersionParameters['key'] = this.currentVersionKey(); this.setCurrentVersion(new Clipperz.PM.DataModel.RecordVersion(this, currentVersionParameters)); if (someValues['data']['directLogins'] != null) { var directLoginReference; for (directLoginReference in someValues['data']['directLogins']) { var directLogin; var directLoginParameters; directLoginParameters = someValues['data']['directLogins'][directLoginReference]; directLoginParameters.record = this; directLoginParameters.reference = directLoginReference; directLogin = new Clipperz.PM.DataModel.DirectLogin(directLoginParameters); this.addDirectLogin(directLogin, true); } } this.setShouldProcessData(false); } Clipperz.NotificationCenter.notify(this, 'recordDataReady'); //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.processData"); //MochiKit.Logging.logDebug("<<< Record.processData"); return this; }, //------------------------------------------------------------------------- 'processDataToExtractLegacyValues': function(someValues) { //MochiKit.Logging.logDebug(">>> Record.processDataToExtractLegacyValues"); if (someValues['data'] != null) { this.setNotes(someValues['data']); } if ( (typeof(someValues['loginFormData']) != "undefined") && (typeof(someValues['loginBindings'] != "undefined")) && (someValues['loginFormData'] != "") && (someValues['loginBindings'] != "") ) { var directLogin; directLogin = new Clipperz.PM.DataModel.DirectLogin({ record:this, label:this.label() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], reference:Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(this.label() + someValues['loginFormData'] + someValues['loginBindings'])).toHexString().substring(2), formData:Clipperz.Base.evalJSON(someValues['loginFormData']), legacyBindingData:Clipperz.Base.evalJSON(someValues['loginBindings']), bookmarkletVersion:'0.1' }); this.addDirectLogin(directLogin, true); } //MochiKit.Logging.logDebug("<<< Record.processDataToExtractLegacyValues"); }, //------------------------------------------------------------------------- 'getReadyBeforeUpdatingVersionValues': function() { }, //------------------------------------------------------------------------- 'addNewField': function() { var newField; //MochiKit.Logging.logDebug(">>> Record.addNewField - " + this); this.getReadyBeforeUpdatingVersionValues(); newField = this.currentVersion().addNewField(); Clipperz.NotificationCenter.notify(this, 'recordUpdated'); //MochiKit.Logging.logDebug("<<< Record.addNewField"); return newField; }, //------------------------------------------------------------------------- 'removeField': function(aField) { this.getReadyBeforeUpdatingVersionValues(); this.currentVersion().removeField(aField); Clipperz.NotificationCenter.notify(this, 'recordUpdated'); }, 'removeEmptyFields': function() { MochiKit.Iter.forEach(MochiKit.Base.values(this.currentVersion().fields()), MochiKit.Base.bind(function(aField) { if (aField.isEmpty()) { this.removeField(aField); // this.currentVersion().removeField(aField); } }, this)); }, //------------------------------------------------------------------------- 'notes': function() { return this._notes; }, 'setNotes': function(aValue) { this._notes = aValue; |