added promises to extend.update

This commit is contained in:
Andy Gup 2015-02-19 18:51:34 -07:00
parent 7c18f8832a
commit cb2c9a7f23
3 changed files with 643 additions and 602 deletions

View File

@ -121,10 +121,16 @@ define([
* @param layer
* @returns deferred
*/
extend: function(layer)
extend: function(layer,callback)
{
var self = this;
// Attempt to initialize the database
self._editStore.init(function(result){
callback(result);
return;
});
// we keep track of the FeatureLayer object
this._featureLayers[ layer.url ] = layer;
@ -318,6 +324,8 @@ define([
// inside this method, 'this' will be the FeatureLayer
// and 'self' will be the offlineFeatureLayer object
var promises = [];
if( self.getOnlineStatus() === self.ONLINE)
{
var def = this._applyEdits(adds,updates,deletes,
@ -360,22 +368,29 @@ define([
updates = updates || [];
updates.forEach(function(updateEdit)
{
var objectId = updateEdit.attributes[ this.objectIdField ];
var result = self._editStore.pushEdit(self._editStore.UPDATE, this.url, updateEdit);
results.updateResults.push({success:result.success, error: result.error, objectId: objectId});
var deferred = new Deferred();
var objectId = updateEdit.attributes[ this.objectIdField ]; console.log("OBJECT ID " + objectId);
updatesMap[ objectId ] = updateEdit;
if(result.success)
{
var phantomUpdate = new Graphic(
updateEdit.geometry,
self._getPhantomSymbol(updateEdit.geometry, self._editStore.UPDATE),
{
objectId: objectId
});
this._phantomLayer.add(phantomUpdate);
domAttr.set(phantomUpdate.getNode(),"stroke-dasharray","5,2");
domStyle.set(phantomUpdate.getNode(), "pointer-events","none");
}
var phantomLayer = this._phantomLayer;
self._editStore.pushEdit(self._editStore.UPDATE, this.url, updateEdit,function(result,error){
result == true ? deferred.resolve(result) : deferred.reject(error);
});
results.updateResults.push({success:true, error: null, objectId: objectId});
console.log("UPDATE RESULTS " + results.updateResults.length);
var phantomUpdate = new Graphic(
updateEdit.geometry,
self._getPhantomSymbol(updateEdit.geometry, self._editStore.UPDATE),
{
objectId: objectId
});
phantomLayer.add(phantomUpdate);
domAttr.set(phantomUpdate.getNode(),"stroke-dasharray","5,2");
domStyle.set(phantomUpdate.getNode(), "pointer-events","none");
promises.push(deferred);
},this);
deletes = deletes || [];
@ -406,13 +421,17 @@ define([
}
},this);
/* we already pushed the edits into the local store, now we let the FeatureLayer to do the local updating of the layer graphics */
setTimeout(function()
{
this._editHandler(results, adds, updatesMap, callback, errback, deferred);
self.emit(self.events.EDITS_ENQUEUED, results);
}.bind(this),0);
return deferred;
all(promises).then( function(r)
{ console.log("RR " + r)
/* we already pushed the edits into the database, now we let the FeatureLayer to do the local updating of the layer graphics */
setTimeout(function()
{ console.log("HAHAH " + results.updateResults.length + " ," + updatesMap);
this._editHandler(results, adds, updatesMap, callback, errback, deferred);
self.emit(self.events.EDITS_ENQUEUED, results);
}.bind(this),0);
return deferred;
}.bind(this));
}; // layer.applyEdits()
/**

View File

@ -19,9 +19,9 @@
}
</script>
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
<script src="http://js.arcgis.com/3.10/"></script>
<link rel="stylesheet" href="http://js.arcgis.com/3.12/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.12/esri/css/esri.css">
<script src="http://js.arcgis.com/3.12/"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/offlineFeaturesManagerSpec.js"></script>
@ -39,7 +39,7 @@
"esri/layers/FeatureLayer", "esri/geometry", "esri/request",
"dojo/dom", "dojo/on", "dojo/query",
"dojo/dom-construct",
"../dist/offline-edit-min.js",
"../dist/offline-edit-src.js",
"dojo/domReady!"],
function(Map,
GraphicsLayer, Graphic,
@ -61,8 +61,10 @@
});
var fsUrl = "http://services2.arcgis.com/CQWCKwrSm5dkM28A/arcgis/rest/services/Military/FeatureServer/";
// var layersIds = [0,1,2,3,4,5,6];
var layersIds = [1,2,3,6];
// Layer 1 = points
// Layer 2 = lines
// Layer 3 = polygons
var layersIds = [1,2,3];
layersIds.forEach(function(layerId)
{
@ -83,7 +85,9 @@
{
g_featureLayers.forEach(function(layer)
{
g_offlineFeaturesManager.extend(layer);
g_offlineFeaturesManager.extend(layer,function(result){
if(result == false) alert("Unable to initialize database");
});
});
}
catch(err)

File diff suppressed because it is too large Load Diff