mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Avoid overlapping saves ...
This commit is contained in:
parent
90b584569b
commit
8de31d9edc
@ -46,54 +46,71 @@ mindplot.RESTPersistenceManager = new Class({
|
|||||||
query = query + (this.timestamp ? "×tamp=" + this.timestamp : "");
|
query = query + (this.timestamp ? "×tamp=" + this.timestamp : "");
|
||||||
query = query + (this.session ? "&session=" + this.session : "");
|
query = query + (this.session ? "&session=" + this.session : "");
|
||||||
|
|
||||||
var request = new Request({
|
if (!persistence.onSave) {
|
||||||
url:this.saveUrl.replace("{id}", mapId) + "?" + query,
|
|
||||||
method:'put',
|
|
||||||
async:!sync,
|
|
||||||
|
|
||||||
onSuccess:function (responseText, responseXML) {
|
// Mark save in process and fire a event unlocking the save ...
|
||||||
events.onSuccess();
|
persistence.onSave = true;
|
||||||
persistence.timestamp = responseText;
|
persistence.clearTimeout = setTimeout(function () {
|
||||||
},
|
persistence.clearTimeout = null;
|
||||||
|
persistence.onSave = false;
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
onException:function (headerName, value) {
|
var request = new Request({
|
||||||
console.log("onException....");
|
url:this.saveUrl.replace("{id}", mapId) + "?" + query,
|
||||||
|
method:'put',
|
||||||
|
async:!sync,
|
||||||
|
|
||||||
events.onError(persistence._buildError());
|
onSuccess:function (responseText, responseXML) {
|
||||||
},
|
persistence.timestamp = responseText;
|
||||||
|
events.onSuccess();
|
||||||
|
},
|
||||||
|
|
||||||
onFailure:function (xhr) {
|
onException:function (headerName, value) {
|
||||||
|
events.onError(persistence._buildError());
|
||||||
|
},
|
||||||
|
|
||||||
var responseText = xhr.responseText;
|
onComplete:function () {
|
||||||
var userMsg = {severity:"SEVERE", message:$msg('SAVE_COULD_NOT_BE_COMPLETED')};
|
// Clear event timeout ...
|
||||||
|
if (persistence.clearTimeout) {
|
||||||
var contentType = this.getHeader("Content-Type");
|
clearTimeout(persistence.clearTimeout);
|
||||||
if (contentType != null && contentType.indexOf("application/json") != -1) {
|
|
||||||
var serverMsg = null;
|
|
||||||
try {
|
|
||||||
serverMsg = JSON.decode(responseText);
|
|
||||||
serverMsg = serverMsg.globalSeverity ? serverMsg : null;
|
|
||||||
} catch (e) {
|
|
||||||
// Message could not be decoded ...
|
|
||||||
}
|
}
|
||||||
userMsg = persistence._buildError(serverMsg);
|
persistence.onSave = false;
|
||||||
|
},
|
||||||
|
|
||||||
} else {
|
onFailure:function (xhr) {
|
||||||
if (this.status == 405) {
|
|
||||||
userMsg = {severity:"SEVERE", message:$msg('SESSION_EXPIRED')};
|
var responseText = xhr.responseText;
|
||||||
|
var userMsg = {severity:"SEVERE", message:$msg('SAVE_COULD_NOT_BE_COMPLETED')};
|
||||||
|
|
||||||
|
var contentType = this.getHeader("Content-Type");
|
||||||
|
if (contentType != null && contentType.indexOf("application/json") != -1) {
|
||||||
|
var serverMsg = null;
|
||||||
|
try {
|
||||||
|
serverMsg = JSON.decode(responseText);
|
||||||
|
serverMsg = serverMsg.globalSeverity ? serverMsg : null;
|
||||||
|
} catch (e) {
|
||||||
|
// Message could not be decoded ...
|
||||||
|
}
|
||||||
|
userMsg = persistence._buildError(serverMsg);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (this.status == 405) {
|
||||||
|
userMsg = {severity:"SEVERE", message:$msg('SESSION_EXPIRED')};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
events.onError(userMsg);
|
||||||
events.onError(userMsg);
|
|
||||||
|
|
||||||
// Only for debug. Remove.
|
// @Todo: Only for debug. Remove.
|
||||||
throw new Error("responseText:" + responseText + ",status:" + this.status);
|
persistence.onSave = false;
|
||||||
},
|
throw new Error("responseText:" + responseText + ",status:" + this.status);
|
||||||
|
},
|
||||||
|
|
||||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||||
emulation:false,
|
emulation:false,
|
||||||
urlEncoded:false
|
urlEncoded:false
|
||||||
});
|
});
|
||||||
request.put(JSON.encode(data));
|
request.put(JSON.encode(data));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
discardChanges:function (mapId) {
|
discardChanges:function (mapId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user