Fix several issues.
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({
|
||||
initialize: function(model, collaborativeModelFactory)
|
||||
{
|
||||
this._collaborativeModelFactory = collaborativeModelFactory;
|
||||
if (!$defined(model)) {
|
||||
model = this._buildInitialCollaborativeModel();
|
||||
}
|
||||
initialize: function(model) {
|
||||
$assert(model, "model can not be null");
|
||||
this._model = model;
|
||||
this._actionDispatcher = null;
|
||||
},
|
||||
@@ -18,31 +14,17 @@ mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({
|
||||
var cmind = this.getModel();
|
||||
var mmind = new mindplot.model.Mindmap();
|
||||
cmind.copyTo(mmind);
|
||||
|
||||
return mmind;
|
||||
},
|
||||
|
||||
_buildInitialCollaborativeModel: function() {
|
||||
|
||||
var mindmap = this._collaborativeModelFactory.buildMindMap();
|
||||
var centralTopic = mindmap.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE);
|
||||
mindmap.addBranch(centralTopic, true);
|
||||
this.addMindmap(mindmap);
|
||||
return mindmap;
|
||||
},
|
||||
|
||||
addMindmap:function(model) {
|
||||
throw "method to implement";
|
||||
},
|
||||
|
||||
_findTopic : function(topics, id) {
|
||||
_findTopic : function(nodes, id) {
|
||||
var result;
|
||||
for (var i = 0; i < topics.length; i++) {
|
||||
var topic = topics[i];
|
||||
if (topic.getId() == id) {
|
||||
result = topic;
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
if (node.getId() == id) {
|
||||
result = node;
|
||||
} else {
|
||||
var children = topic.getChildren();
|
||||
var children = node.getChildren();
|
||||
result = this._findTopic(children, id)
|
||||
}
|
||||
|
||||
@@ -54,9 +36,9 @@ mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({
|
||||
},
|
||||
|
||||
getTopic:function(id) {
|
||||
$assert(id, "id can not be null")
|
||||
$assert($defined(id), "id can not be null");
|
||||
var branches = this.getModel().getBranches();
|
||||
var result = this._findTopic(branches, id);
|
||||
var result = this._findTopic(branches, id);
|
||||
$assert(result, "Could not find topic:" + id);
|
||||
return result;
|
||||
},
|
||||
|
@@ -17,12 +17,10 @@
|
||||
*/
|
||||
|
||||
mindplot.collaboration.framework.AbstractCollaborativeModelFactory = new Class({
|
||||
initialize:function() {
|
||||
createNewMindmap:function() {
|
||||
throw "Unsupported operation";
|
||||
},
|
||||
buildMindMap:function() {
|
||||
|
||||
},
|
||||
buildCollaborativeModelFor:function(model) {
|
||||
|
||||
buildMindmap:function(model) {
|
||||
throw "Unsupported operation";
|
||||
}
|
||||
});
|
@@ -19,17 +19,19 @@
|
||||
mindplot.collaboration.framework.brix.BrixCollaborativeModelFactory = new Class({
|
||||
Extends:mindplot.collaboration.framework.AbstractCollaborativeModelFactory,
|
||||
initialize:function(brixFramework) {
|
||||
$assert(brixFramework, 'brixFramework can not be null');
|
||||
this._brixFramework = brixFramework;
|
||||
},
|
||||
|
||||
buildMindMap:function() {
|
||||
createNewMindmap : function() {
|
||||
var mindmap = new mindplot.collaboration.framework.brix.model.Mindmap(this._brixFramework);
|
||||
var node = mindmap.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, 0);
|
||||
mindmap.setVersion('pela-brix');
|
||||
mindmap.addBranch(node);
|
||||
return mindmap;
|
||||
},
|
||||
|
||||
buildCollaborativeModelFor:function(model) {
|
||||
buildMindmap : function(model) {
|
||||
return new mindplot.collaboration.framework.brix.model.Mindmap(this._brixFramework, model);
|
||||
}
|
||||
});
|
@@ -20,19 +20,18 @@ mindplot.collaboration.framework.brix.BrixFramework = new Class({
|
||||
Extends: mindplot.collaboration.framework.AbstractCollaborativeFramework,
|
||||
initialize: function(model, app) {
|
||||
this._app = app;
|
||||
var collaborativeModelFactory = new mindplot.collaboration.framework.brix.BrixCollaborativeModelFactory(this);
|
||||
var cModel = null;
|
||||
var factory = new mindplot.collaboration.framework.brix.BrixCollaborativeModelFactory(this);
|
||||
var root = this.getBrixModel().getRoot();
|
||||
if (!root.isEmpty()) {
|
||||
var brixMap = root.get("mindmap");
|
||||
cModel = collaborativeModelFactory.buildCollaborativeModelFor(brixMap);
|
||||
var cmodel = null;
|
||||
var brixMap = root.get("mindmap");
|
||||
if (brixMap != null) {
|
||||
cmodel = factory.buildMindmap(brixMap);
|
||||
} else {
|
||||
cmodel = factory.createNewMindmap();
|
||||
root.put("mindmap", cmodel.getBrixModel());
|
||||
}
|
||||
this.parent(cModel, collaborativeModelFactory);
|
||||
},
|
||||
|
||||
addMindmap:function(model) {
|
||||
var root = this.getBrixModel().getRoot();
|
||||
root.put("mindmap", model);
|
||||
this.parent(cmodel);
|
||||
console.log("cmodel:" + cmodel.inspect());
|
||||
},
|
||||
|
||||
getBrixModel:function() {
|
||||
|
@@ -48,7 +48,6 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
|
||||
var model = this._brixFramework.getBrixModel().create("Map");
|
||||
var branches = this._brixFramework.getBrixModel().create("List");
|
||||
model.put("branches", branches);
|
||||
this._brixFramework.addMindmap(model);
|
||||
return model;
|
||||
},
|
||||
|
||||
@@ -75,29 +74,17 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
|
||||
|
||||
removeBranch : function(nodeModel) {
|
||||
$assert(nodeModel, "nodeModel can not be null");
|
||||
$assert(nodeModel.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, "central topic can not be removed");
|
||||
|
||||
var branches = this._brixModel.get("branches");
|
||||
var brixModel = nodeModel.getBrixModel();
|
||||
branches.remove(brixModel);
|
||||
},
|
||||
|
||||
connect : function(parent, child) {
|
||||
// Remove from the branch ...
|
||||
var branches = this._brixModel.get("branches");
|
||||
var childIndex = null;
|
||||
for (var i = 0; i < branches.size(); i++) {
|
||||
if (branches.get(i) == child.getBrixModel()) {
|
||||
childIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (childIndex != null) {
|
||||
branches.remove(childIndex);
|
||||
}
|
||||
},
|
||||
|
||||
createNode : function(type, id) {
|
||||
return mindplot.collaboration.framework.brix.model.NodeModel.create(this._brixFramework, this, type, id);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -28,23 +28,40 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
|
||||
this._addBrixListeners();
|
||||
},
|
||||
|
||||
_addBrixListeners:function() {
|
||||
// Register listener for properties changes ....
|
||||
this._brixModel.addListener("valueChanged", function(event) {
|
||||
var key = event.getProperty();
|
||||
_addBrixListeners : function() {
|
||||
|
||||
var actionDispatcher = this._brixFramework.getActionDispatcher();
|
||||
var value = event.getNewValue();
|
||||
// Nodes creation should be cached ...
|
||||
if (!this._brixModel.__registered) {
|
||||
// Register listener for properties changes ....
|
||||
this._brixModel.addListener("valueChanged", function(event) {
|
||||
var key = event.getProperty();
|
||||
|
||||
var funName = 'change' + key.capitalize() + 'ToTopic';
|
||||
if (!$defined(actionDispatcher[funName])) {
|
||||
throw "No implementation for:" + funName;
|
||||
}
|
||||
actionDispatcher[funName](this.getId(), value);
|
||||
}.bind(this));
|
||||
var actionDispatcher = this._brixFramework.getActionDispatcher();
|
||||
var value = event.getNewValue();
|
||||
|
||||
var children = this._brixModel.get("children");
|
||||
children.addListener("valuesAdded", this._childAddedListener.bind(this));
|
||||
var funName = 'change' + key.capitalize() + 'ToTopic';
|
||||
if (!$defined(actionDispatcher[funName])) {
|
||||
throw "No implementation for:" + funName;
|
||||
}
|
||||
console.log("This action dispatcher:" + funName);
|
||||
actionDispatcher[funName]([this.getId()], value);
|
||||
}.bind(this));
|
||||
|
||||
var children = this._brixModel.get("children");
|
||||
children.addListener("valuesAdded", function(event) {
|
||||
var brixNodeModel = event.getValues().get(0);
|
||||
|
||||
var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, brixNodeModel, this.getMindmap());
|
||||
|
||||
// @Todo: This is not ok...
|
||||
var model = new mindplot.model.NodeModel(cmodel.getType(), designer.getMindmap(), this.getId());
|
||||
cmodel.copyTo(model);
|
||||
|
||||
this._brixFramework.getActionDispatcher().addTopic(model, this.getId(), true);
|
||||
}.bind(this));
|
||||
|
||||
this._brixModel.__registered = true;
|
||||
}
|
||||
},
|
||||
|
||||
getChildren : function() {
|
||||
@@ -58,18 +75,6 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
|
||||
return result;
|
||||
},
|
||||
|
||||
_childAddedListener:function(event) {
|
||||
var newValue = event.getValues().get(0);
|
||||
var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, newValue, 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);
|
||||
},
|
||||
|
||||
getBrixModel:function() {
|
||||
return this._brixModel;
|
||||
@@ -89,12 +94,15 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
|
||||
return this._brixModel.getKeys();
|
||||
},
|
||||
|
||||
connectTo : function(parent) {
|
||||
var mindmap = this.getMindmap();
|
||||
mindmap.connect(parent, this);
|
||||
getParent : function() {
|
||||
return this._brixModel._parent;
|
||||
},
|
||||
|
||||
// @Todo: This must be persited ?Ummm...
|
||||
this._parent = parent;
|
||||
appendChild : function(node) {
|
||||
$assert(node && node.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
|
||||
var children = this._brixModel.get("children");
|
||||
children.add(node.getBrixModel());
|
||||
node.getBrixModel()._parent = this;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -104,10 +112,9 @@ mindplot.collaboration.framework.brix.model.NodeModel.create = function(brixFram
|
||||
$assert(type, 'type can not be null');
|
||||
$assert($defined(id), 'id can not be null');
|
||||
|
||||
|
||||
var brixModel = brixFramework.getBrixModel().create("Map");
|
||||
brixModel.put("type", type);
|
||||
brixModel.put("id", this._id);
|
||||
brixModel.put("id", id);
|
||||
|
||||
var children = brixFramework.getBrixModel().create("List");
|
||||
brixModel.put("children", children);
|
||||
|
Reference in New Issue
Block a user