Fixed an issue when editing a card label (without tags)

This commit is contained in:
Giulio Cesare Solaroli 2014-08-25 08:11:28 +02:00
parent 3c68167fb8
commit 3918a7bdfc
5 changed files with 77 additions and 22 deletions

View File

@ -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 || {};

View File

@ -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) {
@ -143,13 +146,18 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt
return this.getIndexDataForKey('label');
},
'updateFullLabelWithTags': function (someTags) {
return Clipperz.Async.callbacks("Record.updateFullLabelWithTags", [
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(' ');
'setFullLabel': function (aLabel, someTags) {
var fullLabel = MochiKit.Base.extend([aLabel], MochiKit.Base.map(function (aTag) { return Clipperz.PM.DataModel.Record.tagChar + aTag; }, someTags)).join(' ');
return this.setIndexDataForKey('label', fullLabel);
},
MochiKit.Base.method(this, 'setIndexDataForKey', 'label')
'updateTags': function (someTagInfo) {
return Clipperz.Async.callbacks("Record.updateTags", [
MochiKit.Base.method(this, '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')
};

View File

@ -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() {

View File

@ -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');

View File

@ -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) {