- Fix Link node

- Finish local storage support
This commit is contained in:
Paulo Veiga 2011-11-30 00:32:24 -03:00
parent 334206ab19
commit bc87d0f311
5 changed files with 138 additions and 124 deletions

View File

@ -43,7 +43,7 @@ mindplot.LocalStorageManager = new Class({
// If I could not load it from a file, hard code one.
if (xml == null) {
xml = '<map name="6" version="pela"><topic central="true" text="General Status" id="1"/></map>';
throw "Map could not be loaded";
}
}

View File

@ -313,7 +313,7 @@ mindplot.Topic = new Class({
//Links
var links = model.getLinks();
for (var i = 0; i < links.length; i++) {
this._link = new mindplot.LinkIcon(links[i], this, designer);
this._link = new mindplot.LinkIcon(this,links[i]);
result.addIcon(this._link);
}

View File

@ -211,11 +211,9 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
this._idsMap = new Hash();
// Start the loading process ...
var mindmap = new mindplot.model.Mindmap();
var version = rootElem.getAttribute("version");
mindmap.setVersion(version);
var mindmap = new mindplot.model.Mindmap(mapId, version);
var children = rootElem.childNodes;
for (var i = 0; i < children.length; i++) {
var child = children[i];
@ -342,7 +340,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
_deserializeIcon : function(domElem, topic) {
var icon = domElem.getAttribute("id");
icon = icon.replace("images/","icons/legacy/");
icon = icon.replace("images/", "icons/legacy/");
return topic.createIcon(icon);
},
@ -352,13 +350,13 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
_deserializeNote : function(domElem, topic) {
var value = domElem.getAttribute("text");
if(!$defined(value)){
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;
}
var child = children[i];
if (child.nodeType == Node.CDATA_SECTION_NODE) {
value = child.nodeValue;
}
}
}
return topic.createNote(value);

View File

@ -1,111 +1,120 @@
/*
* 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.model.Mindmap = new Class({
Extends: mindplot.model.IMindmap,
initialize : function() {
this._branches = [];
this._description = null;
this._version = null;
this._relationships = [];
},
getDescription : function() {
return this._description;
},
setDescription : function(value) {
this._description = value;
},
getId : function() {
return this._iconType;
},
setId : function(id) {
this._iconType = id;
},
getVersion : function() {
return this._version;
},
setVersion : function(version) {
this._version = version;
},
addBranch : function(nodeModel) {
$assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects');
var branches = this.getBranches();
if (branches.length == 0) {
$assert(nodeModel.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, "First element must be the central topic");
nodeModel.setPosition(0, 0);
} else {
$assert(nodeModel.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, "Mindmaps only have one cental topic");
}
this._branches.push(nodeModel);
},
removeBranch : function(nodeModel) {
$assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects');
return this._branches.erase(nodeModel);
},
getBranches : function() {
return this._branches;
},
getRelationships : function() {
return this._relationships;
},
hasAlreadyAdded : function(node) {
var result = false;
// Check in not connected nodes.
var branches = this._branches;
for (var i = 0; i < branches.length; i++) {
result = branches[i]._isChildNode(node);
if (result) {
break;
}
}
},
createNode : function(type, id) {
$assert(type, "node type can not be null");
return new mindplot.model.NodeModel(type, this, id);
},
createRelationship : function(fromNode, toNode) {
$assert(fromNode, 'from node cannot be null');
$assert(toNode, 'to node cannot be null');
return new mindplot.model.RelationshipModel(fromNode, toNode);
},
addRelationship : function(relationship) {
this._relationships.push(relationship);
},
removeRelationship : function(relationship) {
this._relationships.erase(relationship);
}
}
);
/*
* 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.model.Mindmap = new Class({
Extends: mindplot.model.IMindmap,
initialize : function(id, version) {
$assert(id, "Id can not be null");
this._branches = [];
this._description = null;
this._relationships = [];
this._version = $defined(version) ? version : 'pela';
this._id = id;
},
getDescription : function() {
return this._description;
},
setDescription : function(value) {
this._description = value;
},
getId : function() {
return this._id;
},
setId : function(id) {
this._id = id;
},
getVersion : function() {
return this._version;
},
setVersion : function(version) {
this._version = version;
},
addBranch : function(nodeModel) {
$assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects');
var branches = this.getBranches();
if (branches.length == 0) {
$assert(nodeModel.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, "First element must be the central topic");
nodeModel.setPosition(0, 0);
} else {
$assert(nodeModel.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, "Mindmaps only have one cental topic");
}
this._branches.push(nodeModel);
},
removeBranch : function(nodeModel) {
$assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects');
return this._branches.erase(nodeModel);
},
getBranches : function() {
return this._branches;
},
getRelationships : function() {
return this._relationships;
},
hasAlreadyAdded : function(node) {
var result = false;
// Check in not connected nodes.
var branches = this._branches;
for (var i = 0; i < branches.length; i++) {
result = branches[i]._isChildNode(node);
if (result) {
break;
}
}
},
createNode : function(type, id) {
$assert(type, "node type can not be null");
return new mindplot.model.NodeModel(type, this, id);
},
createRelationship : function(fromNode, toNode) {
$assert(fromNode, 'from node cannot be null');
$assert(toNode, 'to node cannot be null');
return new mindplot.model.RelationshipModel(fromNode, toNode);
},
addRelationship : function(relationship) {
this._relationships.push(relationship);
},
removeRelationship : function(relationship) {
this._relationships.erase(relationship);
}
}
);
mindplot.model.Mindmap.buildEmpty = function(mapId) {
var result = new mindplot.model.Mindmap(mapId);
var node = result.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, 0);
result.addBranch(node);
return result;
};

View File

@ -25,7 +25,7 @@
$(document).fireEvent('loadcomplete', 'brix');
};
var mapId = '10'; // @todo: Must be changed ...
var mapId = 'mapId'; // @todo: Must be changed ...
var brixReady = false;
var mindReady = false;
var collab = 'standalone';
@ -58,7 +58,14 @@
// Load map from XML ...
var persitence = mindplot.PersitenceManager.getInstance();
var mindmap = persitence.load("map2");
var mindmap;
try {
mindmap = persitence.load(mapId);
} catch(e) {
// If the map could not be loaded, create a new empty map...
mindmap = mindplot.model.Mindmap.buildEmpty(mapId);
}
designer.loadMap(mindmap);
// If not problem has arisen, close the dialog ...