author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-06-16 07:22:01 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-06-16 07:22:01 (UTC) |
commit | 9ae34bd825e9390eedb1a8c9842b2515699dac99 (patch) (side-by-side diff) | |
tree | f2efea0a967f890ce9235871fd26a96515596bc4 /frontend | |
parent | 36ff1deefcbbd24aceca97eb39a13f9da4af8ff5 (diff) | |
parent | 36b3236415b856ddd0ad2804e82e410b5240ff4f (diff) | |
download | clipperz-9ae34bd825e9390eedb1a8c9842b2515699dac99.zip clipperz-9ae34bd825e9390eedb1a8c9842b2515699dac99.tar.gz clipperz-9ae34bd825e9390eedb1a8c9842b2515699dac99.tar.bz2 |
Merge pull request #40 from jokajak/issue37
fix the cancel button for editing cards
-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Record.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Record.js b/frontend/beta/js/Clipperz/PM/DataModel/Record.js index ffb45de..9e496de 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Record.js @@ -103,386 +103,392 @@ Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, { //------------------------------------------------------------------------- '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; console.log("Record.processData", someValues); 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()); } -// currentVersionParameters = someValues['currentVersion']; - currentVersionParameters = someValues['versions'][someValues['currentVersion']]; +// community edition doesn't currently pass version +// information + if (someValues['versions'] == null) { + currentVersionParameters = someValues['currentVersion']; + } else { + currentVersionParameters = someValues['versions'][someValues['currentVersion']]; + } + console.log("Record.processData - this.currentVersionKey()", this.currentVersionKey()); console.log("Record.processData - currentVersionParameters", currentVersionParameters); 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; this.setHeaderNotes(null); }, //------------------------------------------------------------------------- 'headerNotes': function() { return this._headerNotes; }, 'setHeaderNotes': function(aValue) { this._headerNotes = aValue; }, //------------------------------------------------------------------------- 'remove': function() { //MochiKit.Logging.logDebug(">>> Record.remove - " + this); MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), MochiKit.Base.method(this, 'removeDirectLogin')); this.syncDirectLoginReferenceValues(); this.user().removeRecord(this); //MochiKit.Logging.logDebug("<<< Record.remove"); }, //------------------------------------------------------------------------- 'directLogins': function() { return this._directLogins; }, 'addDirectLogin': function(aDirectLogin, shouldUpdateUser) { this.directLogins()[aDirectLogin.reference()] = aDirectLogin; if (shouldUpdateUser == true) { this.user().addDirectLogin(aDirectLogin); } }, 'removeDirectLogin': function(aDirectLogin) { this.removedDirectLogins().push(aDirectLogin); delete this.directLogins()[aDirectLogin.reference()]; // this.user().removeDirectLogin(aDirectLogin); }, 'resetDirectLogins': function() { this._directLogins = {}; }, 'removedDirectLogins': function() { return this._removedDirectLogins; }, 'resetRemovedDirectLogins': function() { this._removedDirectLogins = []; }, //------------------------------------------------------------------------- 'serverData': function() { return this._serverData; }, 'setServerData': function(aValue) { this._serverData = aValue; this.setShouldLoadData(false); return aValue; }, //------------------------------------------------------------------------- 'decryptedData': function() { return this._decryptedData; }, 'setDecryptedData': function(aValue) { this._decryptedData = aValue; this.setShouldDecryptData(false); return aValue; }, //------------------------------------------------------------------------- 'cachedData': function() { return this._cachedData; }, 'setCachedData': function(aValue) { //MochiKit.Logging.logDebug(">>> Record.setCachedData"); |