Add support for revert changes ...
This commit is contained in:
@@ -27,7 +27,7 @@ mindplot.LocalStorageManager = new Class({
|
||||
events.onSuccess();
|
||||
},
|
||||
|
||||
discard : function(mapId) {
|
||||
discardChanges : function(mapId) {
|
||||
localStorage.removeItem(mapId + "-xml");
|
||||
},
|
||||
|
||||
|
@@ -21,7 +21,6 @@ mindplot.Messages = new Class({
|
||||
init:function (locale) {
|
||||
locale = $defined(locale) ? locale : 'en';
|
||||
mindplot.Messages.__bundle = mindplot.Messages.BUNDLES[locale];
|
||||
console.log(mindplot.Messages.__bundle);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -47,7 +47,7 @@ mindplot.PersistenceManager = new Class({
|
||||
return this.loadFromDom(mapId, domDocument);
|
||||
},
|
||||
|
||||
discard: function(mapId) {
|
||||
discardChanges: function(mapId) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
|
@@ -18,39 +18,61 @@
|
||||
|
||||
mindplot.RESTPersistenceManager = new Class({
|
||||
Extends:mindplot.PersistenceManager,
|
||||
initialize: function(saveUrl) {
|
||||
initialize:function (saveUrl, revertUrl) {
|
||||
this.parent();
|
||||
$assert(saveUrl, "saveUrl can not be null");
|
||||
$assert(revertUrl, "revertUrl can not be null");
|
||||
this.saveUrl = saveUrl;
|
||||
this.revertUrl = revertUrl;
|
||||
},
|
||||
|
||||
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
|
||||
saveMapXml:function (mapId, mapXml, pref, saveHistory, events) {
|
||||
|
||||
var data = {
|
||||
id:mapId,
|
||||
xml: mapXml,
|
||||
properties: pref
|
||||
xml:mapXml,
|
||||
properties:pref
|
||||
};
|
||||
|
||||
var request = new Request({
|
||||
url:this.saveUrl.replace("{id}", mapId) + "?minor=" + !saveHistory,
|
||||
method: 'put',
|
||||
onSuccess:function(responseText, responseXML) {
|
||||
method:'put',
|
||||
onSuccess:function (responseText, responseXML) {
|
||||
events.onSuccess();
|
||||
|
||||
},
|
||||
onException:function(headerName, value) {
|
||||
onException:function (headerName, value) {
|
||||
events.onError();
|
||||
},
|
||||
onFailure:function(xhr) {
|
||||
onFailure:function (xhr) {
|
||||
events.onError();
|
||||
},
|
||||
headers: {"Content-Type":"application/json","Accept":"application/json"},
|
||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||
emulation:false,
|
||||
urlEncoded:false
|
||||
});
|
||||
request.put(JSON.encode(data));
|
||||
},
|
||||
|
||||
discardChanges:function (mapId) {
|
||||
var request = new Request({
|
||||
url:this.revertUrl.replace("{id}", mapId),
|
||||
async:false,
|
||||
method:'post',
|
||||
onSuccess:function () {
|
||||
console.log("Revert success ....");
|
||||
},
|
||||
onException:function () {
|
||||
},
|
||||
onFailure:function () {
|
||||
},
|
||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||
emulation:false,
|
||||
urlEncoded:false
|
||||
});
|
||||
request.post();
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -34,10 +34,10 @@ mindplot.widget.IMenu = new Class({
|
||||
});
|
||||
},
|
||||
|
||||
discard:function () {
|
||||
discardChanges:function () {
|
||||
var persistenceManager = mindplot.PersistenceManager.getInstance();
|
||||
var mindmap = designer.getMindmap();
|
||||
persistenceManager.discard(mindmap.getId());
|
||||
persistenceManager.discardChanges(mindmap.getId());
|
||||
},
|
||||
|
||||
save:function (saveElem, designer, saveHistory) {
|
||||
|
@@ -321,7 +321,13 @@ mindplot.widget.Menu = new Class({
|
||||
var discardElem = $('discard');
|
||||
if (discardElem) {
|
||||
this._addButton('discard', false, false, function () {
|
||||
this.discard();
|
||||
// Avoid autosave before leaving the page ....
|
||||
$(window).removeEvents(['beforeunload']);
|
||||
|
||||
// Discard changes ...
|
||||
this.discardChanges();
|
||||
|
||||
// Reload the page ...
|
||||
window.location.reload();
|
||||
}.bind(this));
|
||||
this._registerTooltip('discard', $msg('DISCARD_CHANGES'));
|
||||
|
Reference in New Issue
Block a user