- 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:
Paulo Veiga 2011-11-29 00:38:11 -03:00
parent c598c1837e
commit 81f9ffa5e9
5 changed files with 192 additions and 183 deletions

View File

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

View File

@ -61,6 +61,10 @@ mindplot.PersitenceManager = new Class({
var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(mapDom);
return serializer.loadFromDom(mapDom, mapId);
},
logEntry: function(severity, message) {
throw "Method must be implemented";
}
});

View File

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

View File

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

View File

@ -29,25 +29,6 @@ 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()