Adding new node with Brix integration

This commit is contained in:
Pablol 2011-08-10 23:11:50 -03:00
parent b699c2670c
commit d75ceba363
6 changed files with 72 additions and 26 deletions

View File

@ -31,6 +31,16 @@ mindplot.BrixActionDispatcher = new Class({
} }
var topic = framework.getTopic(topicsIds[0]); var topic = framework.getTopic(topicsIds[0]);
topic.setText(text, true); topic.setText(text, true);
},
addTopic:function(model, parentTopicId, animated) {
var framework = mindplot.collaboration.CollaborationManager.getInstance().getCollaborativeFramework();
var mindmap = framework.getModel();
var centralTopic = mindmap.getCentralTopic();
var newNode = mindmap.createNode(model.getType(), model.getId());
var position = model.getPosition();
newNode.setPosition(position.x, position.y);
newNode.connectTo(centralTopic);
} }
}); });

View File

@ -24,8 +24,8 @@ mindplot.MindmapDesigner = new Class({
// Dispatcher manager ... // Dispatcher manager ...
var commandContext = new mindplot.CommandContext(this); var commandContext = new mindplot.CommandContext(this);
// this._actionDispatcher = new mindplot.BrixActionDispatcher(commandContext); this._actionDispatcher = new mindplot.BrixActionDispatcher(commandContext);
this._actionDispatcher = new mindplot.LocalActionDispatcher(commandContext); // this._actionDispatcher = new mindplot.LocalActionDispatcher(commandContext);
this._actionDispatcher.addEvent("modelUpdate", function(event) { this._actionDispatcher.addEvent("modelUpdate", function(event) {
this._fireEvent("modelUpdate", event); this._fireEvent("modelUpdate", event);

View File

@ -21,6 +21,16 @@ mindplot.collaboration.frameworks.AbstractCollaborativeFramework = new Class({
var id = branch.getId(); var id = branch.getId();
var node = mindmap.createNode(type,id); var node = mindmap.createNode(type,id);
node.setText(branch.getText()); node.setText(branch.getText());
var position = branch.getPosition();
node.setPosition(position.x, position.y);
var children = branch.getChildren();
children.forEach(function(child){
var node2 = new mindplot.model.NodeModel(child.getType(),mindmap, child.getId());
node2.setText(child.getText());
var pos = child.getPosition();
node2.setPosition(pos.x, pos.y);
node._appendChild(node2);
});
mindmap.addBranch(node); mindmap.addBranch(node);
}.bind(this)); }.bind(this));
return mindmap; return mindmap;
@ -38,6 +48,16 @@ mindplot.collaboration.frameworks.AbstractCollaborativeFramework = new Class({
for(var i = 0; i<branches.length; i++){ for(var i = 0; i<branches.length; i++){
if(branches[i].getId()==id){ if(branches[i].getId()==id){
return branches[i]; return branches[i];
}else {
var children = branches[i].getChildren();
for(var j=0; j<children.length; j++){
if(children[j].getId()==id){
return children[j];
}
}
} }
} }
return null; return null;

View File

@ -27,7 +27,7 @@ mindplot.collaboration.frameworks.brix.model.Mindmap = new Class({
var branches = this._brixModel.get("branches"); var branches = this._brixModel.get("branches");
for(var i=0; i<branches.size(); i++){ for(var i=0; i<branches.size(); i++){
var node = branches.get(i); var node = branches.get(i);
var nodeModel = new mindplot.collaboration.frameworks.brix.model.NodeModel(node, this._brixFramework); var nodeModel = new mindplot.collaboration.frameworks.brix.model.NodeModel(node, this._brixFramework, null, this);
this.addBranch(nodeModel, false); this.addBranch(nodeModel, false);
} }
} }

View File

@ -32,20 +32,47 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
}else{ }else{
var text = this._brixModel.get("text"); var text = this._brixModel.get("text");
this.setText(text, false); this.setText(text, false);
var position = this._brixModel.get("position");
this.setPosition(position.get("x"),position.get("y"), false);
var children = this._brixModel.get("children");
for(var i=0; i<children.size(); i++){
var bChild = children.get(i);
var child= new mindplot.collaboration.frameworks.brix.model.NodeModel(bChild, this._brixFramework, null, mindmap);
this._appendChild(child, false);
}
} }
this._addBrixListeners(); this._addBrixListeners();
}, },
_addBrixListeners:function(){ _addBrixListeners:function(){
this._brixModel.addListener("valueChanged", this._valuechangeListener.bindWithEvent(this)); this._brixModel.addListener("valueChanged", this._valuechangeListener.bindWithEvent(this));
this._brixModel.get("children").addListener("valuesAdded", this._childAddedListener.bindWithEvent(this));
}, },
_valuechangeListener:function(event){ _valuechangeListener:function(event){
this._brixFramework.getActionDispatcher().changeTextOnTopic(this.getId(),event.getNewValue()); this._brixFramework.getActionDispatcher().changeTextOnTopic(this.getId(),event.getNewValue());
}, },
_childAddedListener:function(event){
var newValue = event.getValues().get(0);
var cmodel = new mindplot.collaboration.frameworks.brix.model.NodeModel(newValue,this._brixFramework, null, this.getMindmap());
this._appendChild(cmodel, false);
var model = new mindplot.model.NodeModel(newValue.get("type"),designer.getMindmap(), newValue.get("id"));
var position = newValue.get("position");
var x = position.get("x");
var y = position.get("y");
model.setPosition(x, y);
this._brixFramework.getActionDispatcher().addTopic(model, this.getId(), true);
},
_createBrixModel:function(){ _createBrixModel:function(){
var model = this._brixFramework.getBrixModel().create("Map"); var model = this._brixFramework.getBrixModel().create("Map");
model.put("type",this._type); model.put("type",this._type);
model.put("id",this._id); model.put("id",this._id);
model.put("text",this._type==mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE?"Central Topic":"Main Topic"); model.put("text",this._type==mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE?"Central Topic":"Main Topic");
var position = this._brixFramework.getBrixModel().create("Map");
position.put("x",0);
position.put("y",0);
model.put("position",position);
var children = this._brixFramework.getBrixModel().create("List");
model.put("children", children);
return model; return model;
}, },
getBrixModel:function(){ getBrixModel:function(){
@ -174,10 +201,11 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
this._icons.pop(); this._icons.pop();
}, },
_appendChild : function(child) { _appendChild : function(child, updateModel) {
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object'); this.parent(child);
this._children.push(child); if(!$defined(updateModel) || ($defined(updateModel) && updateModel)){
child._parent = this; this.getBrixModel().get("children").add(child.getBrixModel());
}
}, },
_removeChild : function(child) { _removeChild : function(child) {
@ -186,19 +214,13 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
child._parent = null; child._parent = null;
}, },
setPosition : function(x, y) { setPosition : function(x, y, updateModel) {
$assert(x, "x coordinate must be defined"); this.parent(x,y);
$assert(y, "y coordinate must be defined"); if(!$defined(updateModel) || ($defined(updateModel) && updateModel)){
var position = this.getBrixModel().get("position");
if (!$defined(this._position)) { position.put("x",this._position.x);
this._position = new core.Point(); position.put("y",this._position.y);
} }
this._position.x = parseInt(x);
this._position.y = parseInt(y);
},
getPosition : function() {
return this._position;
}, },
setFinalPosition : function(x, y) { setFinalPosition : function(x, y) {
@ -318,12 +340,6 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
}, },
connectTo : function(parent) {
var mindmap = this.getMindmap();
mindmap.connect(parent, this);
this._parent = parent;
},
disconnect : function() { disconnect : function() {
var mindmap = this.getMindmap(); var mindmap = this.getMindmap();
mindmap.disconnect(this); mindmap.disconnect(this);

View File

@ -5,7 +5,7 @@
<!--[if lt IE 9]> <!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta http-equiv="X-UA-Compatible" content="chrome=1">
<![endif]--> <![endif]-->
<!--<script type="text/javascript" src="http://docs.google.com/brix/static/api/js/jsapi.nocache.js"></script>--> <script type="text/javascript" src="http://docs.google.com/brix/static/api/js/jsapi.nocache.js"></script>
<!-- Internet Explorer 8 Hack --> <!-- Internet Explorer 8 Hack -->
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
<title>WiseMapping - Editor </title> <title>WiseMapping - Editor </title>