Add remove node support.

This commit is contained in:
Paulo Veiga 2011-09-11 00:07:43 -03:00
parent c1e0d52ff5
commit 5a08728686
11 changed files with 69 additions and 149 deletions

View File

@ -52,11 +52,11 @@
<concat destfile="${basedir}/target/tmp/mindplot.js" append="false"> <concat destfile="${basedir}/target/tmp/mindplot.js" append="false">
<filelist dir="${basedir}/src/main/javascript/" files="header.js"/> <filelist dir="${basedir}/src/main/javascript/" files="header.js"/>
<filelist dir="${basedir}/src/main/javascript/libraries/" <filelist dir="${basedir}/src/main/javascript/libraries/moodialog/"
files="Overlay.js"/> files="Overlay.js"/>
<filelist dir="${basedir}/src/main/javascript/libraries/" <filelist dir="${basedir}/src/main/javascript/libraries/moodialog/"
files="MooDialog.js"/> files="MooDialog.js"/>
<filelist dir="${basedir}/src/main/javascript/libraries/" <filelist dir="${basedir}/src/main/javascript/libraries/moodialog/"
files="MooDialog.Fx.js"/> files="MooDialog.Fx.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="EventBus.js"/> <filelist dir="${basedir}/src/main/javascript/" files="EventBus.js"/>

View File

@ -26,6 +26,7 @@ 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 = 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

@ -71,7 +71,12 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
addBranch : function(nodeModel) { addBranch : function(nodeModel) {
$assert(nodeModel, "nodeModel can not be null"); $assert(nodeModel, "nodeModel can not be null");
var branches = this._brixModel.get("branches"); var branches = this._brixModel.get("branches");
branches.add(nodeModel.getBrixModel());
// @Todo: Hack ?
var newModel = mindplot.collaboration.framework.brix.model.NodeModel.create(this._brixFramework, this, nodeModel.getType(), nodeModel.getId());
nodeModel.copyTo(newModel);
branches.add(newModel);
}, },
removeBranch : function(nodeModel) { removeBranch : function(nodeModel) {

View File

@ -63,17 +63,19 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
}.bind(this)); }.bind(this));
children.addListener("valuesRemoved", function(event) { children.addListener("valuesRemoved", function(event) {
console.log("remove node:" + funName); try {
var brixChildren = event.getValues(); var brixChildren = event.getValues();
for (var i = 0; i < brixChildren.size(); i++) { for (var i = 0; i < brixChildren.size(); i++) {
var brixNodeModel = brixChildren.get(i); var brixNodeModel = brixChildren.get(i);
var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, brixNodeModel, this.getMindmap()); var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, brixNodeModel, this.getMindmap());
actionDispatcher.deleteTopics(cmodel.getId()); actionDispatcher.deleteTopics([cmodel.getId()]);
}
} catch(e) {
console.trace();
console.log(e);
} }
}.bind(this)); }.bind(this));
this._brixModel.__registered = true; this._brixModel.__registered = true;
} }
}, },
@ -106,7 +108,7 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
}, },
getPropertiesKeys : function() { getPropertiesKeys : function() {
return this._brixModel.getKeys(); return this._brixModel.getKeys().erase('children');
}, },
getParent : function() { getParent : function() {

View File

@ -225,23 +225,16 @@ mindplot.model.INodeModel = new Class({
deleteNode : function() { deleteNode : function() {
var mindmap = this.getMindmap(); var mindmap = this.getMindmap();
// if it has children nodes, Their must be disconnected. console.log(mindmap.inspect());
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(); var parent = this.getParent();
if ($defined(parent)) { if ($defined(parent)) {
mindmap.disconnect(this); parent.removeChild(this);
} } else {
// If it has not parent, it must be an isolate topic ...
// It's an isolated node. It must be a hole branch ...
mindmap.removeBranch(this); mindmap.removeBranch(this);
}
// It's an isolated node. It must be a hole branch ...
console.log(mindmap.inspect());
}, },
getPropertiesKeys : function() { getPropertiesKeys : function() {
@ -325,7 +318,13 @@ mindplot.model.INodeModel = new Class({
if (children.length > 0) { if (children.length > 0) {
result = result + ", children: {(size:" + children.length; result = result + ", children: {(size:" + children.length;
children.forEach(function(node) { children.forEach(function(node) {
result = result + "=> (" + node.getPropertiesKeys() + ")"; result = result + "=> (";
var keys = node.getPropertiesKeys();
keys.forEach(function(key) {
var value = node.getProperty(key);
result = result + key + ":" + value + ",";
});
result = result + "}"
}.bind(this)); }.bind(this));
} }

View File

@ -59,7 +59,7 @@ mindplot.model.NodeModel = new Class({
return cnode; return cnode;
}); });
result._properties = this._properties.clone(); result._properties = Object.clone(this._properties);
result._icons = this._icons.clone(); result._icons = this._icons.clone();
result._links = this._links.clone(); result._links = this._links.clone();
result._notes = this._notes.clone(); result._notes = this._notes.clone();

View File

@ -8,40 +8,41 @@
app.addListener('modelLoad', function(model) { app.addListener('modelLoad', function(model) {
var root = app.getModel().getRoot(); var root = app.getModel().getRoot();
if (!root.get("mindmap7")) { var myList = root.get("myList");
if (!myList) {
console.log("Creating empty map ..."); myList = app.getModel().create("List");
root.put("myList", myList);
// var topics = app.getModel().create("List");
root.put("mindmap7", "start_");
} }
root.addListener('valueChanged', function(e) { myList.addListener('valuesAdded', function(event) {
console.log("New item added ...:"); console.log("value added:" + myList.size());
console.log(app.getModel().getRoot().get("mindmap7"));
}); });
myList.addListener('valuesRemoved', function(event) {
console.log("value removed:" + myList.size());
}); });
});
removedAction = function() {
var root = app.getModel().getRoot();
var myList = root.get("myList");
myList.remove(myList.size() - 1);
}; };
function addTopic() { addAction = function() {
console.log("Adding new item ver:2 ...");
var root = app.getModel().getRoot(); var root = app.getModel().getRoot();
var topics = root.get("mindmap7"); var myList = root.get("myList");
myList.add("Some elem " + myList.size());
// var topic = app.getModel().create("Map"); console.log("Click on adding...");
// topic.put("id", "topic_x"); };
// topic.put("text", "topic X text"); };
// topics.add(topic);
// root.put("mindmap7", topics);
root.put("mindmap7", app.getModel().getRoot().get("mindmap7") + "_algo");
}
</script> </script>
Este es este no ? Funca?
<input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="a2" onclick="addTopic(this)"/>
<input style="font-size:20px;width:50px;height:50px;" type="button" value="Add" id="a2" onclick="addAction(this)"/>
<input style="font-size:20px;width:50px;height:50px;" type="button" value="Remove" id="a2"
onclick="removedAction(this)"/>
</body> </body>
</html> </html>

View File

@ -11,18 +11,12 @@
<title>WiseMapping - Editor </title> <title>WiseMapping - Editor </title>
<link rel="stylesheet" type="text/css" href="../css/editor.css"/> <link rel="stylesheet" type="text/css" href="../css/editor.css"/>
<link rel="stylesheet" type="text/css" href='/mindplot/src/main/javascript/libraries/moodialog/css/MooDialog.css'/> <link rel="stylesheet" type="text/css" href='/mindplot/src/main/javascript/libraries/moodialog/css/MooDialog.css'/>
<!--<script type='text/javascript' src='../js/wiseLibrary.js'></script>-->
<script type='text/javascript' <script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/mootools/1.3.2/mootools-yui-compressed.js'></script> src='https://ajax.googleapis.com/ajax/libs/mootools/1.3.2/mootools-yui-compressed.js'></script>
<script type='text/javascript' src='../js/mootools-more-1.3.2.1-yui.js'></script> <script type='text/javascript' src='../js/mootools-more-1.3.2.1-yui.js'></script>
<!--<script type='text/javascript' src='../js/common.js'></script>-->
<!--<script type='text/javascript' src='../js/wiseEditorLibrary.js'></script>-->
<script type='text/javascript' src='/core-js/target/classes/core.js'></script> <script type='text/javascript' src='/core-js/target/classes/core.js'></script>
<!--<script type='text/javascript' src='js/core-min.js'></script>-->
<script type="text/javascript"> <script type="text/javascript">

View File

@ -1,4 +1,4 @@
<!DOCTYPE HTML> !DOCTYPE HTML>
<html> <html>
<head> <head>
@ -22,8 +22,6 @@
} }
}; };
$("someId").addEvent("click", function(event) { $("someId").addEvent("click", function(event) {
$("someId").fireEvent("wiseNodeAdded",null) $("someId").fireEvent("wiseNodeAdded",null)
}); });

View File

@ -1,80 +0,0 @@
<html>
<body>
<script type="text/javascript" src="http://docs.google.com/brix/static/api/js/jsapi.nocache.js"></script>
<script type="text/javascript">
var app;
collabOnLoad = function() {
app = new goog.collab.CollaborativeApp();
app.start();
app.addListener('modelLoad', function(model) {
var root = app.getModel().getRoot();
if (root.isEmpty()) {
root.put("a1", ' ');
root.put("a2", " ");
root.put("a3", " ");
root.put("b1", " ");
root.put("b2", " ");
root.put("b3", " ");
root.put("c1", " ");
root.put("c2", " ");
root.put("c3", " ");
root.put("turn", "X");
}
var list1 = app.getModel().create("List");
root.put("list",list1);
document.getElementById("a1").value = root.get("a1");
document.getElementById("a2").value = root.get("a2");
document.getElementById("a3").value = root.get("a3");
document.getElementById("b1").value = root.get("b1");
document.getElementById("b2").value = root.get("b2");
document.getElementById("b3").value = root.get("b3");
document.getElementById("c1").value = root.get("c1");
document.getElementById("c2").value = root.get("c2");
document.getElementById("c3").value = root.get("c3");
relabelTurn(root.get("turn"));
root.addListener('valueChanged', function(e) {
document.getElementById(e.getProperty()).value = e.getNewValue();
relabelTurn(root.get("turn"));
});
});
};
function move(square) {
app.getModel().getRoot().put(square.id, app.getModel().getRoot().get("turn"));
var turn = app.getModel().getRoot().get("turn") == "X" ? "O" : "X";
app.getModel().getRoot().put("turn", turn);
relabelTurn(app.getModel().getRoot().get("turn"));
app.getModel().getRoot().get("list").add(turn);
}
function relabelTurn(turn) {
document.getElementById("turn").innerHTML = "Next move is: " + turn;
}
</script>
<p>
TIC TAC TOE!
<p>
<span id=turn></span>
<table>
<tr>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="a1" onclick="move(this)"></td>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="b1" onclick="move(this)"></td>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="c1" onclick="move(this)"></td>
</tr>
<tr>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="a2" onclick="move(this)"></td>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="b2" onclick="move(this)"></td>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="c2" onclick="move(this)"></td>
</tr>
<tr>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="a3" onclick="move(this)"></td>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="b3" onclick="move(this)"></td>
<td><input style="font-size:20px;width:50px;height:50px;" type="button" value=" " id="c3" onclick="move(this)"></td>
</tr>
</table>
</body>
</html>

View File

@ -237,7 +237,7 @@ if (localEnv) {
} }
}); });
} else { } else {
Asset.javascript("../js/mindplot.svg.js", { Asset.javascript("../js/mindplot-min.js", {
onLoad:function() { onLoad:function() {
$(document).fireEvent('loadcomplete', 'mind') $(document).fireEvent('loadcomplete', 'mind')
} }