More fixes.
This commit is contained in:
@@ -81,7 +81,6 @@ mindplot.model.IMindmap = new Class({
|
||||
$assert(parent, 'Child model seems to be already connected');
|
||||
|
||||
parent.removeChild(child);
|
||||
|
||||
this.addBranch(child);
|
||||
},
|
||||
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
mindplot.model.INodeModel = new Class({
|
||||
initialize: function(mindmap) {
|
||||
$assert(mindmap, 'mindmap can not be null');
|
||||
$assert(mindmap && mindmap.getBranches, 'mindmap can not be null');
|
||||
this._mindmap = mindmap;
|
||||
},
|
||||
|
||||
@@ -200,6 +200,50 @@ mindplot.model.INodeModel = new Class({
|
||||
mindmap.connect(parent, this);
|
||||
},
|
||||
|
||||
copyTo : function(target) {
|
||||
var source = this;
|
||||
// Copy properties ...
|
||||
var keys = source.getPropertiesKeys();
|
||||
keys.forEach(function(key) {
|
||||
var value = source.getProperty(key);
|
||||
target.putProperty(key, value);
|
||||
});
|
||||
|
||||
// Copy childrens ...
|
||||
var children = this.getChildren();
|
||||
var tmindmap = target.getMindmap();
|
||||
|
||||
children.forEach(function(snode) {
|
||||
var tnode = tmindmap.createNode(snode.getType(), snode.getId());
|
||||
snode.copyTo(tnode);
|
||||
target.appendChild(tnode);
|
||||
});
|
||||
|
||||
return target;
|
||||
},
|
||||
|
||||
deleteNode : function() {
|
||||
var mindmap = this.getMindmap();
|
||||
|
||||
// if it has children nodes, Their must be disconnected.
|
||||
var children = this.getChildren();
|
||||
var length = children.length;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
var child = children[i];
|
||||
mindmap.disconnect(child);
|
||||
}
|
||||
|
||||
// if it is connected, I must remove it from the parent..
|
||||
var parent = this.getParent();
|
||||
if ($defined(parent)) {
|
||||
mindmap.disconnect(this);
|
||||
}
|
||||
|
||||
// It's an isolated node. It must be a hole branch ...
|
||||
mindmap.removeBranch(this);
|
||||
},
|
||||
|
||||
getPropertiesKeys : function() {
|
||||
throw "Unsupported operation";
|
||||
},
|
||||
@@ -212,10 +256,6 @@ mindplot.model.INodeModel = new Class({
|
||||
throw "Unsupported operation";
|
||||
},
|
||||
|
||||
deleteNode : function() {
|
||||
throw "Unsupported operation";
|
||||
},
|
||||
|
||||
createLink : function(url) {
|
||||
throw "Unsupported operation";
|
||||
},
|
||||
@@ -283,7 +323,7 @@ mindplot.model.INodeModel = new Class({
|
||||
|
||||
var children = this.getChildren();
|
||||
if (children.length > 0) {
|
||||
result = result + "{(size:" + children.length;
|
||||
result = result + ", children: {(size:" + children.length;
|
||||
children.forEach(function(node) {
|
||||
result = result + "=> (" + node.getPropertiesKeys() + ")";
|
||||
}.bind(this));
|
||||
@@ -293,26 +333,9 @@ mindplot.model.INodeModel = new Class({
|
||||
return result;
|
||||
},
|
||||
|
||||
copyTo : function(target) {
|
||||
var source = this;
|
||||
// Copy properties ...
|
||||
var keys = source.getPropertiesKeys();
|
||||
keys.forEach(function(key) {
|
||||
var value = source.getProperty(key);
|
||||
target.putProperty(key, value);
|
||||
});
|
||||
removeChild : function(child) {
|
||||
throw "Unsupported operation";
|
||||
|
||||
// Copy childrens ...
|
||||
var children = this.getChildren();
|
||||
var tmindmap = target.getMindmap();
|
||||
|
||||
children.forEach(function(snode) {
|
||||
var tnode = tmindmap.createNode(snode.getType(), snode.getId());
|
||||
snode.copyTo(tnode);
|
||||
target.appendChild(tnode);
|
||||
});
|
||||
|
||||
return target;
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -41,9 +41,8 @@ mindplot.model.NodeModel = new Class({
|
||||
},
|
||||
|
||||
|
||||
getProperties: function()
|
||||
{
|
||||
return this._properties;
|
||||
getProperties: function() {
|
||||
return this._properties;
|
||||
},
|
||||
|
||||
getProperty : function(key) {
|
||||
@@ -67,10 +66,10 @@ mindplot.model.NodeModel = new Class({
|
||||
return result;
|
||||
},
|
||||
|
||||
addChildren : function(){
|
||||
addChildren : function() {
|
||||
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
|
||||
this._children.push(child);
|
||||
child._parent = this;
|
||||
this._children.push(child);
|
||||
child._parent = this;
|
||||
},
|
||||
|
||||
createLink : function(url) {
|
||||
@@ -223,28 +222,6 @@ mindplot.model.NodeModel = new Class({
|
||||
|
||||
},
|
||||
|
||||
deleteNode : function() {
|
||||
var mindmap = this._mindmap;
|
||||
|
||||
// if it has children nodes, Their must be disconnected.
|
||||
var lenght = this._children;
|
||||
for (var i = 0; i < lenght; i++) {
|
||||
var child = this._children[i];
|
||||
mindmap.disconnect(child);
|
||||
}
|
||||
|
||||
var parent = this._parent;
|
||||
if ($defined(parent)) {
|
||||
// if it is connected, I must remove it from the parent..
|
||||
mindmap.disconnect(this);
|
||||
}
|
||||
|
||||
// It's an isolated node. It must be a hole branch ...
|
||||
var branches = mindmap.getBranches();
|
||||
branches.erase(this);
|
||||
|
||||
},
|
||||
|
||||
inspect : function() {
|
||||
return '(type:' + this.getType() + ' , id: ' + this.getId() + ')';
|
||||
}
|
||||
|
Reference in New Issue
Block a user