2009-06-12 01:43:45 +08:00
|
|
|
/*
|
2011-01-24 07:34:05 +08:00
|
|
|
* Copyright [2011] [wisemapping]
|
2009-06-12 01:43:45 +08:00
|
|
|
*
|
2011-01-24 08:03:12 +08:00
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
2011-01-24 07:34:05 +08:00
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
2009-06-12 01:43:45 +08:00
|
|
|
*
|
2011-01-24 07:34:05 +08:00
|
|
|
* http://www.wisemapping.org/license
|
2009-06-12 01:43:45 +08:00
|
|
|
*
|
2011-01-24 07:34:05 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-06-12 01:43:45 +08:00
|
|
|
*/
|
|
|
|
|
2010-12-13 22:07:20 +08:00
|
|
|
mindplot.PersistanceManager = {};
|
2009-06-08 02:59:43 +08:00
|
|
|
|
2010-12-13 22:07:20 +08:00
|
|
|
mindplot.PersistanceManager.save = function(mindmap, chartType, xmlChart, editorProperties, onSavedHandler,saveHistory)
|
2009-06-08 02:59:43 +08:00
|
|
|
{
|
|
|
|
core.assert(mindmap, "mindmap can not be null");
|
|
|
|
core.assert(chartType, "chartType can not be null");
|
|
|
|
core.assert(xmlChart, "xmlChart can not be null");
|
|
|
|
core.assert(editorProperties, "editorProperties can not be null");
|
|
|
|
|
|
|
|
var mapId = mindmap.getId();
|
|
|
|
|
2010-12-13 22:07:20 +08:00
|
|
|
var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromMindmap(mindmap);
|
|
|
|
var xmlMap = serializer.toXML(mindmap);
|
2009-06-08 02:59:43 +08:00
|
|
|
var xmlMapStr = core.Utils.innerXML(xmlMap);
|
|
|
|
|
|
|
|
var pref = Json.toString(editorProperties);
|
2010-12-13 22:07:20 +08:00
|
|
|
window.MapEditorService.saveMap(mapId, xmlMapStr, chartType, xmlChart, pref,saveHistory,
|
2009-06-08 02:59:43 +08:00
|
|
|
{
|
|
|
|
callback:function(response) {
|
|
|
|
|
|
|
|
if (response.msgCode != "OK")
|
|
|
|
{
|
|
|
|
monitor.logError("Save could not be completed. Please,try again in a couple of minutes.");
|
2009-06-12 01:43:45 +08:00
|
|
|
wLogger.error(response.msgDetails);
|
2009-06-08 02:59:43 +08:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
// Execute on success handler ...
|
|
|
|
if (onSavedHandler)
|
|
|
|
{
|
|
|
|
onSavedHandler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
errorHandler:function(message) {
|
|
|
|
var monitor = core.Monitor.getInstance();
|
|
|
|
monitor.logError("Save could not be completed. Please,try again in a couple of minutes.");
|
2009-06-12 01:43:45 +08:00
|
|
|
wLogger.error(message);
|
2009-06-08 02:59:43 +08:00
|
|
|
},
|
|
|
|
verb:"POST",
|
|
|
|
async: false
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-12-13 22:07:20 +08:00
|
|
|
mindplot.PersistanceManager.load = function(mapId)
|
2009-06-08 02:59:43 +08:00
|
|
|
{
|
|
|
|
core.assert(mapId, "mapId can not be null");
|
|
|
|
|
|
|
|
var result = {r:null};
|
2010-12-13 22:07:20 +08:00
|
|
|
window.MapEditorService.loadMap(mapId, {
|
2009-06-08 02:59:43 +08:00
|
|
|
callback:function(response) {
|
|
|
|
|
|
|
|
if (response.msgCode == "OK")
|
|
|
|
{
|
|
|
|
// Explorer Hack with local files ...
|
|
|
|
var xmlContent = response.content;
|
|
|
|
var domDocument = core.Utils.createDocumentFromText(xmlContent);
|
2010-12-13 22:07:20 +08:00
|
|
|
var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(domDocument);
|
2009-06-08 02:59:43 +08:00
|
|
|
var mindmap = serializer.loadFromDom(domDocument);
|
|
|
|
mindmap.setId(mapId);
|
|
|
|
|
|
|
|
result.r = mindmap;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// Handle error message ...
|
|
|
|
var msg = response.msgDetails;
|
|
|
|
var monitor = core.Monitor.getInstance();
|
|
|
|
monitor.logFatal("We're sorry, an error has occurred and we can't load your map. Please try again in a few minutes.");
|
2009-06-12 01:43:45 +08:00
|
|
|
wLogger.error(msg);
|
2009-06-08 02:59:43 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
verb:"GET",
|
|
|
|
async: false,
|
|
|
|
errorHandler:function(msg) {
|
|
|
|
var monitor = core.Monitor.getInstance();
|
|
|
|
monitor.logFatal("We're sorry, an error has occurred and we can't load your map. Please try again in a few minutes.");
|
2009-06-12 01:43:45 +08:00
|
|
|
wLogger.error(msg);
|
2009-06-08 02:59:43 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result.r;
|
|
|
|
};
|
|
|
|
|
|
|
|
|