reimplementing persistence managers

This commit is contained in:
Ezequiel Bergamaschi 2014-03-16 16:56:44 -03:00
parent da9f861333
commit 42d22ffcb4
2 changed files with 6 additions and 12 deletions

View File

@ -35,25 +35,21 @@ mindplot.LocalStorageManager = new Class({
loadMapDom:function (mapId) { loadMapDom:function (mapId) {
var xml = localStorage.getItem(mapId + "-xml"); var xml = localStorage.getItem(mapId + "-xml");
if (xml == null || this.forceLoad) { if (xml == null || this.forceLoad) {
var xmlRequest = new Request({ $.ajax({
url:this.documentUrl.replace("{id}", mapId), url:this.documentUrl.replace("{id}", mapId),
headers:{"Content-Type":"text/plain","Accept":"application/xml"}, headers:{"Content-Type":"text/plain","Accept":"application/xml"},
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) {
throw new Error("Map could not be loaded"); throw new Error("Map could not be loaded");
} }
} }
return xml;
var parser = new DOMParser();
return parser.parseFromString(xml, "text/xml");
}, },
unlockMap:function (mindmap) { unlockMap:function (mindmap) {

View File

@ -165,24 +165,22 @@ mindplot.RESTPersistenceManager = new Class({
loadMapDom:function (mapId) { loadMapDom:function (mapId) {
// Let's try to open one from the local directory ... // Let's try to open one from the local directory ...
var xml; var xml;
var xmlRequest = new Request({ $.ajax({
url:this.documentUrl.replace("{id}", mapId) + "/xml", url:this.documentUrl.replace("{id}", mapId) + "/xml",
method:'get', method:'get',
async:false, async:false,
headers:{"Content-Type":"text/plain","Accept":"application/xml"}, headers:{"Content-Type":"text/plain","Accept":"application/xml"},
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) {
throw new Error("Map could not be loaded"); throw new Error("Map could not be loaded");
} }
var parser = new DOMParser(); return xml;
return parser.parseFromString(xml, "text/xml");
} }
} }
); );