new method to delete all attachments of a feature

This commit is contained in:
Javier Abadia 2014-04-09 23:19:23 +02:00
parent 1291976bbb
commit 0d66b7e4c9
3 changed files with 54 additions and 1 deletions

View File

@ -104,6 +104,30 @@ define([], function()
}
}
this.deleteAttachmentsByFeatureId = function(featureLayerUrl,objectId,callback)
{
var featureId = featureLayerUrl + "/" + objectId;
var objectStore = this._db.transaction([OBJECT_STORE_NAME],"readwrite").objectStore(OBJECT_STORE_NAME);
var index = objectStore.index("featureId");
var keyRange = IDBKeyRange.only(featureId);
var deletedCount = 0;
index.openKeyCursor(keyRange).onsuccess = function(evt)
{
var cursor = evt.target.result;
if(cursor)
{
objectStore.delete(cursor.primaryKey);
deletedCount++;
cursor.continue()
}
else
{
callback(deletedCount);
}
}
}
this.delete = function(attachmentId)
{
console.assert(false, "not implemented");

View File

@ -261,7 +261,6 @@ define([
reader.readAsBinaryString(file);
};
});
}
layer.deleteAttachments = function(objectId,attachmentsIds,callback,errback){

View File

@ -101,6 +101,36 @@ describe("attachments store module", function()
});
});
async.it("delete attachments of a single feature", function(done)
{
g_attachmentsStore.deleteAttachmentsByFeatureId("layer1", 300, function(deletedCount)
{
expect(deletedCount).toBe(0);
setTimeout(function()
{
g_attachmentsStore.getUsage(function(usage)
{
expect(usage).not.toBeNull();
expect(usage.attachmentCount).toBe(testData.length);
g_attachmentsStore.deleteAttachmentsByFeatureId("layer1", 1, function(deletedCount)
{
expect(deletedCount).toBe(2);
setTimeout(function()
{
g_attachmentsStore.getUsage(function(usage)
{
expect(usage).not.toBeNull();
expect(usage.attachmentCount).toBe(testData.length -2);
done();
})
});
});
});
});
});
});
async.it("delete all attachments", function(done)
{
g_attachmentsStore.deleteAll(function(success)