mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
new method to delete all attachments of a feature
This commit is contained in:
parent
1291976bbb
commit
0d66b7e4c9
@ -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");
|
||||
|
||||
@ -261,7 +261,6 @@ define([
|
||||
reader.readAsBinaryString(file);
|
||||
};
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
layer.deleteAttachments = function(objectId,attachmentsIds,callback,errback){
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user