Add support for revert changes ...

This commit is contained in:
Paulo Gustavo Veiga
2012-07-04 02:15:55 -03:00
parent b321e205b1
commit 5cf9756ed3
10 changed files with 76 additions and 20 deletions

View File

@@ -27,7 +27,7 @@ mindplot.LocalStorageManager = new Class({
events.onSuccess();
},
discard : function(mapId) {
discardChanges : function(mapId) {
localStorage.removeItem(mapId + "-xml");
},

View File

@@ -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);
}
}
});

View File

@@ -47,7 +47,7 @@ mindplot.PersistenceManager = new Class({
return this.loadFromDom(mapId, domDocument);
},
discard: function(mapId) {
discardChanges: function(mapId) {
throw "Method must be implemented";
},

View File

@@ -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();
}
}
);

View File

@@ -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) {

View File

@@ -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'));