Skip to content

Commit

Permalink
Closes #491, #492
Browse files Browse the repository at this point in the history
  • Loading branch information
andygup committed Nov 1, 2016
1 parent d61fcd6 commit f0913c0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
36 changes: 33 additions & 3 deletions lib/edit/OfflineEditAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ define([
_featureLayers: {},
_featureCollectionUsageFlag: false, // if a feature collection was used to create the feature layer.
_editStore: new O.esri.Edit.EditStore(),
_defaultXhrTimeout: 15000, // ms
_defaultXhrTimeout: 15000, // ms
_esriFieldTypeOID: "", // Determines the correct casing for objectid. Some feature layers use different casing

ONLINE: "online", // all edits will directly go to the server
OFFLINE: "offline", // edits will be enqueued
Expand Down Expand Up @@ -121,6 +122,14 @@ define([
// library will break and we'll have to re-architect how it manages UIDs.
layer.objectIdField = this.DB_UID;

// NOTE: set the casing for the feature layers objectid.
for(var i = 0; i < layer.fields.length; i++){
if(layer.fields[i].type === "esriFieldTypeOID"){
this._esriFieldTypeOID = layer.fields[i].name;
break;
}
}

var url = null;

// There have been reproducible use cases showing when a browser is restarted offline that
Expand Down Expand Up @@ -1896,7 +1905,28 @@ define([
});
}

// addResults present a special case for handling objectid
if(addResults.length > 0) {
var objectid = "";

if(addResults[0].hasOwnProperty("objectid")){
objectid = "objectid";
}

if(addResults[0].hasOwnProperty("objectId")){
objectid = "objectId";
}

if(addResults[0].hasOwnProperty("OBJECTID")){
objectid = "OBJECTID";
}

// ??? These are the most common objectid values. I may have missed some!

// Some feature layers will return different casing such as: 'objectid', 'objectId' and 'OBJECTID'
// Normalize these values to the feature type OID so that we don't break other aspects
// of the JS API.
adds[0].attributes[that._esriFieldTypeOID] = addResults[0][objectid];
var graphic = new Graphic(adds[0].geometry,null,adds[0].attributes);
layer.add(graphic);
}
Expand Down Expand Up @@ -2051,11 +2081,11 @@ define([
if( req.status === 200 && req.responseText !== "")
{
try {
var obj = JSON.parse(this.response);
var obj = JSON.parse(this.responseText);
callback(obj.addResults, obj.updateResults, obj.deleteResults);
}
catch(err) {
console.error("EDIT REQUEST RESPONSE WAS NOT SUCCESSFUL:", req);
console.error("FAILED TO PARSE EDIT REQUEST RESPONSE:", req);
errback("Unable to parse xhr response", req);
}
}
Expand Down
38 changes: 35 additions & 3 deletions lib/edit/OfflineEditBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ define([
_onlineStatus: "online",
_featureLayers: {},
_editStore: new O.esri.Edit.EditStorePOLS(),
_defaultXhrTimeout: 15000, // ms
_defaultXhrTimeout: 15000, // ms
_autoOfflineDetect: true,
_esriFieldTypeOID: "", // Determines the correct casing for objectid. Some feature layers use different casing

ONLINE: "online", // all edits will directly go to the server
OFFLINE: "offline", // edits will be enqueued
Expand Down Expand Up @@ -76,6 +77,14 @@ define([
// library will break and we'll have to re-architect how it manages UIDs.
layer.objectIdField = this.DB_UID;

// NOTE: set the casing for the feature layers objectid.
for(var i = 0; i < layer.fields.length; i++){
if(layer.fields[i].type === "esriFieldTypeOID"){
this._esriFieldTypeOID = layer.fields[i].name;
break;
}
}

var url = null;

// There have been reproducible use cases showing when a browser is restarted offline that
Expand Down Expand Up @@ -820,7 +829,29 @@ define([
this._makeEditRequest(layer, adds, updates, deletes,
function (addResults, updateResults, deleteResults) {

// addResults present a special case for handling objectid
if(addResults.length > 0) {

var objectid = "";

if(addResults[0].hasOwnProperty("objectid")){
objectid = "objectid";
}

if(addResults[0].hasOwnProperty("objectId")){
objectid = "objectId";
}

if(addResults[0].hasOwnProperty("OBJECTID")){
objectid = "OBJECTID";
}

// ??? These are the most common objectid values. I may have missed some!

// Some feature layers will return different casing such as: 'objectid', 'objectId' and 'OBJECTID'
// Normalize these values to the feature type OID so that we don't break other aspects
// of the JS API.
adds[0].attributes[that._esriFieldTypeOID] = addResults[0][objectid];
var graphic = new Graphic(adds[0].geometry,null,adds[0].attributes);
layer.add(graphic);
}
Expand Down Expand Up @@ -962,11 +993,12 @@ define([
if( req.status === 200 && req.responseText !== "")
{
try {
var obj = JSON.parse(this.response);
// var b = this.responseText.replace(/"/g, "'"); // jshint ignore:line
var obj = JSON.parse(this.responseText);
callback(obj.addResults, obj.updateResults, obj.deleteResults);
}
catch(err) {
console.error("EDIT REQUEST REPONSE WAS NOT SUCCESSFUL:", req);
console.error("FAILED TO PARSE EDIT REQUEST RESPONSE:", req);
errback("Unable to parse xhr response", req);
}
}
Expand Down

0 comments on commit f0913c0

Please sign in to comment.