fixed offline restart lifecycle issue

This commit is contained in:
Andy Gup 2015-03-26 08:52:02 -06:00
parent 8e87906977
commit 8db4333f56

View File

@ -1330,54 +1330,54 @@ define([
promises[n] = that._internalApplyEdits(layer, tempArray[n].id, tempObjectIds, adds, updates, deletes);
}
// wait for all requests to finish
// responses contain {id,layer,tempId,addResults,updateResults,deleteResults}
var allPromises = all(promises);
allPromises.then(
function (responses) {
console.log("OfflineFeaturesManager - all responses are back");
this._cleanSuccessfulEditsDatabaseRecords(responses, function (success, error) {
// If successful then we delete all phantom graphics in the DB.
if (success) {
console.log("_replayStoredEdits: CLEANED EDITS DATABASE");
this._editStore.resetPhantomGraphicsQueue(function (success) {
if (success == false) {
console.log("There was a problem deleting phantom graphics in the database.");
this.emit(this.events.EDITS_SENT_ERROR, {msg: "Problem deleting phantom graphic(s)"});
}
else {
console.log("CLEANED PHANTOM GRAPHICS DATABASE");
this.emit(this.events.ALL_EDITS_SENT,responses);
}
callback && callback(true, responses);
}.bind(this))
}
// If not successful then we only delete the phantom graphics that are related to
// edits that were successfully synced
else {
console.error("_replayStoredEdits: There was a problem and not all edits were cleaned.");
this._editStore.resetLimitedPhantomGraphicsQueue(responses, function (success) {
if(!success) console.error("_replayStoredEdits.resetLimitedPhantomGraphicsQueue: There was a problem clearing the queue " + JSON.stringify(error))
});
this.emit(this.events.EDITS_SENT_ERROR, {msg: responses}); // There was a problem, some edits were not successfully sent!
callback && callback(false, responses);
}
}.bind(that));
}.bind(that),
function (errors) {
console.log("OfflineFeaturesManager._replayStoredEdits - ERROR!!");
console.log(errors);
callback && callback(false, errors);
}.bind(that)
);
}
else{
// No edits were found
callback(true,[]);
}
// wait for all requests to finish
// responses contain {id,layer,tempId,addResults,updateResults,deleteResults}
var allPromises = all(promises);
allPromises.then(
function (responses) {
console.log("OfflineFeaturesManager - all responses are back");
this._cleanSuccessfulEditsDatabaseRecords(responses, function (success, error) {
// If successful then we delete all phantom graphics in the DB.
if (success) {
console.log("_replayStoredEdits: CLEANED EDITS DATABASE");
this._editStore.resetPhantomGraphicsQueue(function (success) {
if (success == false) {
console.log("There was a problem deleting phantom graphics in the database.");
this.emit(this.events.EDITS_SENT_ERROR, {msg: "Problem deleting phantom graphic(s)"});
}
else {
console.log("CLEANED PHANTOM GRAPHICS DATABASE");
this.emit(this.events.ALL_EDITS_SENT,responses);
}
callback && callback(true, responses);
}.bind(this))
}
// If not successful then we only delete the phantom graphics that are related to
// edits that were successfully synced
else {
console.error("_replayStoredEdits: There was a problem and not all edits were cleaned.");
this._editStore.resetLimitedPhantomGraphicsQueue(responses, function (success) {
if(!success) console.error("_replayStoredEdits.resetLimitedPhantomGraphicsQueue: There was a problem clearing the queue " + JSON.stringify(error))
});
this.emit(this.events.EDITS_SENT_ERROR, {msg: responses}); // There was a problem, some edits were not successfully sent!
callback && callback(false, responses);
}
}.bind(that));
}.bind(that),
function (errors) {
console.log("OfflineFeaturesManager._replayStoredEdits - ERROR!!");
console.log(errors);
callback && callback(false, errors);
}.bind(that)
);
});
},