From 9f565d2d1db99682a9056d075666e79eebde5fdf Mon Sep 17 00:00:00 2001 From: Andy Gup Date: Wed, 18 Feb 2015 11:52:28 -0700 Subject: [PATCH] update existing edit + unit test --- lib/edit/editsStore.js | 41 ++++++++++++++++++++++++++++++++++++ test/spec/editsStoreSpec2.js | 11 ++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/edit/editsStore.js b/lib/edit/editsStore.js index 9a500a2..046dc57 100644 --- a/lib/edit/editsStore.js +++ b/lib/edit/editsStore.js @@ -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"); diff --git a/test/spec/editsStoreSpec2.js b/test/spec/editsStoreSpec2.js index 4bdc0ca..9052f29 100644 --- a/test/spec/editsStoreSpec2.js +++ b/test/spec/editsStoreSpec2.js @@ -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();