1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
5 <title>Dijit Tree Test</title>
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";
18 <script someProperty="text/javascript" src="testBidi.js"></script>
20 <script someProperty="text/javascript" src="../../../dojo/dojo.js"
21 djConfig="parseOnLoad: true, isDebug: true"></script>
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
31 dojo.require("dojo.dnd.common");
32 dojo.require("dojo.dnd.Source");
39 dojo.addOnLoad(function(){
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;
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;
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(){
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);
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 && pInfo.item;
72 var currentTotal = catStore.getValues(p, "numberOfItems")[0];
73 catStore.setValue(p, "numberOfItems", ++currentTotal);
80 //create a custom label for tree one consisting of the label property pluss the value of the numberOfItems Column
81 function catTreeCustomLabel(item){
82 var label = catStore.getLabel(item);
83 var num = catStore.hasAttribute(item, "numberOfItems") ? catStore.getValues(item,"numberOfItems") : "?";
84 return label + ' (' + num+ ')';
87 //on item tree , we only want to drop on containers, or the root node itself, not on items in the containers
88 function itemTreeCheckItemAcceptance(node,source) {
89 var item = dijit.getEnclosingWidget(node).item;
90 if (item && (item.root || catStore.hasAttribute(item,"numberOfItems"))){
96 function dndAccept(source,nodes){
97 if (this.tree.id=="myTree"){
103 function getIcon(item) {
104 if (!item || catStore.hasAttribute(item, "numberOfItems")) {
129 <body class="tundra">
130 <h1 class="testTitle">Dijit Tree Test - Drag And Drop Support</h1>
132 <div dojoType="dojo.data.ItemFileWriteStore" jsId="catStore"
133 url="../_data/categories.json"></div>
135 <table width="100%" style="margin:5px solid gray" >
137 <tr style="width:100%">
138 <td style="width: 50%">
140 <p>Should add this category to the store. The second parameter is the value for numberOfItems.</p>
141 <div class="container">
142 <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>
147 <p>List of Items to be categorized<p>
148 <div dojoType="dojo.dnd.Source" jsId="c2" class="container" style="height: 100px; overflow: auto">
149 <div class="dojoDndItem" id="1001">Apple</div>
150 <div class="dojoDndItem" id="1002">Orange</div>
151 <div class="dojoDndItem" id="1003">Banana</div>
152 <div class="dojoDndItem" id="1004">Tomato</div>
153 <div class="dojoDndItem" id="1005">Pepper</div>
154 <div class="dojoDndItem" id="1006">Wheat</div>
155 <div class="dojoDndItem" id="1007">Corn</div>
156 <div class="dojoDndItem" id="1008">Spinach</div>
157 <div class="dojoDndItem" id="1009">Cucumber</div>
158 <div class="dojoDndItem" id="1010">Carrot</div>
159 <div class="dojoDndItem" id="1011">Potato</div>
160 <div class="dojoDndItem" id="1012">Grape</div>
161 <div class="dojoDndItem" id="1013">Lemon</div>
162 <div class="dojoDndItem" id="1010">Lettuce</div>
163 <div class="dojoDndItem" id="1010">Peanut</div>
169 <h2>Collection Count Summary</h2>
170 <p>You can't drop items onto this tree.</p>
171 <div dojoType="dijit.tree.TreeStoreModel" jsId="catModel"
172 store="catStore" query="{id: '0'}"></div>
173 <div class="container" dojoType="dijit.Tree" id="collectionsTree" model="catModel"
174 getLabel="catTreeCustomLabel" dndController="dijit._tree.dndSource"
175 checkAcceptance="dndAccept" getIconClass="getIcon"></div>
180 Drop items onto this tree, but only onto categories; should fail to let you drop on other items.
181 Can also move items within this tree.
183 <div dojoType="dijit.tree.TreeStoreModel" jsId="itemModel"
184 store="catStore" query="{id: '0'}" childrenAttrs="items, children"></div>
185 <div class="container" dojoType="dijit.Tree" id="itemTree"
187 dndController="dijit._tree.dndSource" checkAcceptance="dndAccept" checkItemAcceptance="itemTreeCheckItemAcceptance"
188 getIconClass="getIcon"></div>