update existing edit + unit test

This commit is contained in:
Andy Gup 2015-02-18 11:52:28 -07:00
parent 150dd1b72d
commit 9f565d2d1d
2 changed files with 52 additions and 0 deletions

View File

@ -68,6 +68,47 @@ O.esri.Edit.EditStore = function()
}
};
/**
* Update an edit already exists in the database
* @param operation add, update or delete
* @param layer the URL of the feature layer
* @param graphic esri/graphic. The method will serialize to JSON
* @param callback {true, edit} or {false, error}
*/
this.updateExistingEdit = function(operation,layer,graphic, callback){
console.assert(this._db !== null, "indexeddb not initialized");
var objectStore = this._db.transaction([objectStoreName],"readwrite").objectStore(objectStoreName);
//Let's get the entry associated with the graphic
var objectStoreGraphicRequest = objectStore.get(graphic.attributes.objectid);
objectStoreGraphicRequest.onsuccess = function() {
//Grab the data object returned as a result
var data = objectStoreGraphicRequest.result;
//Create a new update object
var update = {
id: graphic.attributes.objectid,
operation: operation,
layer: layer,
graphic: graphic.toJson()
};
// Insert the update into the database
var updateGraphicRequest = objectStore.put(update);
updateGraphicRequest.onsuccess = function(){
callback(true);
}
updateGraphicRequest.onerror = function(err){
callback(false,err);
};
}
};
this.resetEditsQueue = function(callback)
{
console.assert(this._db !== null, "indexeddb not initialized");

View File

@ -266,6 +266,17 @@ describe("Public Interface", function()
});
});
async.it("update existing edit in the queue", function(done)
{
require(["esri/graphic"],function(Graphic){
g_test.lineFeature = new Graphic( g_test.line, g_test.lineSymbol, {"nombre": "America","objectid":5});
g_editsStore.updateExistingEdit(g_editsStore.DELETE,2, g_test.lineFeature, function(result){
expect(result).toEqual(true);
done();
});
});
});
// it("pending edits", function()
// {
// expect(g_editsStore.hasPendingEdits()).toBeTruthy();