mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-08-20 12:30:44 +02:00
- Fix auto save.
- Fix error trying to remove a node that contains a icons - Fix auto-save leaving the page.
This commit is contained in:
parent
c598c1837e
commit
81f9ffa5e9
@ -60,13 +60,6 @@ mindplot.Designer = new Class({
|
||||
|
||||
// Register keyboard events ...
|
||||
mindplot.DesignerKeyboard.register(this);
|
||||
|
||||
// To prevent the user from leaving the page with changes ...
|
||||
$(window).addEvent('beforeunload', function () {
|
||||
if (this.needsSave()) {
|
||||
this.save(null, false);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
_registerMouseEvents : function() {
|
||||
|
@ -1,74 +1,78 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "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
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
mindplot.PersitenceManager = new Class({
|
||||
initialize: function() {
|
||||
|
||||
},
|
||||
|
||||
save: function(mindmap, editorProperties, saveHistory, events) {
|
||||
$assert(mindmap, "mindmap can not be null");
|
||||
$assert(editorProperties, "editorProperties can not be null");
|
||||
|
||||
var mapId = mindmap.getId();
|
||||
$assert(mapId, "mapId can not be null");
|
||||
|
||||
var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromMindmap(mindmap);
|
||||
var domMap = serializer.toXML(mindmap);
|
||||
var mapXml = core.Utils.innerXML(domMap);
|
||||
|
||||
var pref = JSON.encode(editorProperties);
|
||||
try {
|
||||
this.saveMapXml(mapId, mapXml, pref, saveHistory, events);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
events.onError();
|
||||
}
|
||||
},
|
||||
|
||||
load: function(mapId) {
|
||||
$assert(mapId, "mapId can not be null");
|
||||
var domDocument = this.loadMapDom(mapId);
|
||||
return this.loadFromDom(mapId, domDocument);
|
||||
},
|
||||
|
||||
loadMapDom: function(mapId) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
loadFromDom : function(mapId, mapDom) {
|
||||
$assert(mapId, "mapId can not be null");
|
||||
$assert(mapDom, "mapDom can not be null");
|
||||
|
||||
var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(mapDom);
|
||||
return serializer.loadFromDom(mapDom, mapId);
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.PersitenceManager.init = function(instance) {
|
||||
mindplot.PersitenceManager._instance = instance;
|
||||
};
|
||||
|
||||
mindplot.PersitenceManager.getInstance = function() {
|
||||
return mindplot.PersitenceManager._instance;
|
||||
};
|
||||
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "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
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
mindplot.PersitenceManager = new Class({
|
||||
initialize: function() {
|
||||
|
||||
},
|
||||
|
||||
save: function(mindmap, editorProperties, saveHistory, events) {
|
||||
$assert(mindmap, "mindmap can not be null");
|
||||
$assert(editorProperties, "editorProperties can not be null");
|
||||
|
||||
var mapId = mindmap.getId();
|
||||
$assert(mapId, "mapId can not be null");
|
||||
|
||||
var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromMindmap(mindmap);
|
||||
var domMap = serializer.toXML(mindmap);
|
||||
var mapXml = core.Utils.innerXML(domMap);
|
||||
|
||||
var pref = JSON.encode(editorProperties);
|
||||
try {
|
||||
this.saveMapXml(mapId, mapXml, pref, saveHistory, events);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
events.onError();
|
||||
}
|
||||
},
|
||||
|
||||
load: function(mapId) {
|
||||
$assert(mapId, "mapId can not be null");
|
||||
var domDocument = this.loadMapDom(mapId);
|
||||
return this.loadFromDom(mapId, domDocument);
|
||||
},
|
||||
|
||||
loadMapDom: function(mapId) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
saveMapXml : function(mapId, mapXml, pref, saveHistory, events) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
loadFromDom : function(mapId, mapDom) {
|
||||
$assert(mapId, "mapId can not be null");
|
||||
$assert(mapDom, "mapDom can not be null");
|
||||
|
||||
var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(mapDom);
|
||||
return serializer.loadFromDom(mapDom, mapId);
|
||||
},
|
||||
|
||||
logEntry: function(severity, message) {
|
||||
throw "Method must be implemented";
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.PersitenceManager.init = function(instance) {
|
||||
mindplot.PersitenceManager._instance = instance;
|
||||
};
|
||||
|
||||
mindplot.PersitenceManager.getInstance = function() {
|
||||
return mindplot.PersitenceManager._instance;
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
mindplot.commands.DeleteCommand = new Class({
|
||||
Extends:mindplot.Command,
|
||||
initialize: function(topicIds,relIds) {
|
||||
initialize: function(topicIds, relIds) {
|
||||
this._relIds = relIds;
|
||||
this._topicIds = topicIds;
|
||||
this._deletedTopicModels = [];
|
||||
@ -32,9 +32,9 @@ mindplot.commands.DeleteCommand = new Class({
|
||||
if (topics.length > 0) {
|
||||
topics.forEach(
|
||||
function(topic, index) {
|
||||
var model = topic.getModel().clone();
|
||||
var model = topic.getModel();
|
||||
|
||||
//delete relationships
|
||||
// Delete relationships
|
||||
var relationships = topic.getRelationships();
|
||||
while (relationships.length > 0) {
|
||||
var relationship = relationships[0];
|
||||
@ -68,6 +68,7 @@ mindplot.commands.DeleteCommand = new Class({
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
undoExecute: function(commandContext) {
|
||||
|
||||
var topics = commandContext.findTopics(this._topicIds);
|
||||
|
@ -245,27 +245,24 @@ mindplot.widget.Menu = new Class({
|
||||
var saveElem = $('save');
|
||||
if (saveElem) {
|
||||
this.addButton('save', false, false, function() {
|
||||
|
||||
$notify("Saving ...");
|
||||
saveElem.setStyle('cursor', 'wait');
|
||||
|
||||
// Load map content ...
|
||||
var mindmap = designer.getMindmap();
|
||||
var mindmapProp = designer.getMindmapProperties();
|
||||
|
||||
var persistenceManager = mindplot.PersitenceManager.getInstance();
|
||||
persistenceManager.save(mindmap, mindmapProp, true, {
|
||||
onSuccess: function() {
|
||||
saveElem.setStyle('cursor', 'pointer');
|
||||
$notify("Save complete");
|
||||
|
||||
},
|
||||
onError: function() {
|
||||
saveElem.setStyle('cursor', 'pointer');
|
||||
$notify("Save could not be completed. Try latter");
|
||||
}
|
||||
});
|
||||
this._save(saveElem, designer, true);
|
||||
});
|
||||
|
||||
if (!readOnly) {
|
||||
// To prevent the user from leaving the page with changes ...
|
||||
$(window).addEvent('beforeunload', function () {
|
||||
if (designer.needsSave()) {
|
||||
this._save(saveElem, designer, false);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
// Autosave on a fixed period of time ...
|
||||
(function() {
|
||||
if (designer.needsSave()) {
|
||||
this._save(saveElem, designer, false);
|
||||
}
|
||||
}.bind(this)).periodical(30000);
|
||||
}
|
||||
}
|
||||
|
||||
var discardElem = $('discard');
|
||||
@ -436,5 +433,38 @@ mindplot.widget.Menu = new Class({
|
||||
this._toolbarElems.forEach(function(item) {
|
||||
item.hide();
|
||||
});
|
||||
},
|
||||
|
||||
_save:function (saveElem, designer, saveHistory) {
|
||||
|
||||
// Load map content ...
|
||||
var mindmap = designer.getMindmap();
|
||||
var mindmapProp = designer.getMindmapProperties();
|
||||
|
||||
// Display save message ..
|
||||
if (saveHistory) {
|
||||
$notify("Saving ...");
|
||||
saveElem.setStyle('cursor', 'wait');
|
||||
} else {
|
||||
console.log("Saving without history ...");
|
||||
}
|
||||
|
||||
// Call persistence manager for saving ...
|
||||
var persistenceManager = mindplot.PersitenceManager.getInstance();
|
||||
persistenceManager.save(mindmap, mindmapProp, saveHistory, {
|
||||
onSuccess: function() {
|
||||
if (saveHistory) {
|
||||
saveElem.setStyle('cursor', 'pointer');
|
||||
$notify("Save complete");
|
||||
}
|
||||
},
|
||||
onError: function() {
|
||||
if (saveHistory) {
|
||||
saveElem.setStyle('cursor', 'pointer');
|
||||
$notify("Save could not be completed. Try latter");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
@ -1,79 +1,60 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "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
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
Asset.javascript('../js/mindplot-min.js', {
|
||||
id: 'MindplotSVGLib',
|
||||
onLoad: function() {
|
||||
$(document).fireEvent('loadcomplete', 'mind')
|
||||
}
|
||||
});
|
||||
|
||||
var designer = null;
|
||||
/* JavaScript tabs changer */
|
||||
|
||||
function setUpToolbar(designer, readOnly) {
|
||||
|
||||
var menu = new mindplot.widget.Menu(designer, 'toolbar', mapId);
|
||||
|
||||
// Autosave ...
|
||||
if (!readOnly) {
|
||||
(function() {
|
||||
|
||||
if (designer.needsSave()) {
|
||||
designer.save(function() {
|
||||
var monitor = core.ToolbarNotifier.getInstance();
|
||||
}, false);
|
||||
}
|
||||
}).periodical(30000);
|
||||
|
||||
// To prevent the user from leaving the page with changes ...
|
||||
window.onbeforeunload = function() {
|
||||
if (designer.needsSave()) {
|
||||
designer.save(null, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If a node has focus, focus can be move to another node using the keys.
|
||||
designer._cleanScreen = function() {
|
||||
menu.clear()
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
function buildDesigner(properties) {
|
||||
$assert(properties, "properties can not be null");
|
||||
|
||||
var container = $('mindplot');
|
||||
container.setStyles({
|
||||
height: parseInt(screen.height),
|
||||
width: parseInt(screen.width)
|
||||
});
|
||||
|
||||
designer = new mindplot.Designer(properties, container);
|
||||
designer.setViewPort({
|
||||
height: parseInt(window.innerHeight - 151), // Footer and Header
|
||||
width: parseInt(window.innerWidth)
|
||||
});
|
||||
|
||||
// Toolbar is only loaded if it was defined ...
|
||||
if ($('toolbar')) {
|
||||
setUpToolbar(designer, properties.readOnly);
|
||||
}
|
||||
return designer;
|
||||
}
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "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
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
Asset.javascript('../js/mindplot-min.js', {
|
||||
id: 'MindplotSVGLib',
|
||||
onLoad: function() {
|
||||
$(document).fireEvent('loadcomplete', 'mind')
|
||||
}
|
||||
});
|
||||
|
||||
var designer = null;
|
||||
/* JavaScript tabs changer */
|
||||
|
||||
function setUpToolbar(designer, readOnly) {
|
||||
|
||||
var menu = new mindplot.widget.Menu(designer, 'toolbar', mapId);
|
||||
|
||||
// If a node has focus, focus can be move to another node using the keys.
|
||||
designer._cleanScreen = function() {
|
||||
menu.clear()
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
function buildDesigner(properties) {
|
||||
$assert(properties, "properties can not be null");
|
||||
|
||||
var container = $('mindplot');
|
||||
container.setStyles({
|
||||
height: parseInt(screen.height),
|
||||
width: parseInt(screen.width)
|
||||
});
|
||||
|
||||
designer = new mindplot.Designer(properties, container);
|
||||
designer.setViewPort({
|
||||
height: parseInt(window.innerHeight - 151), // Footer and Header
|
||||
width: parseInt(window.innerWidth)
|
||||
});
|
||||
|
||||
// Toolbar is only loaded if it was defined ...
|
||||
if ($('toolbar')) {
|
||||
setUpToolbar(designer, properties.readOnly);
|
||||
}
|
||||
return designer;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user