2150 |
mathias |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
|
2 |
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
3 |
<html>
|
|
|
4 |
<head>
|
|
|
5 |
<title>Dijit Tree Test</title>
|
|
|
6 |
|
|
|
7 |
<style someProperty="text/css">
|
|
|
8 |
@import "../../../dojo/resources/dojo.css";
|
|
|
9 |
@import "../../themes/tundra/tundra.css";
|
|
|
10 |
@import "../../themes/tundra/tundra_rtl.css";
|
|
|
11 |
@import "../css/dijitTests.css";
|
|
|
12 |
@import "../dndDefault.css";
|
|
|
13 |
@import "../../../dojo/resources/dojo.css";
|
|
|
14 |
@import "../../../dojo/resources/dnd.css";
|
|
|
15 |
@import "../../../dojo/tests/dnd/dndDefault.css";
|
|
|
16 |
</style>
|
|
|
17 |
|
|
|
18 |
<script someProperty="text/javascript" src="testBidi.js"></script>
|
|
|
19 |
|
|
|
20 |
<script someProperty="text/javascript" src="../../../dojo/dojo.js"
|
|
|
21 |
djConfig="parseOnLoad: true, isDebug: true"></script>
|
|
|
22 |
|
|
|
23 |
<script language="JavaScript" someProperty="text/javascript">
|
|
|
24 |
dojo.require("dojo.data.ItemFileWriteStore");
|
|
|
25 |
dojo.require("dijit.Tree");
|
|
|
26 |
dojo.require("dijit._tree.dndSource");
|
|
|
27 |
dojo.require("dijit.Menu");
|
|
|
28 |
dojo.require("dijit.form.Button");
|
|
|
29 |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them
|
|
|
30 |
|
|
|
31 |
dojo.require("dojo.dnd.common");
|
|
|
32 |
dojo.require("dojo.dnd.Source");
|
|
|
33 |
|
|
|
34 |
selected=[];
|
|
|
35 |
|
|
|
36 |
globalId=1000;
|
|
|
37 |
lastSelected=null;
|
|
|
38 |
|
|
|
39 |
dojo.addOnLoad(function(){
|
|
|
40 |
|
|
|
41 |
//record the selection from tree 1
|
|
|
42 |
dojo.subscribe("myTree", null, function(message){
|
|
|
43 |
if(message.event=="execute"){
|
|
|
44 |
console.log("Tree1 Select: ",dijit.byId("myTree").store.getLabel(message.item));
|
|
|
45 |
lastSelected=selected["myTree"]=message.item;
|
|
|
46 |
}
|
|
|
47 |
});
|
|
|
48 |
|
|
|
49 |
//record the selection from tree 2
|
|
|
50 |
dojo.subscribe("myTree2", null, function(message){
|
|
|
51 |
if(message.event=="execute"){
|
|
|
52 |
console.log("Tree2 Select: ",dijit.byId("myTree2").store.getLabel(message.item));
|
|
|
53 |
lastSelected=selected["myTree2"]=message.item;
|
|
|
54 |
}
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
//connect to the add button and have it add a new container to the store as necessary
|
|
|
58 |
dojo.connect(dijit.byId("addButton"), "onClick", function(){
|
|
|
59 |
var pInfo = {
|
|
|
60 |
parent: lastSelected,
|
|
|
61 |
attribute: "children"
|
|
|
62 |
};
|
|
|
63 |
|
|
|
64 |
//store.newItem({name: dojo.byId('newCat').value, id:globalId++, numberOfItems:dojo.byId('numItems').value}, pInfo);
|
|
|
65 |
catStore.newItem({name: dojo.byId('newCat').value, numberOfItems:0,id:globalId++}, pInfo);
|
|
|
66 |
});
|
|
|
67 |
|
|
|
68 |
//since we don't have a server, we're going to connect to the store and do a few things the server/store combination would normal be taking care of for us
|
|
|
69 |
dojo.connect(catStore, "onNew", function(item, pInfo){
|
|
|
70 |
var p = pInfo.item;
|
|
|
71 |
if (p) {
|
|
|
72 |
var currentTotal = catStore.getValues(p, "numberOfItems")[0];
|
|
|
73 |
catStore.setValue(p, "numberOfItems", ++currentTotal);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
});
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
tree1 = dijit.byId('myTree');
|
|
|
80 |
tree2 = dijit.byId('myTree2');
|
|
|
81 |
});
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
//create a custom label for tree one consisting of the label property pluss the value of the numberOfItems Column
|
|
|
85 |
function tree1CustomLabel(item){
|
|
|
86 |
var label = catStore.getLabel(item);
|
|
|
87 |
var num = catStore.getValues(item,"numberOfItems");
|
|
|
88 |
//return the new label
|
|
|
89 |
return label + ' (' + num+ ')';
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
//custom function to handle drop for tree two. Items dropped onto nodes here should be applied to the items attribute in this particular store.
|
|
|
94 |
function tree2CustomDrop(source,nodes,copy){
|
|
|
95 |
if (this.containerState=="Over"){
|
|
|
96 |
this.isDragging=false;
|
|
|
97 |
var target= this.current;
|
|
|
98 |
var items = this.itemCreator(nodes, target);
|
|
|
99 |
|
|
|
100 |
if (!target || target==this.tree.domNode){
|
|
|
101 |
for (var i=0; i<items.length;i++){
|
|
|
102 |
this.tree.store.newItem(items[i],null);
|
|
|
103 |
}
|
|
|
104 |
}else {
|
|
|
105 |
for (var i=0; i<items.length;i++){
|
|
|
106 |
pInfo={parent:dijit.getEnclosingWidget(target).item, attribute:"items"};
|
|
|
107 |
this.tree.store.newItem(items[i],pInfo);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
//on tree two, we only want to drop on containers, not on items in the containers
|
|
|
114 |
function tree2CheckItemAcceptance(node,source) {
|
|
|
115 |
var item = dijit.getEnclosingWidget(node).item;
|
|
|
116 |
if (item && this.tree.store.hasAttribute(item,"numberOfItems")){
|
|
|
117 |
var numItems=this.tree.store.getValues(item, "numberOfItems");
|
|
|
118 |
return true;
|
|
|
119 |
}
|
|
|
120 |
return false;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
function tree2ItemCreator(nodes){
|
|
|
124 |
var items = []
|
|
|
125 |
|
|
|
126 |
for(var i=0;i<nodes.length;i++){
|
|
|
127 |
items.push({
|
|
|
128 |
"name":nodes[i].textContent,
|
|
|
129 |
"id": nodes[i].id
|
|
|
130 |
});
|
|
|
131 |
}
|
|
|
132 |
return items;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
function dndAccept(source,nodes){
|
|
|
136 |
if (this.tree.id=="myTree"){
|
|
|
137 |
return false;
|
|
|
138 |
}
|
|
|
139 |
return true;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
function getIcon(item) {
|
|
|
143 |
if (!item || catStore.hasAttribute(item, "numberOfItems")) {
|
|
|
144 |
return "myFolder";
|
|
|
145 |
}
|
|
|
146 |
return "myItem"
|
|
|
147 |
}
|
|
|
148 |
</script>
|
|
|
149 |
|
|
|
150 |
<style>
|
|
|
151 |
.myFolder{
|
|
|
152 |
display: "block";
|
|
|
153 |
width: 16px;
|
|
|
154 |
height: 16px;
|
|
|
155 |
background: blue;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
.myItem{
|
|
|
159 |
display: "block";
|
|
|
160 |
width: 16px;
|
|
|
161 |
height: 16px;
|
|
|
162 |
background: green;
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
</style>
|
|
|
166 |
|
|
|
167 |
</head>
|
|
|
168 |
<body class="tundra">
|
|
|
169 |
<h1 class="testTitle">Dijit Tree Test - Drag And Drop Support</h1>
|
|
|
170 |
|
|
|
171 |
<div dojoType="dojo.data.ItemFileWriteStore" jsId="catStore"
|
|
|
172 |
url="../_data/categories.json"></div>
|
|
|
173 |
|
|
|
174 |
<table width="100%" style="margin:5px solid gray" >
|
|
|
175 |
|
|
|
176 |
<tr style="width:100%">
|
|
|
177 |
<td style="width: 50%">
|
|
|
178 |
<h2>Custom</h2>
|
|
|
179 |
<p>Should add this category to the store. The second parameter is the value for numberOfItems.</p>
|
|
|
180 |
<div class="container">
|
|
|
181 |
<input id="newCat" type="text" value="Pottedmeat" /><input id="numItems" type="text" value="0" size="3"/><div id="addButton" dojoType="dijit.form.Button">Add Category</div>
|
|
|
182 |
</div>
|
|
|
183 |
</td>
|
|
|
184 |
<td>
|
|
|
185 |
<h2>Items: </h2>
|
|
|
186 |
<p>List of Items to be categorized<p>
|
|
|
187 |
<div dojoType="dojo.dnd.Source" jsId="c2" class="container" style="height: 100px; overflow: auto">
|
|
|
188 |
<div class="dojoDndItem" id="1001">Apple</div>
|
|
|
189 |
<div class="dojoDndItem" id="1002">Orange</div>
|
|
|
190 |
<div class="dojoDndItem" id="1003">Banana</div>
|
|
|
191 |
<div class="dojoDndItem" id="1004">Tomato</div>
|
|
|
192 |
<div class="dojoDndItem" id="1005">Pepper</div>
|
|
|
193 |
<div class="dojoDndItem" id="1006">Wheat</div>
|
|
|
194 |
<div class="dojoDndItem" id="1007">Corn</div>
|
|
|
195 |
<div class="dojoDndItem" id="1008">Spinach</div>
|
|
|
196 |
<div class="dojoDndItem" id="1009">Cucumber</div>
|
|
|
197 |
<div class="dojoDndItem" id="1010">Carot</div>
|
|
|
198 |
<div class="dojoDndItem" id="1011">Potato</div>
|
|
|
199 |
<div class="dojoDndItem" id="1012">Grape</div>
|
|
|
200 |
<div class="dojoDndItem" id="1013">Lemon</div>
|
|
|
201 |
<div class="dojoDndItem" id="1010">Letuce</div>
|
|
|
202 |
<div class="dojoDndItem" id="1010">Peanut</div>
|
|
|
203 |
</div>
|
|
|
204 |
</td>
|
|
|
205 |
</tr>
|
|
|
206 |
<tr>
|
|
|
207 |
<td>
|
|
|
208 |
<h2>Collection Count Summary</h2>
|
|
|
209 |
<p>You can't drop items onto this tree.</p>
|
|
|
210 |
<div class="container" dojoType="dijit.Tree" id="myTree" store="catStore" label="Collections"
|
|
|
211 |
labelAttr="name" getLabel="tree1CustomLabel" childrenAttr="children" dndController="dijit._tree.dndSource"
|
|
|
212 |
checkAcceptance="dndAccept" getIconClass="getIcon"></div>
|
|
|
213 |
</td>
|
|
|
214 |
<td>
|
|
|
215 |
<h2>Collection</h2>
|
|
|
216 |
<p>Drop items onto this tree, but only on categories, should fail to let you drop on other items.</p>
|
|
|
217 |
<div class="container" dojoType="dijit.Tree" id="myTree2" label="Collections" store="catStore" labelAttr="name" childrenAttr="children, items" dndController="dijit._tree.dndSource" onDndDrop="tree2CustomDrop" checkAcceptance="dndAccept" checkItemAcceptance="tree2CheckItemAcceptance" getIconClass="getIcon"></div>
|
|
|
218 |
</td>
|
|
|
219 |
</tr>
|
|
|
220 |
</table>
|
|
|
221 |
|
|
|
222 |
</body>
|
|
|
223 |
</html>
|