Keep fixing issues.

This commit is contained in:
Paulo Veiga 2011-09-09 02:22:44 -03:00
parent 0c216778e5
commit 2a4d96151b
15 changed files with 157 additions and 98 deletions

View File

@ -39,7 +39,7 @@ mindplot.ActionDispatcher = new Class({
throw "method must be implemented.";
},
addTopic: function(model, parentTopicId, animated) {
addTopic: function(nodeModel, parentTopicId, animated) {
throw "method must be implemented.";
},

View File

@ -39,15 +39,16 @@ mindplot.BrixActionDispatcher = new Class({
return mindplot.collaboration.CollaborationManager.getInstance().getCollaborativeFramework();
},
addTopic : function(model, parentTopicId, animated) {
addTopic : function(nodeModel, parentTopicId, animated) {
var framework = this._getFramework();
var mindmap = framework.getModel();
var centralTopic = mindmap.getCentralTopic();
var cmapindmap = framework.getModel();
var centralTopic = cmapindmap.getCentralTopic();
var newNode = mindmap.createNode(model.getType(), model.getId());
var position = model.getPosition();
newNode.setPosition(position.x, position.y);
newNode.connectTo(centralTopic);
var cnode = cmapindmap.createNode(nodeModel.getType(), nodeModel.getId());
var position = nodeModel.getPosition();
cnode.setPosition(position.x, position.y);
cnode.connectTo(centralTopic);
},
changeFontSizeToTopic : function(topicsIds, size) {

View File

@ -38,8 +38,8 @@ mindplot.LocalActionDispatcher = new Class({
this.execute(command);
},
addTopic:function(model, parentTopicId, animated) {
var command = new mindplot.commands.AddTopicCommand(model, parentTopicId, animated);
addTopic:function(nodeModel, parentTopicId, animated) {
var command = new mindplot.commands.AddTopicCommand(nodeModel, parentTopicId, animated);
this.execute(command);
},

View File

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

View File

@ -22,21 +22,12 @@ mindplot.collaboration.CollaborationManager = new Class({
this.collaborativeModelReady = null;
},
isCollaborationFrameworkAvailable : function() {
return (typeof goog != "undefined") && (typeof goog.collab != "undefined");
},
setCollaborativeFramework : function(framework) {
this._collaborativeFramework = framework;
this.collaborativeModelReady = true;
},
isCollaborativeFrameworkReady:function() {
return this.collaborativeModelReady;
},
buildWiseModel: function() {
return this._collaborativeFramework.buildWiseModel();
buildMindmap: function() {
return this._collaborativeFramework.buildMindmap();
},
getCollaborativeFramework:function() {

View File

@ -1,5 +1,6 @@
mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({
initialize: function(model, collaborativeModelFactory) {
initialize: function(model, collaborativeModelFactory)
{
this._collaborativeModelFactory = collaborativeModelFactory;
if (!$defined(model)) {
model = this._buildInitialCollaborativeModel();
@ -12,38 +13,26 @@ mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({
return this._model;
},
buildWiseModel : function() {
var cmindMap = this.getModel();
var mindmap = new mindplot.model.Mindmap();
var branches = cmindMap.getBranches();
branches.forEach(function(branch) {
var type = branch.getType();
var id = branch.getId();
var node = mindmap.createNode(type, id);
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);
}.bind(this));
return mindmap;
buildMindmap : function() {
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) {

View File

@ -21,10 +21,15 @@ mindplot.collaboration.framework.brix.BrixCollaborativeModelFactory = new Class(
initialize:function(brixFramework) {
this._brixFramework = brixFramework;
},
buildMindMap:function() {
return new mindplot.collaboration.framework.brix.model.Mindmap(null, this._brixFramework);
var mindmap = new mindplot.collaboration.framework.brix.model.Mindmap(this._brixFramework);
var node = mindmap.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, 0);
mindmap.addBranch(node);
return mindmap;
},
buildCollaborativeModelFor:function(model) {
return new mindplot.collaboration.framework.brix.model.Mindmap(model, this._brixFramework);
return new mindplot.collaboration.framework.brix.model.Mindmap(this._brixFramework, model);
}
});

View File

@ -24,35 +24,38 @@ mindplot.collaboration.framework.brix.BrixFramework = new Class({
var cModel = null;
var root = this.getBrixModel().getRoot();
if (!root.isEmpty()) {
cModel = collaborativeModelFactory.buildCollaborativeModelFor(root.get("mindmap"));
var brixMap = root.get("mindmap");
cModel = collaborativeModelFactory.buildCollaborativeModelFor(brixMap);
}
this.parent(cModel, collaborativeModelFactory);
},
addMindmap:function(model) {
var root = this.getBrixModel().getRoot();
root.put("mindmap", model);
},
getBrixModel:function() {
return this._app.getModel();
},
buildWiseModel: function() {
return this.parent();
}
});
instanciated = false;
mindplot.collaboration.framework.brix.BrixFramework.init = function(onload) {
$assert(onload, "load function can not be null");
if ((typeof isGoogleBrix != "undefined") && !instanciated) {
instanciated = true;
if (!instanciated) {
var app = new goog.collab.CollaborativeApp();
mindplot.collaboration.framework.brix.BrixFramework.buildMenu(app);
app.start();
app.addListener('modelLoad', function(model) {
var framework = new mindplot.collaboration.framework.brix.BrixFramework(model, app);
mindplot.collaboration.CollaborationManager.getInstance().setCollaborativeFramework(framework);
onload();
}.bind(this));
instanciated = true;
}
};

View File

@ -17,21 +17,33 @@
*/
mindplot.collaboration.framework.brix.model.Mindmap = new Class({
Extends:mindplot.model.IMindmap,
initialize:function(brixModel, brixFramework) {
this._brixModel = brixModel;
initialize:function(brixFramework, brixModel) {
$assert(brixFramework, 'brixFramework can not be null');
this._brixFramework = brixFramework;
if (!$defined(this._brixModel)) {
if (!$defined(brixModel)) {
this._brixModel = this._createBrixModel();
} else {
var branches = this._brixModel.get("branches");
for (var i = 0; i < branches.size(); i++) {
var node = branches.get(i);
var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(node, this._brixFramework, null, this);
this.addBranch(nodeModel, false);
}
this._brixModel = brixModel;
}
},
getVersion: function() {
return this._brixModel.get('version');
},
setVersion: function(value) {
this._brixModel.put('version', value);
},
getDescription: function() {
return this._brixModel.get('description');
},
setDescription: function(value) {
this._brixModel.put('description', value);
},
_createBrixModel:function() {
var model = this._brixFramework.getBrixModel().create("Map");
var branches = this._brixFramework.getBrixModel().create("List");
@ -47,11 +59,12 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
getBranches : function() {
var result = [];
var branches = this._brixModel.get("branches");
for (var i = 0; i < branches.size(); i++) {
result.push();
var node = branches.get(i);
var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this);
result.push(nodeModel);
}
return result;
},
addBranch : function(nodeModel) {
@ -63,12 +76,11 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
removeBranch : function(nodeModel) {
$assert(nodeModel, "nodeModel can not be null");
var branches = this._brixModel.get("branches");
branches.remove(nodeModel.getBrixModel());
var brixModel = nodeModel.getBrixModel();
branches.remove(brixModel);
},
connect : function(parent, child) {
this.parent(parent, child);
// Remove from the branch ...
var branches = this._brixModel.get("branches");
var childIndex = null;
@ -84,7 +96,8 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
},
createNode : function(type, id) {
return mindplot.collaboration.framework.brix.model.NodeModel.create(this._brixFramework, type, id, this);
return mindplot.collaboration.framework.brix.model.NodeModel.create(this._brixFramework, this, type, id);
}
}
);
);

View File

@ -18,14 +18,13 @@
mindplot.collaboration.framework.brix.model.NodeModel = new Class({
Extends: mindplot.model.INodeModel,
initialize : function(brixModel, brixFramework, mindmap) {
$assert(brixModel, "brixModel can not null");
initialize : function(brixFramework, brixModel, mindmap) {
$assert(brixFramework, "brixFramework can not null");
$assert(brixModel, "brixModel can not null");
this.parent(mindmap);
this._brixModel = brixModel;
this._brixFramework = brixFramework;
this._injectSetAndGet();
this._addBrixListeners();
},
@ -44,12 +43,24 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
actionDispatcher[funName](this.getId(), value);
}.bind(this));
this._brixModel.get("children").addListener("valuesAdded", this._childAddedListener.bind(this));
var children = this._brixModel.get("children");
children.addListener("valuesAdded", this._childAddedListener.bind(this));
},
getChildren : function() {
var result = [];
var children = this._brixModel.get("children");
for (var i = 0; i < children.size(); i++) {
var node = children.get(i);
var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this);
result.push(nodeModel);
}
return result;
},
_childAddedListener:function(event) {
var newValue = event.getValues().get(0);
var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(newValue, this._brixFramework, null, this.getMindmap());
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"));
@ -62,13 +73,41 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
getBrixModel:function() {
return this._brixModel;
},
putProperty : function(key, value) {
$defined(key, 'key can not be null');
this._brixModel.put(key, value);
},
getProperty : function(key) {
$defined(key, 'key can not be null');
return this._brixModel.get(key);
},
getPropertiesKeys : function() {
return this._brixModel.getKeys();
},
connectTo : function(parent) {
var mindmap = this.getMindmap();
mindmap.connect(parent, this);
// @Todo: This must be persited ?Ummm...
this._parent = parent;
}
});
mindplot.collaboration.framework.brix.model.NodeModel.create = function(brixFramework, type, id, mindmap) {
mindplot.collaboration.framework.brix.model.NodeModel.create = function(brixFramework, mindmap, type, id) {
$assert(brixFramework, 'brixFramework can not be null');
$assert(mindmap, 'mindmap can not be null');
$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); // @todo...
brixModel.put("id", this._id);
var children = brixFramework.getBrixModel().create("List");
brixModel.put("children", children);

View File

@ -110,17 +110,15 @@ mindplot.model.IMindmap = new Class({
result = '{ ';
var branches = this.getBranches();
result = result + "version:" + this.getVersion();
for (var i = 0; i < branches.length; i++) {
var node = branches[i];
if (i != 0) {
result = result + ', ';
}
result = result + this._toString(node);
}
result = result + ' } ';
return result;
},
@ -147,18 +145,20 @@ mindplot.model.IMindmap = new Class({
return result;
},
copyTo : function(mindmap) {
var version = this.getVersion();
mindmap.setVersion(version);
copyTo : function(target) {
var source = this;
var version = source.getVersion();
target.setVersion(version);
var desc = this.getDescription();
mindmap.setDescription(desc);
target.setDescription(desc);
var sbranchs = this.getBranches();
// Then the rest of the branches ...
var sbranchs = source.getBranches();
sbranchs.forEach(function(snode) {
var tnode = mindmap.createNode(snode.getType(), snode.getId());
var tnode = target.createNode(snode.getType(), snode.getId());
snode.copyTo(tnode);
mindmap.addBranch(snode);
target.addBranch(tnode);
});
}
});

View File

@ -191,11 +191,11 @@ mindplot.model.INodeModel = new Class({
},
putProperty: function(key, value) {
getPropertiesKeys : function() {
throw "Unsupported operation";
},
setProperty: function(key, value) {
putProperty: function(key, value) {
throw "Unsupported operation";
},
@ -269,6 +269,16 @@ mindplot.model.INodeModel = new Class({
inspect : function() {
return '(type:' + this.getType() + ' , id: ' + this.getId() + ')';
},
copyTo : function(target) {
var source = this;
var keys = source.getPropertiesKeys();
keys.forEach(function(key) {
var value = source.getProperty(key);
target.putProperty(value);
});
return target;
}
});

View File

@ -28,6 +28,10 @@ mindplot.model.Mindmap = new Class({
return this._description;
},
setDescription : function(value) {
this._description = value;
},
getId : function() {
return this._iconType;
},
@ -58,7 +62,7 @@ mindplot.model.Mindmap = new Class({
this._branches.push(nodeModel);
},
removeBranch : function(nodeModel){
removeBranch : function(nodeModel) {
$assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects');
return this._branches.erase(nodeModel);
},

View File

@ -40,6 +40,12 @@ mindplot.model.NodeModel = new Class({
this._properties[key] = value;
},
getProperties: function()
{
return this._properties;
},
getProperty : function(key) {
$defined(key, 'key can not be null');
var result = this._properties[key];

View File

@ -5,7 +5,7 @@
<!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<![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 -->
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
<title>WiseMapping - Editor </title>
@ -33,13 +33,12 @@
//Google-Brix framework load callback function
collabOnLoad = function() {
isGoogleBrix = true;
$(document).fireEvent('loadcomplete', 'brix');
};
var brixReady = false;
var mindReady = false;
var local = true;
var local = false;
$(document).addEvent('loadcomplete', function(resource) {
brixReady = resource == 'brix' ? true : brixReady;
mindReady = resource == 'mind' ? true : mindReady;
@ -53,10 +52,9 @@
mindplot.collaboration.framework.brix.BrixFramework.init(function() {
var manager = mindplot.collaboration.CollaborationManager.getInstance();
if (manager.isCollaborativeFrameworkReady()) {
var mindmap = manager.buildWiseModel();
designer.loadMap(mindmap);
}
var mindmap = manager.buildMindmap();
designer.loadMap(mindmap);
// If not problem has arisen, close the dialog ...
if (!window.hasUnexpectedErrors) {
waitDialog.deactivate();