From 3918a7bdfc063306787a5df6a390689420016a4d Mon Sep 17 00:00:00 2001 From: Giulio Cesare Solaroli Date: Mon, 25 Aug 2014 08:11:28 +0200 Subject: [PATCH] Fixed an issue when editing a card label (without tags) --- .../PM/DataModel/EncryptedRemoteObject.js | 7 ++- .../delta/js/Clipperz/PM/DataModel/Record.js | 56 ++++++++++++++----- .../delta/js/Clipperz/PM/DataModel/User.js | 17 +++++- .../Clipperz/PM/DataModel/Record.test.js | 7 +++ .../tests/Clipperz/PM/DataModel/User.test.js | 12 ++-- 5 files changed, 77 insertions(+), 22 deletions(-) diff --git a/frontend/delta/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js b/frontend/delta/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js index 1aa7a52..bddc720 100644 --- a/frontend/delta/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js +++ b/frontend/delta/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js @@ -21,12 +21,15 @@ refer to http://www.clipperz.com. */ +"use strict"; try { if (typeof(Clipperz.KeyValueObjectStore) == 'undefined') { throw ""; }} catch (e) { throw "Clipperz.PM.DataModel.EncryptedRemoteObject depends on Clipperz.KeyValueObjectStore!"; } -if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } -if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } +Clipperz.Base.module('Clipperz.PM.DataModel'); + +//if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +//if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } Clipperz.PM.DataModel.EncryptedRemoteObject = function(args) { args = args || {}; diff --git a/frontend/delta/js/Clipperz/PM/DataModel/Record.js b/frontend/delta/js/Clipperz/PM/DataModel/Record.js index 4913cf2..4abc5c5 100644 --- a/frontend/delta/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/delta/js/Clipperz/PM/DataModel/Record.js @@ -21,9 +21,12 @@ refer to http://www.clipperz.com. */ -if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } -if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } -if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } +"use strict"; +Clipperz.Base.module('Clipperz.PM.DataModel'); + +//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) { @@ -142,14 +145,19 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt 'fullLabel': function () { return this.getIndexDataForKey('label'); }, + + 'setFullLabel': function (aLabel, someTags) { + var fullLabel = MochiKit.Base.extend([aLabel], MochiKit.Base.map(function (aTag) { return Clipperz.PM.DataModel.Record.tagChar + aTag; }, someTags)).join(' '); - 'updateFullLabelWithTags': function (someTags) { - return Clipperz.Async.callbacks("Record.updateFullLabelWithTags", [ + return this.setIndexDataForKey('label', fullLabel); + }, + + 'updateTags': function (someTagInfo) { + return Clipperz.Async.callbacks("Record.updateTags", [ MochiKit.Base.method(this, 'label'), - function (aLabel) { - return aLabel + ' ' + MochiKit.Base.map(function (aTag) { return Clipperz.PM.DataModel.Record.tagChar + aTag; }, MochiKit.Base.keys(someTags)).join(' '); - }, - MochiKit.Base.method(this, 'setIndexDataForKey', 'label') + MochiKit.Base.bind(function (aLabel) { + return this.setFullLabel(aLabel, MochiKit.Base.keys(someTagInfo)); + }, this) ], {trace:false}); }, @@ -183,7 +191,18 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt }, 'setLabel': function (aValue) { - return this.setIndexDataForKey('label', aValue); // [???] +// var tags; + + return Clipperz.Async.callbacks("Record.setLabel", [ + MochiKit.Base.method(this, 'tags'), +// function (someValues) { console.log("TAGS", someValues); tags = someValues; }, +// MochiKit.Base.method(this, 'setIndexDataForKey', 'label', aValue), +// MochiKit.Base.method(this, 'updateFullLabelWithTags', tags), + MochiKit.Base.method(this, 'setFullLabel', aValue), + MochiKit.Base.method(this, 'label'), + ], {trace:false}); + +// return this.setIndexDataForKey('label', aValue); // [???] }, //......................................................................... @@ -217,7 +236,7 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt MochiKit.Base.method(this, 'fullLabel'), MochiKit.Base.method(this, 'extractTags'), function (someTags) { someTags[aNewTag] = true; /* console.log("UPDATED TAGS", someTags); */ return someTags; }, - MochiKit.Base.method(this, 'updateFullLabelWithTags') + MochiKit.Base.method(this, 'updateTags') ], {trace:false}); }, @@ -227,7 +246,7 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt MochiKit.Base.method(this, 'fullLabel'), MochiKit.Base.method(this, 'extractTags'), function (someTags) { delete someTags[aTag]; return someTags; }, - MochiKit.Base.method(this, 'updateFullLabelWithTags') + MochiKit.Base.method(this, 'updateTags') ], {trace:false}); }, @@ -754,7 +773,9 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt 'hasPendingChanges': function () { var deferredResult; - if (this.hasInitiatedObjectDataStore()) { + /*if (this.isBrandNew()) { + deferredResult = MochiKit.Async.succeed(true); + } else*/ if (this.hasInitiatedObjectDataStore()) { deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.hasPendingChanges", {trace:false}); deferredResult.collectResults({ 'super': MochiKit.Base.bind(Clipperz.PM.DataModel.Record.superclass.hasPendingChanges, this), @@ -984,6 +1005,14 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt ]) }, + //========================================================================= + + 'setUpWithRecord': function (aRecord) { + return Clipperz.Async.callbacks("Record.hasAnyCleanTextData", [ + MochiKit.Base.method(aRecord, 'full') + ], {trace:false}); + }, + //========================================================================= __syntaxFix__: "syntax fix" }); @@ -995,6 +1024,7 @@ Clipperz.PM.DataModel.Record.defaultCardInfo = { '_searchableContent': MochiKit.Base.methodcaller('searchableContent'), '_accessDate': MochiKit.Base.methodcaller('accessDate'), '_isArchived': MochiKit.Base.methodcaller('isArchived'), + '_isBrandNew': MochiKit.Base.methodcaller('isBrandNew'), 'label': MochiKit.Base.methodcaller('label'), 'favicon': MochiKit.Base.methodcaller('favicon') }; diff --git a/frontend/delta/js/Clipperz/PM/DataModel/User.js b/frontend/delta/js/Clipperz/PM/DataModel/User.js index 6795c87..e1c459e 100644 --- a/frontend/delta/js/Clipperz/PM/DataModel/User.js +++ b/frontend/delta/js/Clipperz/PM/DataModel/User.js @@ -21,9 +21,12 @@ refer to http://www.clipperz.com. */ -if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } -if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } -if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } +"use strict"; +Clipperz.Base.module('Clipperz.PM.DataModel'); + +//if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +//if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +//if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } //############################################################################# @@ -656,6 +659,14 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { ], {trace:false}); }, + 'cloneRecord': function (aRecord) { +console.log("USER.cloneRecord", aRecord); + return Clipperz.Async.callbacks("User.cloneRecord", [ + MochiKit.Base.method(this, 'createNewRecord'), + MochiKit.Base.methodcaller('setUpWithRecord', aRecord) + ], {trace:false}); + }, + //========================================================================= 'getDirectLogins': function() { diff --git a/frontend/delta/tests/tests/Clipperz/PM/DataModel/Record.test.js b/frontend/delta/tests/tests/Clipperz/PM/DataModel/Record.test.js index 8c26e14..f9f8fde 100644 --- a/frontend/delta/tests/tests/Clipperz/PM/DataModel/Record.test.js +++ b/frontend/delta/tests/tests/Clipperz/PM/DataModel/Record.test.js @@ -1514,6 +1514,10 @@ deferredResult.addCallback(function (aValue) { console.log("FIELDS", aValue); re deferredResult.addMethodcaller('tags'); deferredResult.addCallback(SimpleTest.eq, ['Tag1', 'Tag2']); + deferredResult.addMethod(user, 'getRecord', recordID); + deferredResult.addMethodcaller('label'); + deferredResult.addTest("Card 1", "expected label"); + deferredResult.addMethod(user, 'getRecord', recordID); //deferredResult.addCallback(function (aValue) { console.log("VALUE", aValue); return aValue; }); deferredResult.addMethodcaller('addTag', "TagX"); @@ -1522,6 +1526,9 @@ deferredResult.addCallback(function (aValue) { console.log("FIELDS", aValue); re deferredResult.addMethodcaller('tags'); deferredResult.addCallback(SimpleTest.eq, ['Tag1', 'Tag2', 'TagX']); + deferredResult.addMethod(user, 'getRecord', recordID); + deferredResult.addMethodcaller('setLabel', "Card 1 - edited"); + deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "user should have pending changes"); deferredResult.addMethod(user, 'saveChanges'); diff --git a/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js b/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js index 1f646e8..b41bedf 100644 --- a/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js +++ b/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js @@ -1397,10 +1397,14 @@ var tests = { }); deferredResult.addMethod(user, 'createNewRecord'); - deferredResult.addMethodcaller('reference'); - deferredResult.addCallback(function (aNewRecordReference) { - newRecordReference = aNewRecordReference; - }) + deferredResult.addMethodcaller('hasPendingChanges'); +// deferredResult.addTest(true, "a brand new record should report pending changes until it is saved"); + deferredResult.addTest(false, "a brand new record should not report any pending changes until it is actually changed"); + +// deferredResult.addMethodcaller('reference'); +// deferredResult.addCallback(function (aNewRecordReference) { +// newRecordReference = aNewRecordReference; +// }) deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) {