mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
prevent attributeEditor to appear after replaying the stored edits
be careful with updates for features added offline (replace tmp id by final id), (ongoing)
This commit is contained in:
parent
36651ee221
commit
1f2c10e0ea
@ -3,13 +3,12 @@
|
||||
- adds: OK
|
||||
- deletes: OK
|
||||
- change pushEdit() to pushEdits(), NO
|
||||
- control QuotaError error gracefully, ONGOING
|
||||
|
||||
- control QuotaError error gracefully, OK
|
||||
- try and fill localStorage to see what happens... OK, localStorage.setItem() throws error
|
||||
- prevent attributeEditor to appear after replaying the stored edits
|
||||
- be careful with updates for features added offline (replace tmp id by final id)
|
||||
- goOnline()/goOffline() automatically
|
||||
- prevent attributeEditor to appear after replaying the stored edits, OK
|
||||
- be careful with updates for features added offline (replace tmp id by final id), ONGOING
|
||||
|
||||
- goOnline()/goOffline() automatically
|
||||
- unit tests
|
||||
- feedback graphics layer
|
||||
- add timestamp to edits
|
||||
|
||||
@ -88,6 +88,11 @@ define(["esri/graphic"], function(Graphic)
|
||||
return null;
|
||||
},
|
||||
|
||||
replaceTempId: function(tempId, objectid)
|
||||
{
|
||||
console.log("temp:",tempId,"objectid:",objectid);
|
||||
},
|
||||
|
||||
hasPendingEdits: function()
|
||||
{
|
||||
var storedValue = window.localStorage.getItem(EDITS_QUEUE_KEY) || "";
|
||||
|
||||
@ -17,11 +17,9 @@ define([
|
||||
{
|
||||
var self = this;
|
||||
|
||||
// we keep track of the FeatureLayer object
|
||||
this._featureLayers[ layer.url ] = layer;
|
||||
|
||||
// layer.on('before-apply-edits', function(){ console.log('before-apply-edits');});
|
||||
// layer.on('edits-complete', function(){ console.log('edits-complete');});
|
||||
|
||||
/* replace the applyEdits() method */
|
||||
layer._applyEdits = layer.applyEdits;
|
||||
layer.applyEdits = function(adds,updates,deletes,callback,errback)
|
||||
@ -30,8 +28,13 @@ define([
|
||||
// and 'self' will be the offlineFeatureLayer object
|
||||
if( self.isOnline() )
|
||||
{
|
||||
self.emit('edits-sent',{});
|
||||
var def = layer._applyEdits(adds,updates,deletes,callback,errback);
|
||||
var def = layer._applyEdits(adds,updates,deletes,
|
||||
function()
|
||||
{
|
||||
self.emit('edits-sent',arguments);
|
||||
callback && callback.apply(this,arguments);
|
||||
},
|
||||
errback);
|
||||
return def;
|
||||
}
|
||||
else
|
||||
@ -71,23 +74,26 @@ define([
|
||||
deferred.resolve([addResults,updateResults,deleteResults])
|
||||
|
||||
this.emit('edits-complete', { adds: addResults, updates:updateResults, deletes:deleteResults });
|
||||
self.emit('edits-enqueued',{});
|
||||
|
||||
if(callback)
|
||||
callback({ adds: addResults, updates:updateResults, deletes:deleteResults });
|
||||
self.emit('edits-enqueued', { adds: addResults, updates:updateResults, deletes:deleteResults });
|
||||
|
||||
callback && callback({ adds: addResults, updates:updateResults, deletes:deleteResults });
|
||||
|
||||
return deferred;
|
||||
}
|
||||
}; // layer.applyEdits()
|
||||
|
||||
layer._nextTempId = -1;
|
||||
|
||||
// we need to identify ADDs before sending them to the server
|
||||
// we assign temporary ids (using negative numbers to distinguish them from real ids)
|
||||
layer._nextTempId = -1;
|
||||
layer.getNextTempId = function()
|
||||
{
|
||||
return this._nextTempId--;
|
||||
};
|
||||
|
||||
}, // extend
|
||||
|
||||
|
||||
goOffline: function()
|
||||
{
|
||||
console.log('going offline');
|
||||
@ -107,17 +113,20 @@ define([
|
||||
return this._online;
|
||||
},
|
||||
|
||||
|
||||
replayStoredEdits: function()
|
||||
{
|
||||
if( editsStore.hasPendingEdits() )
|
||||
{
|
||||
var edit = editsStore.peekFirstEdit();
|
||||
var layer = this._featureLayers[ edit.layer ];
|
||||
var tempId = null;
|
||||
|
||||
var adds = [], updates = [], deletes = [];
|
||||
switch(edit.operation)
|
||||
{
|
||||
case editsStore.ADD:
|
||||
tempId = edit.graphic.attributes[ layer.objectIdField ];
|
||||
delete edit.graphic.attributes[ layer.objectIdField ];
|
||||
adds.push(edit.graphic);
|
||||
break;
|
||||
@ -131,17 +140,40 @@ define([
|
||||
|
||||
var self = this;
|
||||
console.log("sending edits",adds,updates,deletes);
|
||||
layer._applyEdits(adds,updates,deletes, //jabadia: avoid this to trigger events (or not?) it opens the infoWindow
|
||||
function()
|
||||
{
|
||||
|
||||
// now, we remove the obBeforeApplyEdits && onEditsComplete handlers from the FeatureLayer
|
||||
// we already sent the events when the edit was kept in localStorage, and we don't want
|
||||
// to send them again. It causes some problems When using the esri/dijit/editing/Editor,
|
||||
// for instance opening the attributeEditor again after sending the edits
|
||||
var onEditsComplete = layer["onEditsComplete"];
|
||||
layer["onEditsComplete"] = function() { console.log("intercepting events onEditsComplete");}
|
||||
var onBeforeApplyEdits = layer["onBeforeApplyEdits"];
|
||||
layer["onBeforeApplyEdits"] = function() { console.log("intercepting events onBeforeApplyEdits");}
|
||||
|
||||
layer._applyEdits(adds,updates,deletes,
|
||||
function(addResults,updateResults,deleteResults) // success
|
||||
{
|
||||
// restore event handlers
|
||||
layer["onEditsComplete"] = onEditsComplete;
|
||||
layer["onBeforeApplyEdits"] = onBeforeApplyEdits;
|
||||
editsStore.popFirstEdit();
|
||||
console.log("edits-sent");
|
||||
self.emit('edits-sent',{});
|
||||
if( addResults )
|
||||
{
|
||||
editsStore.replaceTempId(tempId, addResults[0].objectId);
|
||||
}
|
||||
self.emit('edits-sent',arguments);
|
||||
self.replayStoredEdits();
|
||||
},
|
||||
function(err)
|
||||
{
|
||||
// restore event handlers
|
||||
layer["onEditsComplete"] = onEditsComplete;
|
||||
layer["onBeforeApplyEdits"] = onBeforeApplyEdits;
|
||||
console.log(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
}, // replayStoredEdits()
|
||||
|
||||
}); // declare
|
||||
}); // define
|
||||
}); // define
|
||||
|
||||
@ -166,7 +166,6 @@
|
||||
function initEditor(evt)
|
||||
{
|
||||
try {
|
||||
|
||||
/* extend layer with offline detection functionality */
|
||||
evt.layers.forEach(function(result)
|
||||
{
|
||||
@ -176,7 +175,13 @@
|
||||
|
||||
// jabadia: only if we have internet available
|
||||
offlineFeatureService.replayStoredEdits();
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
try {
|
||||
/* template picker */
|
||||
var templateLayers = evt.layers.map(function(result){return result.layer;});
|
||||
var templatePicker = new TemplatePicker({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user