Save action working again :).

This commit is contained in:
Paulo Veiga 2011-10-02 14:47:54 -03:00
parent a994099397
commit f3af50740c
11 changed files with 152 additions and 261 deletions

View File

@ -27,7 +27,7 @@ mindplot.Beta2PelaMigrator = new Class({
loadFromDom : function(dom, mapId) {
$assert($defined(mapId), "mapId can not be null");
var mindmap = this._betaSerializer.loadFromDom(dom);
var mindmap = this._betaSerializer.loadFromDom(dom, mapId);
mindmap.setVersion(mindplot.ModelCodeName.PELA);
return mindmap;
}

View File

@ -50,6 +50,7 @@ mindplot.DesignerActionRunner = new Class({
markAsChangeBase: function() {
return this._undoManager.markAsChangeBase();
},
hasBeenChanged: function() {
return this._undoManager.hasBeenChanged();
}

View File

@ -61,9 +61,9 @@ mindplot.MindmapDesigner = new Class({
// To prevent the user from leaving the page with changes ...
$(window).addEvent('beforeunload', function () {
// if (this.needsSave()) {
// this.save(null, false)
// }
if (this.needsSave()) {
this.save(null, false);
}
}.bind(this));
},
@ -360,19 +360,24 @@ mindplot.MindmapDesigner = new Class({
},
needsSave : function() {
return this._actionRunner.hasBeenChanged();
//@Todo: Review all this ...
// return this._actionDispatcher.hasBeenChanged();
return true;
},
save : function(onSavedHandler, saveHistory) {
var persistantManager = mindplot.PersistanceManager;
var mindmap = this._mindmap;
var mindmap = this.getMindmap();
var properties = {zoom:this.getModel().getZoom(), layoutManager:this._layoutManager.getClassName()};
var persistantManager = mindplot.PersistanceManager;
persistantManager.save(mindmap, properties, onSavedHandler, saveHistory);
this.fireEvent("save", {type:saveHistory});
// Refresh undo state...
this._actionRunner.markAsChangeBase();
//@Todo: Review all this. It should not be here ...
// this._actionDispatcher.markAsChangeBase();
},

View File

@ -18,31 +18,29 @@
mindplot.PersistanceManager = {};
mindplot.PersistanceManager.save = function(mindmap, editorProperties, onSavedHandler,saveHistory)
{
mindplot.PersistanceManager.save = function(mindmap, editorProperties, onSavedHandler, saveHistory) {
$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 xmlMap = serializer.toXML(mindmap);
var xmlMapStr = core.Utils.innerXML(xmlMap);
var pref = JSON.toString(editorProperties);
var pref = JSON.encode(editorProperties);
window.MapEditorService.saveMap(mapId, xmlMapStr, pref, saveHistory,
{
callback:function(response) {
if (response.msgCode != "OK")
{
if (response.msgCode != "OK") {
monitor.logError("Save could not be completed. Please,try again in a couple of minutes.");
// wLogger.error(response.msgDetails);
} else
{
} else {
// Execute on success handler ...
if ($defined(onSavedHandler))
{
if ($defined(onSavedHandler)) {
onSavedHandler();
}
}
@ -58,16 +56,14 @@ mindplot.PersistanceManager.save = function(mindmap, editorProperties, onSavedHa
};
mindplot.PersistanceManager.load = function(mapId)
{
mindplot.PersistanceManager.load = function(mapId) {
$assert(mapId, "mapId can not be null");
var result = {r:null};
window.MapEditorService.loadMap(mapId, {
callback:function(response) {
if (response.msgCode == "OK")
{
if (response.msgCode == "OK") {
// Explorer Hack with local files ...
var xmlContent = response.content;
var domDocument = core.Utils.createDocumentFromText(xmlContent);
@ -76,8 +72,7 @@ mindplot.PersistanceManager.load = function(mapId)
mindmap.setId(mapId);
result.r = mindmap;
} else
{
} else {
// Handle error message ...
var msg = response.msgDetails;
var monitor = core.Monitor.getInstance();

View File

@ -157,8 +157,10 @@ mindplot.XMLMindmapSerializer_Beta = new Class({
return noteDom;
},
loadFromDom : function(dom) {
loadFromDom : function(dom, mapId) {
$assert(dom, "Dom can not be null");
$assert(mapId, "mapId can not be null");
var rootElem = dom.documentElement;
// Is a wisemap?.
@ -175,6 +177,7 @@ mindplot.XMLMindmapSerializer_Beta = new Class({
mindmap.addBranch(topic);
}
}
mindmap.setId(mapId);
return mindmap;
},

View File

@ -198,8 +198,10 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
return relationDom;
},
loadFromDom : function(dom) {
$assert(dom, "Dom can not be null");
loadFromDom : function(dom, mapId) {
$assert(dom, "dom can not be null");
$assert(mapId, "mapId can not be null");
var rootElem = dom.documentElement;
// Is a wisemap?.
@ -230,6 +232,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
}
}
this._idsMap = null;
mindmap.setId(mapId);
return mindmap;
},

View File

@ -17,7 +17,7 @@
*/
mindplot.widget.Menu = new Class({
initialize : function(designer, containerId) {
initialize : function(designer, containerId, readOnly) {
$assert(designer, "designer can not be null");
$assert(containerId, "containerId can not be null");
// @Todo: Remove hardcode ...
@ -256,6 +256,89 @@ mindplot.widget.Menu = new Class({
}
});
var saveElem = $('saveButton');
if (saveElem) {
saveElem.addEvent('click', function() {
if (!readOnly) {
$('saveButton').setStyle('cursor', 'wait');
(function() {
designer.save(function() {
// var monitor = core.Monitor.getInstance();
// monitor.logMessage('Save completed successfully');
saveElem.setStyle('cursor', 'pointer');
}, true);
}).delay(1);
} else {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.<br/> to create an account click <a href="userRegistration.htm">here</a>',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
}
});
}
var discartElem = $('discartElem');
if (discartElem) {
discartElem.addEvent('click', function() {
if (!readOnly) {
displayLoading();
window.document.location = "mymaps.htm";
} else {
displayLoading();
window.document.location = "home.htm";
}
});
}
if (readOnly) {
$('tagIt').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
$('shareIt').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
$('publishIt').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
$('history').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
}
},
clear : function() {

View File

@ -399,7 +399,7 @@
</output>
<includes>
<include>help.js</include>
<include>helpPanel.js</include>
<include>Panel.js</include>
</includes>
</aggregation>
</aggregations>

View File

@ -183,86 +183,6 @@ function setUpToolbar(designer, isTryMode) {
});
}
// Save event handler ....
var saveButton = $('saveButton');
saveButton.addEvent('click', function(event) {
if (!isTryMode) {
// @todo: This must be fixed ...
// saveButton.setStyle('cursor', 'wait');
// var saveFunc = function() {
// designer.save(function() {
// var monitor = core.Monitor.getInstance();
// monitor.logMessage('Save completed successfully');
// saveButton.setStyle('cursor', 'pointer');
// }, true);
// };
// saveFunc.delay(1);
} else {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.<br/> to create an account click <a href="userRegistration.htm">here</a>',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
}
});
var discardButton = $('discardButton');
discardButton.addEvent('click', function(event) {
if (!isTryMode) {
displayLoading();
window.document.location = "mymaps.htm";
} else {
displayLoading();
window.document.location = "home.htm";
}
});
if (isTryMode) {
$('tagIt').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
$('shareIt').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
$('publishIt').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
$('history').addEvent('click', function(event) {
new Windoo.Confirm('This option is not enabled in try mode. You must by signed in order to execute this action.',
{
'window': {theme:Windoo.Themes.wise,
title:''
}
});
});
}
// Autosave ...
if (!isTryMode) {
(function() {

View File

@ -1,119 +0,0 @@
/*
* 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.
*/
/* transcorners : Yaroslaff Fedin (inviz.ru). updates : [url=http://forum.mootools.net/topic.php?id=1202]http://forum.mootools.net/topic.php?id=1202[/url] */
var Transcorner = new Class({
setOptions: function(options) {
this.options = Object.extend({
radius: 10,
borderColor: null,
backgroundColor: this.el.getStyle('background-color'),
transition: this.fx,
onComplete: Class.empty
}, options || {});
}
,initialize: function(el, sides, options) {
this.el = $(el);
if (!sides || $type(sides) == 'object') {
options = sides || false;
sides = 'top, bottom';
}
;
this.setOptions(options);
sides.split(',').each(function(side) {
side = side.clean().test(' ') ? side.clean().split(' ') : [side.trim()];
this.assemble(side[0], side[1]);
}, this);
}
,fx: function(pos) {
return -(Math.sqrt(1 - Math.pow(pos, 2)) - 1);
}
,assemble: function(vertical, horizontal) {
var corner;
var el = this.el;
while ((el = el.getParent()) && el.getTag() != 'html' && [false, 'transparent'].test(corner = el.getStyle('background-color'))) {
}
;
var s = function(property, dontParse) {
return !dontParse ? (parseInt(this.el.getStyle(property)) || 0) : this.el.getStyle(property);
}.bind(this);
var sides = {
left:'right',
right:'left'
};
var styles = {
display: 'block',
backgroundColor: corner,
zIndex: 1,
position: 'relative',
zoom: 1
};
for (side in sides) {
styles['margin-' + side] = "-" + (s('padding-' + side) + s('border-' + side + '-width')) + "px";
}
for (side in {top:1, bottom:1}) {
styles['margin-' + side] = vertical == side ? "0" : (s('padding-' + vertical) - this.options.radius) + "px";
}
var handler = new Element("b").setStyles(styles).addClass('corner-container');
this.options.borderColor = this.options.borderColor || (s('border-' + vertical + '-width') > 0 ? s('border-' + vertical + '-color', 1) : this.options.backgroundColor);
this.el.setStyle('border-' + vertical, '0').setStyle('padding-' + vertical, '0');
var stripes = [];
var borders = {};
var exMargin = 0;
for (side in sides) {
borders[side] = s('border-' + side + '-width', 1) + " " + s('border-' + side + '-style', 1) + " " + s('border-' + side + '-color', 1);
}
for (var i = 1; i < this.options.radius; i++) {
margin = Math.round(this.options.transition((this.options.radius - i) / this.options.radius) * this.options.radius);
var styles = {
background: i == 1 ? this.options.borderColor : this.options.backgroundColor,
display: 'block',
height: '1px',
overflow: 'hidden',
zoom: 1
};
for (side in sides) {
var check = horizontal == sides[side];
styles['border-' + side] = check ? borders[side] : (((exMargin || margin) - margin) || 1) + 'px solid ' + this.options.borderColor;
styles['margin-' + side] = check ? 0 : margin + 'px';
}
;
exMargin = margin;
stripes.push(new Element("b").setStyles(styles).addClass('corner'));
}
;
if (vertical == 'top') {
this.el.insertBefore(handler, this.el.firstChild);
}
else {
handler.injectInside(this.el);
stripes = stripes.reverse();
}
;
stripes.each(function(stripe) {
stripe.injectInside(handler);
});
this.options.onComplete();
}
});
Element.extend({
makeRounded: function(side, options) {
return new Transcorner(this, side, options);
}
});