Avoid overlapping saves ...

This commit is contained in:
Paulo Gustavo Veiga 2012-11-12 21:45:08 -03:00
parent 90b584569b
commit 8de31d9edc

View File

@ -46,22 +46,37 @@ mindplot.RESTPersistenceManager = new Class({
query = query + (this.timestamp ? "&timestamp=" + this.timestamp : "");
query = query + (this.session ? "&session=" + this.session : "");
if (!persistence.onSave) {
// Mark save in process and fire a event unlocking the save ...
persistence.onSave = true;
persistence.clearTimeout = setTimeout(function () {
persistence.clearTimeout = null;
persistence.onSave = false;
}, 10000);
var request = new Request({
url:this.saveUrl.replace("{id}", mapId) + "?" + query,
method:'put',
async:!sync,
onSuccess:function (responseText, responseXML) {
events.onSuccess();
persistence.timestamp = responseText;
events.onSuccess();
},
onException:function (headerName, value) {
console.log("onException....");
events.onError(persistence._buildError());
},
onComplete:function () {
// Clear event timeout ...
if (persistence.clearTimeout) {
clearTimeout(persistence.clearTimeout);
}
persistence.onSave = false;
},
onFailure:function (xhr) {
var responseText = xhr.responseText;
@ -85,7 +100,8 @@ mindplot.RESTPersistenceManager = new Class({
}
events.onError(userMsg);
// Only for debug. Remove.
// @Todo: Only for debug. Remove.
persistence.onSave = false;
throw new Error("responseText:" + responseText + ",status:" + this.status);
},
@ -94,6 +110,7 @@ mindplot.RESTPersistenceManager = new Class({
urlEncoded:false
});
request.put(JSON.encode(data));
}
},
discardChanges:function (mapId) {