mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
RestPersisnteceManager reimplemented with ajax
This commit is contained in:
parent
d41a261897
commit
8cb45c587f
@ -16,7 +16,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//FIXME: remove Request class
|
|
||||||
mindplot.RESTPersistenceManager = new Class({
|
mindplot.RESTPersistenceManager = new Class({
|
||||||
Extends:mindplot.PersistenceManager,
|
Extends:mindplot.PersistenceManager,
|
||||||
initialize:function (options) {
|
initialize:function (options) {
|
||||||
@ -56,38 +55,38 @@ mindplot.RESTPersistenceManager = new Class({
|
|||||||
persistence.onSave = false;
|
persistence.onSave = false;
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
var request = new Request({
|
$.ajax({
|
||||||
url: this.documentUrl.replace("{id}", mapId) + "?" + query,
|
url: this.documentUrl.replace("{id}", mapId) + "?" + query,
|
||||||
|
headers:{"Content-Type":"application/json; charset=utf-8", "Accept":"application/json"},
|
||||||
method:'put',
|
method:'put',
|
||||||
async:!sync,
|
async:!sync,
|
||||||
|
dataType: "json",
|
||||||
|
data: data,
|
||||||
|
|
||||||
onSuccess:function (responseText, responseXML) {
|
success: function (data, textStatus, jqXHRresponseText) {
|
||||||
persistence.timestamp = responseText;
|
persistence.timestamp = jqXHRresponseText;
|
||||||
events.onSuccess();
|
events.onSuccess();
|
||||||
},
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
onException:function (headerName, value) {
|
|
||||||
events.onError(persistence._buildError());
|
events.onError(persistence._buildError());
|
||||||
},
|
},
|
||||||
|
complete: function () {
|
||||||
onComplete:function () {
|
|
||||||
// Clear event timeout ...
|
// Clear event timeout ...
|
||||||
if (persistence.clearTimeout) {
|
if (persistence.clearTimeout) {
|
||||||
clearTimeout(persistence.clearTimeout);
|
clearTimeout(persistence.clearTimeout);
|
||||||
}
|
}
|
||||||
persistence.onSave = false;
|
persistence.onSave = false;
|
||||||
},
|
},
|
||||||
|
fail:function (xhr, textStatus) {
|
||||||
onFailure:function (xhr) {
|
|
||||||
|
|
||||||
var responseText = xhr.responseText;
|
var responseText = xhr.responseText;
|
||||||
var userMsg = {severity:"SEVERE", message:$msg('SAVE_COULD_NOT_BE_COMPLETED')};
|
var userMsg = {severity:"SEVERE", message:$msg('SAVE_COULD_NOT_BE_COMPLETED')};
|
||||||
|
|
||||||
var contentType = this.getHeader("Content-Type");
|
var contentType = xhr.getResponseHeader("Content-Type");
|
||||||
if (contentType != null && contentType.indexOf("application/json") != -1) {
|
if (contentType != null && contentType.indexOf("application/json") != -1) {
|
||||||
var serverMsg = null;
|
var serverMsg = null;
|
||||||
try {
|
try {
|
||||||
serverMsg = JSON.decode(responseText);
|
serverMsg = $.parseJSON(responseText);
|
||||||
serverMsg = serverMsg.globalSeverity ? serverMsg : null;
|
serverMsg = serverMsg.globalSeverity ? serverMsg : null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Message could not be decoded ...
|
// Message could not be decoded ...
|
||||||
@ -101,52 +100,29 @@ mindplot.RESTPersistenceManager = new Class({
|
|||||||
}
|
}
|
||||||
events.onError(userMsg);
|
events.onError(userMsg);
|
||||||
persistence.onSave = false;
|
persistence.onSave = false;
|
||||||
},
|
}
|
||||||
|
|
||||||
headers:{"Content-Type":"application/json; charset=utf-8", "Accept":"application/json"},
|
|
||||||
emulation:false,
|
|
||||||
urlEncoded:false
|
|
||||||
});
|
});
|
||||||
request.put(JSON.encode(data));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
discardChanges:function (mapId) {
|
discardChanges:function (mapId) {
|
||||||
var request = new Request({
|
$.ajax({
|
||||||
url:this.revertUrl.replace("{id}", mapId),
|
url:this.revertUrl.replace("{id}", mapId),
|
||||||
async:false,
|
async:false,
|
||||||
method:'post',
|
method:'post',
|
||||||
onSuccess:function () {
|
headers:{"Content-Type":"application/json; charset=utf-8", "Accept":"application/json"}
|
||||||
},
|
|
||||||
onException:function () {
|
|
||||||
},
|
|
||||||
onFailure:function () {
|
|
||||||
},
|
|
||||||
headers:{"Content-Type":"application/json; charset=utf-8", "Accept":"application/json"},
|
|
||||||
emulation:false,
|
|
||||||
urlEncoded:false
|
|
||||||
});
|
});
|
||||||
request.post();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unlockMap:function (mindmap) {
|
unlockMap:function (mindmap) {
|
||||||
var mapId = mindmap.getId();
|
var mapId = mindmap.getId();
|
||||||
var request = new Request({
|
$.ajax({
|
||||||
url:this.lockUrl.replace("{id}", mapId),
|
url:this.lockUrl.replace("{id}", mapId),
|
||||||
async:false,
|
async:false,
|
||||||
method:'put',
|
method:'put',
|
||||||
onSuccess:function () {
|
|
||||||
|
|
||||||
},
|
|
||||||
onException:function () {
|
|
||||||
},
|
|
||||||
onFailure:function () {
|
|
||||||
},
|
|
||||||
headers:{"Content-Type":"text/plain"},
|
headers:{"Content-Type":"text/plain"},
|
||||||
emulation:false,
|
data: "false"
|
||||||
urlEncoded:false
|
|
||||||
});
|
});
|
||||||
request.put("false");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildError:function (jsonSeverResponse) {
|
_buildError:function (jsonSeverResponse) {
|
||||||
|
@ -14,11 +14,11 @@ function createStorageManager(mindplot) {
|
|||||||
|
|
||||||
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
|
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
|
||||||
var url = this.backendUrl + mapId;
|
var url = this.backendUrl + mapId;
|
||||||
var xmlRequest = new Request({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
async: false,
|
async: false,
|
||||||
onSuccess: function(responseText) {
|
success: function(responseText) {
|
||||||
events.onSuccess();
|
events.onSuccess();
|
||||||
},
|
},
|
||||||
onError: function (text, error) {
|
onError: function (text, error) {
|
||||||
@ -26,20 +26,18 @@ function createStorageManager(mindplot) {
|
|||||||
events.onError();
|
events.onError();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
xmlRequest.send();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
loadMapDom : function(mapId) {
|
loadMapDom : function(mapId) {
|
||||||
var xml;
|
var xml;
|
||||||
var xmlRequest = new Request({
|
$.ajax({
|
||||||
url: this.backendUrl + mapId,
|
url: this.backendUrl + mapId,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
async: false,
|
async: false,
|
||||||
onSuccess: function(responseText) {
|
success: function(responseText) {
|
||||||
xml = responseText;
|
xml = responseText;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
xmlRequest.send();
|
|
||||||
|
|
||||||
// If I could not load it from a file, hard code one.
|
// If I could not load it from a file, hard code one.
|
||||||
if (xml == null) {
|
if (xml == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user