diff --git a/lib/edit/offlineFeaturesManager.js b/lib/edit/offlineFeaturesManager.js index 249c444..9c19736 100644 --- a/lib/edit/offlineFeaturesManager.js +++ b/lib/edit/offlineFeaturesManager.js @@ -20,6 +20,13 @@ define([ OFFLINE: "offline", // edits will be enqueued RECONNECTING: "reconnecting", // sending stored edits to the server + // manager emits event when... + events: { + EDITS_SENT: 'edits-sent', // ...whenever any edit is actually sent to the server + EDITS_ENQUEUED: 'edits-enqueued', // ...when an edit is enqueued (and not sent to the server) + ALL_EDITS_SENT: 'all-edits-sent' // ...after going online and there are no pending edits in the queue + }, + extend: function(layer) { var self = this; @@ -34,12 +41,13 @@ define([ { // inside this method, 'this' will be the FeatureLayer // and 'self' will be the offlineFeatureLayer object + if( self.getOnlineStatus() == self.ONLINE) { var def = layer._applyEdits(adds,updates,deletes, function() { - self.emit('edits-sent',arguments); + self.emit(self.events.EDITS_SENT,arguments); callback && callback.apply(this,arguments); }, errback); @@ -52,7 +60,6 @@ define([ var updatesMap = {}; this.onBeforeApplyEdits(adds, updates, deletes); - //this.emit('before-apply-edits', [adds,updates,deletes]); adds = adds || []; adds.forEach(function(addEdit) @@ -81,7 +88,7 @@ define([ /* we already pushed the edits into the local store, now we let the FeatureLayer to do the local updating of the layer graphics */ this._editHandler(results, adds, updatesMap, callback, errback, deferred); - self.emit('edits-enqueued', results); + self.emit(self.events.EDITS_ENQUEUED, results); return deferred; } }; // layer.applyEdits() @@ -237,21 +244,21 @@ define([ function(responses) { console.log("all responses are back"); - // self.emit('edits-sent'); - this.emit('all-edits-sent',{}); - callback && callback(); + this.emit(this.events.EDITS_SENT); + this.emit(this.events.ALL_EDITS_SENT); + callback && callback(true,responses); }.bind(this), function(errors) { console.log("ERROR!!"); console.log(errors); - callback && callback(errors); + callback && callback(false,errors); }.bind(this)); } // hasPendingEdits() else { - this.emit('all-edits-sent',{}); - callback && callback(); + this.emit(this.events.ALL_EDITS_SENT); + callback && callback(true, {}); } }, diff --git a/samples/military-offline.html b/samples/military-offline.html index 80cf253..10276ca 100644 --- a/samples/military-offline.html +++ b/samples/military-offline.html @@ -129,9 +129,9 @@ on(dom.byId('go-online-btn'),'click', goOnline); on(dom.byId('refresh-feature-layers-btn'),'click', refreshFeatureLayers); var offlineFeaturesManager = new OfflineFeaturesManager(); - offlineFeaturesManager.on('edits-enqueued', updateStatus); - offlineFeaturesManager.on('edits-sent', updateStatus); - offlineFeaturesManager.on('all-edits-sent', updateStatus); + offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_ENQUEUED, updateStatus); + offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_SENT, updateStatus); + offlineFeaturesManager.on(offlineFeaturesManager.events.ALL_EDITS_SENT, updateStatus); updateConnectivityIndicator(); updateStorageInfo();