1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.TreeDemo");
|
|
|
14 |
dojo.require("dojo.Deferred");
|
|
|
15 |
dojo.widget.TreeDemo = {reportIfDefered:function (res) {
|
|
|
16 |
if (res instanceof dojo.Deferred) {
|
|
|
17 |
res.addCallbacks(function (res) {
|
|
|
18 |
return res;
|
|
|
19 |
}, function (err) {
|
|
|
20 |
dojo.debug("Error");
|
|
|
21 |
dojo.debugShallow(err);
|
|
|
22 |
});
|
|
|
23 |
}
|
|
|
24 |
}, resetRandomChildren:function (maxCount) {
|
|
|
25 |
this.randomChildrenMaxCount = maxCount;
|
|
|
26 |
this.randomChildrenCount = 0;
|
|
|
27 |
this.randomChildrenDepth = 0;
|
|
|
28 |
}, makeRandomChildren:function (title) {
|
|
|
29 |
this.randomChildrenDepth++;
|
|
|
30 |
var children = [];
|
|
|
31 |
for (var i = 1; i <= 5; i++) {
|
|
|
32 |
var t = title + (this.randomChildrenDepth == 1 ? "" : ".") + i;
|
|
|
33 |
var node = {title:t};
|
|
|
34 |
children.push(node);
|
|
|
35 |
this.randomChildrenCount++;
|
|
|
36 |
if (this.randomChildrenCount >= this.randomChildrenMaxCount) {
|
|
|
37 |
break;
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
var i = 1;
|
|
|
41 |
var _this = this;
|
|
|
42 |
dojo.lang.forEach(children, function (child) {
|
|
|
43 |
var t = title + (_this.randomChildrenDepth == 1 ? "" : ".") + i;
|
|
|
44 |
i++;
|
|
|
45 |
if (_this.randomChildrenCount < _this.randomChildrenMaxCount && (_this.randomChildrenDepth == 1 && child === children[0] || _this.randomChildrenDepth < 5 && Math.random() > 0.3)) {
|
|
|
46 |
child.children = _this.makeRandomChildren(t);
|
|
|
47 |
}
|
|
|
48 |
});
|
|
|
49 |
this.randomChildrenDepth--;
|
|
|
50 |
return children;
|
|
|
51 |
}, bindDemoMenu:function (controller) {
|
|
|
52 |
var _t = this;
|
|
|
53 |
dojo.event.topic.subscribe("treeContextMenuDestroy/engage", function (menuItem) {
|
|
|
54 |
var node = menuItem.getTreeNode();
|
|
|
55 |
_t.reportIfDefered(controller.destroyChild(node));
|
|
|
56 |
});
|
|
|
57 |
dojo.event.topic.subscribe("treeContextMenuRefresh/engage", function (menuItem) {
|
|
|
58 |
var node = menuItem.getTreeNode();
|
|
|
59 |
_t.reportIfDefered(controller.refreshChildren(node));
|
|
|
60 |
});
|
|
|
61 |
dojo.event.topic.subscribe("treeContextMenuCreate/engage", function (menuItem) {
|
|
|
62 |
var node = menuItem.getTreeNode();
|
|
|
63 |
var d = controller.createAndEdit(node, 0);
|
|
|
64 |
_t.reportIfDefered(d);
|
|
|
65 |
});
|
|
|
66 |
dojo.event.topic.subscribe("treeContextMenuUp/engage", function (menuItem) {
|
|
|
67 |
var node = menuItem.getTreeNode();
|
|
|
68 |
if (node.isFirstChild()) {
|
|
|
69 |
return;
|
|
|
70 |
}
|
|
|
71 |
_t.reportIfDefered(controller.move(node, node.parent, node.getParentIndex() - 1));
|
|
|
72 |
});
|
|
|
73 |
dojo.event.topic.subscribe("treeContextMenuDown/engage", function (menuItem) {
|
|
|
74 |
var node = menuItem.getTreeNode();
|
|
|
75 |
if (node.isLastChild()) {
|
|
|
76 |
return;
|
|
|
77 |
}
|
|
|
78 |
_t.reportIfDefered(controller.move(node, node.parent, node.getParentIndex() + 1));
|
|
|
79 |
});
|
|
|
80 |
dojo.event.topic.subscribe("treeContextMenuEdit/engage", function (menuItem) {
|
|
|
81 |
var node = menuItem.getTreeNode();
|
|
|
82 |
_t.reportIfDefered(controller.editLabelStart(node));
|
|
|
83 |
});
|
|
|
84 |
}};
|
|
|
85 |
|