- Finish exclusive locking support.
This commit is contained in:
committed by
Paulo Gustavo Veiga
parent
e5e2e86fce
commit
a179875fee
@@ -18,28 +18,28 @@
|
||||
|
||||
mindplot.LocalStorageManager = new Class({
|
||||
Extends:mindplot.PersistenceManager,
|
||||
initialize: function() {
|
||||
initialize:function () {
|
||||
this.parent();
|
||||
},
|
||||
|
||||
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
|
||||
saveMapXml:function (mapId, mapXml, pref, saveHistory, events) {
|
||||
localStorage.setItem(mapId + "-xml", mapXml);
|
||||
events.onSuccess();
|
||||
},
|
||||
|
||||
discardChanges : function(mapId) {
|
||||
discardChanges:function (mapId) {
|
||||
localStorage.removeItem(mapId + "-xml");
|
||||
},
|
||||
|
||||
loadMapDom : function(mapId) {
|
||||
loadMapDom:function (mapId) {
|
||||
var xml = localStorage.getItem(mapId + "-xml");
|
||||
if (xml == null) {
|
||||
// Let's try to open one from the local directory ...
|
||||
var xmlRequest = new Request({
|
||||
url: 'samples/' + mapId + '.xml',
|
||||
method: 'get',
|
||||
async: false,
|
||||
onSuccess: function(responseText) {
|
||||
url:'samples/' + mapId + '.xml',
|
||||
method:'get',
|
||||
async:false,
|
||||
onSuccess:function (responseText) {
|
||||
xml = responseText;
|
||||
}
|
||||
});
|
||||
@@ -54,6 +54,10 @@ mindplot.LocalStorageManager = new Class({
|
||||
|
||||
var parser = new DOMParser();
|
||||
return parser.parseFromString(xml, "text/xml");
|
||||
},
|
||||
|
||||
unlockMap:function (mindmap) {
|
||||
// Ignore, no implementation required ...
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@@ -31,7 +31,7 @@ mindplot.PersistenceManager = new Class({
|
||||
|
||||
},
|
||||
|
||||
save:function (mindmap, editorProperties, saveHistory, events) {
|
||||
save:function (mindmap, editorProperties, saveHistory, events, sync) {
|
||||
$assert(mindmap, "mindmap can not be null");
|
||||
$assert(editorProperties, "editorProperties can not be null");
|
||||
|
||||
@@ -44,7 +44,7 @@ mindplot.PersistenceManager = new Class({
|
||||
|
||||
var pref = JSON.encode(editorProperties);
|
||||
try {
|
||||
this.saveMapXml(mapId, mapXml, pref, saveHistory, events);
|
||||
this.saveMapXml(mapId, mapXml, pref, saveHistory, events,sync);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
events.onError();
|
||||
@@ -58,15 +58,19 @@ mindplot.PersistenceManager = new Class({
|
||||
},
|
||||
|
||||
discardChanges:function (mapId) {
|
||||
throw "Method must be implemented";
|
||||
throw new Error("Method must be implemented");
|
||||
},
|
||||
|
||||
loadMapDom:function (mapId) {
|
||||
throw "Method must be implemented";
|
||||
throw new Error("Method must be implemented");
|
||||
},
|
||||
|
||||
saveMapXml:function (mapId, mapXml, pref, saveHistory, events) {
|
||||
throw "Method must be implemented";
|
||||
saveMapXml:function (mapId, mapXml, pref, saveHistory, events,sync) {
|
||||
throw new Error("Method must be implemented");
|
||||
},
|
||||
|
||||
unlockMap:function (mindmap) {
|
||||
throw new Error("Method must be implemented");
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -18,15 +18,17 @@
|
||||
|
||||
mindplot.RESTPersistenceManager = new Class({
|
||||
Extends:mindplot.PersistenceManager,
|
||||
initialize:function (saveUrl, revertUrl) {
|
||||
initialize:function (saveUrl, revertUrl, lockUrl) {
|
||||
this.parent();
|
||||
$assert(saveUrl, "saveUrl can not be null");
|
||||
$assert(revertUrl, "revertUrl can not be null");
|
||||
this.saveUrl = saveUrl;
|
||||
this.revertUrl = revertUrl;
|
||||
this.lockUrl = lockUrl;
|
||||
this.timestamp = null;
|
||||
},
|
||||
|
||||
saveMapXml:function (mapId, mapXml, pref, saveHistory, events) {
|
||||
saveMapXml:function (mapId, mapXml, pref, saveHistory, events, sync) {
|
||||
|
||||
var data = {
|
||||
id:mapId,
|
||||
@@ -34,12 +36,17 @@ mindplot.RESTPersistenceManager = new Class({
|
||||
properties:pref
|
||||
};
|
||||
|
||||
var persistence = this;
|
||||
var query = "minor=" + !saveHistory;
|
||||
query = query + (this.timestamp ? "×tamp=" + this.timestamp : "");
|
||||
|
||||
var request = new Request({
|
||||
url:this.saveUrl.replace("{id}", mapId) + "?minor=" + !saveHistory,
|
||||
url:this.saveUrl.replace("{id}", mapId) + "?" + query,
|
||||
method:'put',
|
||||
async:!sync,
|
||||
onSuccess:function (responseText, responseXML) {
|
||||
events.onSuccess();
|
||||
|
||||
persistence.timestamp = responseText;
|
||||
},
|
||||
onException:function (headerName, value) {
|
||||
events.onError();
|
||||
@@ -81,8 +88,27 @@ mindplot.RESTPersistenceManager = new Class({
|
||||
urlEncoded:false
|
||||
});
|
||||
request.post();
|
||||
}
|
||||
},
|
||||
|
||||
unlockMap:function (mindmap) {
|
||||
var mapId = mindmap.getId();
|
||||
var request = new Request({
|
||||
url:this.lockUrl.replace("{id}", mapId),
|
||||
async:false,
|
||||
method:'put',
|
||||
onSuccess:function () {
|
||||
|
||||
},
|
||||
onException:function () {
|
||||
},
|
||||
onFailure:function () {
|
||||
},
|
||||
headers:{"Content-Type":"text/plain"},
|
||||
emulation:false,
|
||||
urlEncoded:false
|
||||
});
|
||||
request.put("false");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -40,7 +40,7 @@ mindplot.widget.IMenu = new Class({
|
||||
});
|
||||
},
|
||||
|
||||
discardChanges:function () {
|
||||
discardChanges:function (designer) {
|
||||
// Avoid autosave before leaving the page ....
|
||||
this.setRequireChange(false);
|
||||
|
||||
@@ -49,12 +49,21 @@ mindplot.widget.IMenu = new Class({
|
||||
var mindmap = designer.getMindmap();
|
||||
persistenceManager.discardChanges(mindmap.getId());
|
||||
|
||||
// Unlock map ...
|
||||
this.unlockMap(designer);
|
||||
|
||||
// Reload the page ...
|
||||
window.location.reload();
|
||||
|
||||
},
|
||||
|
||||
save:function (saveElem, designer, saveHistory) {
|
||||
unlockMap:function (designer) {
|
||||
var mindmap = designer.getMindmap();
|
||||
var persistenceManager = mindplot.PersistenceManager.getInstance();
|
||||
persistenceManager.unlockMap(mindmap);
|
||||
},
|
||||
|
||||
save:function (saveElem, designer, saveHistory, sync) {
|
||||
// Load map content ...
|
||||
var mindmap = designer.getMindmap();
|
||||
var mindmapProp = designer.getMindmapProperties();
|
||||
@@ -88,7 +97,8 @@ mindplot.widget.IMenu = new Class({
|
||||
$notify(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, sync);
|
||||
|
||||
},
|
||||
|
||||
isSaveRequired:function () {
|
||||
|
@@ -325,10 +325,12 @@ mindplot.widget.Menu = new Class({
|
||||
|
||||
if (!readOnly) {
|
||||
// To prevent the user from leaving the page with changes ...
|
||||
$(window).addEvent('beforeunload', function () {
|
||||
Element.NativeEvents.unload = 2;
|
||||
$(window).addEvent('unload', function () {
|
||||
if (this.isSaveRequired()) {
|
||||
this.save(saveElem, designer, false);
|
||||
this.save(saveElem, designer, false, true);
|
||||
}
|
||||
this.unlockMap(designer);
|
||||
}.bind(this));
|
||||
|
||||
// Autosave on a fixed period of time ...
|
||||
@@ -343,29 +345,11 @@ mindplot.widget.Menu = new Class({
|
||||
var discardElem = $('discard');
|
||||
if (discardElem) {
|
||||
this._addButton('discard', false, false, function () {
|
||||
this.discardChanges();
|
||||
this.discardChanges(designer);
|
||||
}.bind(this));
|
||||
this._registerTooltip('discard', $msg('DISCARD_CHANGES'));
|
||||
}
|
||||
|
||||
var tagElem = $('tagIt');
|
||||
if (tagElem) {
|
||||
this._addButton('tagIt', false, false, function () {
|
||||
var reqDialog = new MooDialog.Request('c/tags?mapId=' + mapId, null,
|
||||
{'class':'modalDialog tagItModalDialog',
|
||||
closeButton:true,
|
||||
destroyOnClose:true,
|
||||
title:'Tags'
|
||||
});
|
||||
reqDialog.setRequestOptions({
|
||||
onRequest:function () {
|
||||
reqDialog.setContent($msg('LOADING'));
|
||||
}
|
||||
});
|
||||
});
|
||||
this._registerTooltip('tagIt', "Tag");
|
||||
}
|
||||
|
||||
var shareElem = $('shareIt');
|
||||
if (shareElem) {
|
||||
this._addButton('shareIt', false, false, function () {
|
||||
|
Reference in New Issue
Block a user