- Fix notes issues. Now, notes are part of a CDATA seccion

This commit is contained in:
Paulo Veiga 2011-11-27 20:55:52 -03:00
parent 0ac513ea1e
commit 30de8b44ed
3 changed files with 307 additions and 291 deletions

View File

@ -1,287 +1,284 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.FixedDistanceBoard = new Class({ mindplot.FixedDistanceBoard = new Class({
Extends:mindplot.Board, Extends:mindplot.Board,
initialize:function(defaultHeight, topic, layoutManager) { initialize:function(defaultHeight, topic, layoutManager) {
this._topic = topic; this._topic = topic;
this._layoutManager = layoutManager; this._layoutManager = layoutManager;
var reference = topic.getPosition(); var reference = topic.getPosition();
this.parent(defaultHeight, reference); this.parent(defaultHeight, reference);
this._height = defaultHeight; this._height = defaultHeight;
this._entries = []; this._entries = [];
}, },
getHeight : function() { getHeight : function() {
return this._height; return this._height;
}, },
lookupEntryByOrder : function(order) { lookupEntryByOrder : function(order) {
var result = null; var result = null;
var entries = this._entries; var entries = this._entries;
if (order < entries.length) { if (order < entries.length) {
result = entries[order]; result = entries[order];
} }
if (result == null) { if (result == null) {
var defaultHeight = this._defaultWidth; var defaultHeight = this._defaultWidth;
var reference = this.getReferencePoint(); var reference = this.getReferencePoint();
if (entries.length == 0) { if (entries.length == 0) {
var yReference = reference.y; var yReference = reference.y;
result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0); result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0);
} else { } else {
var entriesLenght = entries.length; var entriesLenght = entries.length;
var lastEntry = entries[entriesLenght - 1]; var lastEntry = entries[entriesLenght - 1];
var lowerLimit = lastEntry.getUpperLimit(); var lowerLimit = lastEntry.getUpperLimit();
var upperLimit = lowerLimit + defaultHeight; var upperLimit = lowerLimit + defaultHeight;
result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght + 1); result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght + 1);
} }
} }
return result; return result;
}, },
createBoardEntry : function(lowerLimit, upperLimit, order) { createBoardEntry : function(lowerLimit, upperLimit, order) {
var result = new mindplot.BoardEntry(lowerLimit, upperLimit, order); var result = new mindplot.BoardEntry(lowerLimit, upperLimit, order);
var xPos = this.workoutXBorderDistance(); var xPos = this.workoutXBorderDistance();
result.setXPosition(xPos); result.setXPosition(xPos);
return result; return result;
}, },
updateReferencePoint : function() { updateReferencePoint : function() {
var entries = this._entries; var entries = this._entries;
var parentTopic = this.getTopic(); var parentTopic = this.getTopic();
var parentPosition = parentTopic.workoutIncomingConnectionPoint(parentTopic.getPosition()); var parentPosition = parentTopic.workoutIncomingConnectionPoint(parentTopic.getPosition());
var referencePoint = this.getReferencePoint(); var referencePoint = this.getReferencePoint();
var yOffset = parentPosition.y - referencePoint.y; var yOffset = parentPosition.y - referencePoint.y;
for (var i = 0; i < entries.length; i++) { for (var i = 0; i < entries.length; i++) {
var entry = entries[i]; var entry = entries[i];
if ($defined(entry)) { if ($defined(entry)) {
var upperLimit = entry.getUpperLimit() + yOffset; var upperLimit = entry.getUpperLimit() + yOffset;
var lowerLimit = entry.getLowerLimit() + yOffset; var lowerLimit = entry.getLowerLimit() + yOffset;
entry.setUpperLimit(upperLimit); entry.setUpperLimit(upperLimit);
entry.setLowerLimit(lowerLimit); entry.setLowerLimit(lowerLimit);
// Fix x position ... // Fix x position ...
var xPos = this.workoutXBorderDistance(); var xPos = this.workoutXBorderDistance();
entry.setXPosition(xPos); entry.setXPosition(xPos);
entry.update(); entry.update();
} }
} }
this._referencePoint = parentPosition.clone(); this._referencePoint = parentPosition.clone();
}, },
/** /**
* This x distance doesn't take into account the size of the shape. * This x distance doesn't take into account the size of the shape.
*/ */
workoutXBorderDistance : function() { workoutXBorderDistance : function() {
var topic = this.getTopic(); var topic = this.getTopic();
var topicPosition = topic.getPosition(); var topicPosition = topic.getPosition();
var topicSize = topic.getSize(); var topicSize = topic.getSize();
var halfTargetWidth = topicSize.width / 2; var halfTargetWidth = topicSize.width / 2;
var result; var result;
if (topicPosition.x >= 0) { if (topicPosition.x >= 0) {
// It's at right. // It's at right.
result = topicPosition.x + halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE; result = topicPosition.x + halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE;
} else { } else {
result = topicPosition.x - (halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE); result = topicPosition.x - (halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE);
} }
return result; return result;
}, },
getTopic : function() { getTopic : function() {
return this._topic; return this._topic;
}, },
freeEntry : function(entry) { freeEntry : function(entry) {
var newEntries = []; var newEntries = [];
var entries = this._entries; var entries = this._entries;
var order = 0; var order = 0;
for (var i = 0; i < entries.length; i++) { for (var i = 0; i < entries.length; i++) {
var e = entries[i]; var e = entries[i];
if (e == entry) { if (e == entry) {
order++; order++;
} }
newEntries[order] = e; newEntries[order] = e;
order++; order++;
} }
this._entries = newEntries; this._entries = newEntries;
}, },
repositionate : function() { repositionate : function() {
// Workout width and update topic height. // Workout width and update topic height.
var entries = this._entries; var entries = this._entries;
var height = 0; var height = 0;
var model = this._topic.getModel(); var model = this._topic.getModel();
if (entries.length >= 1 && !model.areChildrenShrinked()) { if (entries.length >= 1 && !model.areChildrenShrinked()) {
for (var i = 0; i < entries.length; i++) { for (var i = 0; i < entries.length; i++) {
var e = entries[i]; var e = entries[i];
if (e && e.getTopic()) { if (e && e.getTopic()) {
var topic = e.getTopic(); var topic = e.getTopic();
var topicBoard = this._layoutManager.getTopicBoardForTopic(topic); var topicBoard = this._layoutManager.getTopicBoardForTopic(topic);
var topicBoardHeight = topicBoard.getHeight(); var topicBoardHeight = topicBoard.getHeight();
height += topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; height += topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
} }
} }
} }
else { else {
var topic = this._topic; var topic = this._topic;
height = topic.getSize().height + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; height = topic.getSize().height + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
} }
var oldHeight = this._height; var oldHeight = this._height;
this._height = height; this._height = height;
// I must update all the parent nodes first... // I must update all the parent nodes first...
if (oldHeight != this._height) { if (oldHeight != this._height) {
var topic = this._topic; var topic = this._topic;
var parentTopic = topic.getParent(); var parentTopic = topic.getParent();
if (parentTopic != null) { if (parentTopic != null) {
var board = this._layoutManager.getTopicBoardForTopic(parentTopic); var board = this._layoutManager.getTopicBoardForTopic(parentTopic);
board.repositionate(); board.repositionate();
} }
} }
// @todo: Esto hace backtraking. Hay que cambiar la implementacion del set position de // Workout center the new topic center...
// forma tal que no se mande a hacer el update de todos los hijos. var refence = this.getReferencePoint();
var lowerLimit;
// Workout center the new topic center... if (entries.length > 0) {
var refence = this.getReferencePoint(); var l = 0;
var lowerLimit; for (l = 0; l < entries.length; l++) {
if (entries.length > 0) { if ($defined(entries[l]))
var l = 0; break;
for (l = 0; l < entries.length; l++) { }
if ($defined(entries[l])) var topic = entries[l].getTopic();
break; var firstNodeHeight = topic.getSize().height;
} lowerLimit = refence.y - (height / 2) - (firstNodeHeight / 2) + 1;
var topic = entries[l].getTopic(); }
var firstNodeHeight = topic.getSize().height;
lowerLimit = refence.y - (height / 2) - (firstNodeHeight / 2) + 1; var upperLimit = null;
}
// Start moving all the elements ...
var upperLimit = null; var newEntries = [];
var order = 0;
// Start moving all the elements ... for (var i = 0; i < entries.length; i++) {
var newEntries = []; var e = entries[i];
var order = 0; if (e && e.getTopic()) {
for (var i = 0; i < entries.length; i++) {
var e = entries[i]; var currentTopic = e.getTopic();
if (e && e.getTopic()) { e.setLowerLimit(lowerLimit);
var currentTopic = e.getTopic(); // Update entry ...
e.setLowerLimit(lowerLimit); var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic);
var topicBoardHeight = topicBoard.getHeight();
// Update entry ...
var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic); upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
var topicBoardHeight = topicBoard.getHeight(); e.setUpperLimit(upperLimit);
lowerLimit = upperLimit;
upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
e.setUpperLimit(upperLimit); e.setOrder(order);
lowerLimit = upperLimit; currentTopic.setOrder(order);
e.setOrder(order); e.update();
currentTopic.setOrder(order); newEntries[order] = e;
order++;
e.update(); }
newEntries[order] = e; }
order++; this._entries = newEntries;
} },
}
this._entries = newEntries; removeTopic : function(topic) {
}, var order = topic.getOrder();
var entry = this.lookupEntryByOrder(order);
removeTopic : function(topic) { $assert(!entry.isAvailable(), "Illegal state");
var order = topic.getOrder();
var entry = this.lookupEntryByOrder(order); entry.setTopic(null);
$assert(!entry.isAvailable(), "Illegal state"); topic.setOrder(null);
this._entries.erase(entry);
entry.setTopic(null);
topic.setOrder(null); // Repositionate all elements ...
this._entries.erase(entry); this.repositionate();
},
// Repositionate all elements ...
this.repositionate(); addTopic : function(order, topic) {
},
// If the entry is not available, I must swap the the entries...
addTopic : function(order, topic) { var entry = this.lookupEntryByOrder(order);
if (!entry.isAvailable()) {
// If the entry is not available, I must swap the the entries... this.freeEntry(entry);
var entry = this.lookupEntryByOrder(order); // Create a dummy entry ...
if (!entry.isAvailable()) { // Puaj, do something with this...
this.freeEntry(entry); entry = this.createBoardEntry(-1, 0, order);
// Create a dummy entry ... this._entries[order] = entry;
// Puaj, do something with this... }
entry = this.createBoardEntry(-1, 0, order); this._entries[order] = entry;
this._entries[order] = entry;
} // Add to the board ...
this._entries[order] = entry; entry.setTopic(topic, false);
// Add to the board ... // Repositionate all elements ...
entry.setTopic(topic, false); this.repositionate();
},
// Repositionate all elements ...
this.repositionate(); lookupEntryByPosition : function(pos) {
}, $assert(pos, 'position can not be null');
lookupEntryByPosition : function(pos) { var entries = this._entries;
$assert(pos, 'position can not be null'); var result = null;
for (var i = 0; i < entries.length; i++) {
var entries = this._entries; var entry = entries[i];
var result = null; if (pos.y < entry.getUpperLimit() && pos.y >= entry.getLowerLimit()) {
for (var i = 0; i < entries.length; i++) { result = entry;
var entry = entries[i]; }
if (pos.y < entry.getUpperLimit() && pos.y >= entry.getLowerLimit()) { }
result = entry;
} if (result == null) {
} var defaultHeight = this._defaultWidth;
if (entries.length == 0) {
if (result == null) { var reference = this.getReferencePoint();
var defaultHeight = this._defaultWidth; var yReference = reference.y;
if (entries.length == 0) { result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0);
var reference = this.getReferencePoint(); } else {
var yReference = reference.y; var firstEntry = entries[0];
result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0); if (pos.y < firstEntry.getLowerLimit()) {
} else { var upperLimit = firstEntry.getLowerLimit();
var firstEntry = entries[0]; var lowerLimit = upperLimit - defaultHeight;
if (pos.y < firstEntry.getLowerLimit()) { result = this.createBoardEntry(lowerLimit, upperLimit, 0);
var upperLimit = firstEntry.getLowerLimit(); } else {
var lowerLimit = upperLimit - defaultHeight; var entriesLenght = entries.length;
result = this.createBoardEntry(lowerLimit, upperLimit, 0); var lastEntry = entries[entriesLenght - 1];
} else { var lowerLimit = lastEntry.getUpperLimit();
var entriesLenght = entries.length; var upperLimit = lowerLimit + defaultHeight;
var lastEntry = entries[entriesLenght - 1]; result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght);
var lowerLimit = lastEntry.getUpperLimit(); }
var upperLimit = lowerLimit + defaultHeight; }
result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght); }
}
} return result;
} }
})
return result; ;
} mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE = 6;
}) mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60;
;
mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE = 6;
mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60;

View File

@ -174,7 +174,8 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
_noteToXML : function(document, note) { _noteToXML : function(document, note) {
var noteDom = document.createElement("note"); var noteDom = document.createElement("note");
noteDom.setAttribute('text', note.getText()); var cdata = document.createCDATASection(note.getText());
noteDom.appendChild(cdata);
return noteDom; return noteDom;
}, },
@ -313,14 +314,13 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
if ($defined(position)) { if ($defined(position)) {
var pos = position.split(','); var pos = position.split(',');
topic.setPosition(pos[0], pos[1]); topic.setPosition(pos[0], pos[1]);
// topic.setFinalPosition(pos[0], pos[1]);
} }
//Creating icons and children nodes //Creating icons and children nodes
var children = domElem.childNodes; var children = domElem.childNodes;
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
var child = children[i]; var child = children[i];
if (child.nodeType == 1) { if (child.nodeType == Node.ELEMENT_NODE) {
$assert(child.tagName == "topic" || child.tagName == "icon" || child.tagName == "link" || child.tagName == "note", 'Illegal node type:' + child.tagName); $assert(child.tagName == "topic" || child.tagName == "icon" || child.tagName == "link" || child.tagName == "note", 'Illegal node type:' + child.tagName);
if (child.tagName == "topic") { if (child.tagName == "topic") {
var childTopic = this._deserializeNode(child, mindmap); var childTopic = this._deserializeNode(child, mindmap);
@ -349,7 +349,17 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
}, },
_deserializeNote : function(domElem, topic) { _deserializeNote : function(domElem, topic) {
return topic.createNote(domElem.getAttribute("text")); var value = domElem.getAttribute("text");
if(!$defined(value)){
var children = domElem.childNodes;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if(child.nodeType == Node.CDATA_SECTION_NODE){
value = child.nodeValue;
}
}
}
return topic.createNote(value);
}, },
_deserializeRelationship : function(domElement, mindmap) { _deserializeRelationship : function(domElement, mindmap) {

View File

@ -78,6 +78,15 @@
} }
} }
}); });
// @Todo: Hack for testing save ...
window.MapEditorService = {};
window.MapEditorService.saveMap = function(mapId, xmlMapStr, pref, saveHistory){
console.log(xmlMapStr);
};
</script> </script>
<link rel="icon" href="../images/favicon.ico" type="image/x-icon"> <link rel="icon" href="../images/favicon.ico" type="image/x-icon">