diff --git a/lib/edit/offlineFeaturesManager.js b/lib/edit/offlineFeaturesManager.js index 950d98f..9a2c6a2 100644 --- a/lib/edit/offlineFeaturesManager.js +++ b/lib/edit/offlineFeaturesManager.js @@ -322,9 +322,24 @@ define([ var promises = [] attachments.forEach(function(attachment) { - console.log("sending attachment", attachment.featureId); - promises.push( self._uploadAttachment(attachment) ); - }); + console.log("sending attachment", attachment.id, "to feature", attachment.featureId); + var uploadCompleted = self._uploadAttachment(attachment); + var deleteCompleted = new Deferred(); + uploadCompleted.then(function(attachmentId, deleteCompleted) // closure to keep attachmentId and deleteCompleted value + { + return function(result) + { + console.log("upload complete",result,attachmentId); + this.attachmentsStore.delete(attachmentId, function(success) + { + console.log("delete complete", result, success); + deleteCompleted.resolve(result); + }); + }.bind(this); + }.bind(this)(attachment.id, deleteCompleted) + ); + promises.push( deleteCompleted ); + }.bind(this)); console.log("promises", promises.length); var allPromises = new all(promises); allPromises.then(function(results) @@ -337,7 +352,7 @@ define([ console.log("error!",err); callback && callback(false); }); - }) + }.bind(this)) } diff --git a/test/spec/offlineAttachmentsSpec.js b/test/spec/offlineAttachmentsSpec.js index 947490f..08ed8d4 100644 --- a/test/spec/offlineAttachmentsSpec.js +++ b/test/spec/offlineAttachmentsSpec.js @@ -372,7 +372,7 @@ describe("Attachments", function() expect(g_editsStore.pendingEditsCount()).toBe(0); done(); }); - /* + async.it("no attachments pending", function(done) { g_featureLayers[3].attachmentsStore.getUsage(function(usage) @@ -381,9 +381,7 @@ describe("Attachments", function() done(); }); }); - */ - - /**/ + async.it("query attachments info - online - 1", function(done) { g_featureLayers[3].queryAttachmentInfos(g1_online.attributes.objectid, @@ -417,7 +415,6 @@ describe("Attachments", function() done(); }); }); - //*/ - }) + }); });