]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/tests/test_Tree.html
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / tests / test_Tree.html
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 type="text/css">
8                 @import "../../dojo/resources/dojo.css";
9                 @import "css/dijitTests.css";
10         </style>
11
12         <script type="text/javascript" src="../../dojo/dojo.js"
13                 djConfig="parseOnLoad: true, isDebug: true"></script>
14         <script type="text/javascript" src="_testCommon.js"></script>
15
16         <script language="JavaScript" type="text/javascript">
17                 dojo.require("dojo.data.ItemFileReadStore");
18                 dojo.require("dijit.Tree");
19                 dojo.require("dijit.ColorPalette");
20                 dojo.require("dijit.Menu");
21                 dojo.require("dojo.parser");    // scan page for widgets and instantiate them
22         </script>
23
24 </head>
25 <body>
26
27         <h1 class="testTitle">Dijit Tree Test</h1>
28
29         <div dojoType="dojo.data.ItemFileReadStore" jsId="continentStore"
30                 url="_data/countries.json"></div>
31         <div dojoType="dijit.tree.ForestStoreModel" jsId="continentModel" 
32                 store="continentStore" query="{type:'continent'}"
33                 rootId="continentRoot" rootLabel="Continents" childrenAttrs="children"></div>
34
35         <h3>Tree with hardcoded root node (not corresponding to any item in the store)</h3>
36         <p>Clicking a folder node will open/close it (openOnclick==true), and clicking a leaf node will popup an alert.</p>
37         <div dojoType="dijit.Tree" id="mytree"
38                 model="continentModel" openOnClick="true">
39                 <script type="dojo/method" event="onClick" args="item">
40                         alert("Execute of node " + continentStore.getLabel(item)
41                                 +", population=" + continentStore.getValue(item, "population"));
42                 </script>
43         </div>
44
45         <button onclick="dijit.byId('mytree').destroyRecursive();">destroy</button>
46
47         <h2>A rootless tree (no "continents" node) with context menus, and custom icons</h2>
48
49         <ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">
50                 <li dojoType="dijit.MenuItem" onClick="alert('Hello world');">Enabled Item</li>
51                 <li dojoType="dijit.MenuItem" disabled="true">Disabled Item</li>
52                 <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCut"
53                         onClick="alert('not actually cutting anything, just a test!')">Cut</li>
54                 <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCopy"
55                         onClick="alert('not actually copying anything, just a test!')">Copy</li>
56                 <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconPaste"
57                         onClick="alert('not actually pasting anything, just a test!')">Paste</li>
58                 <li dojoType="dijit.PopupMenuItem">
59                         <span>Enabled Submenu</span>
60                         <ul dojoType="dijit.Menu" id="submenu2">
61                                 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
62                                 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
63                                 <li dojoType="dijit.PopupMenuItem">
64                                         <span>Deeper Submenu</span>
65                                         <ul dojoType="dijit.Menu" id="submenu4">
66                                                 <li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 1!')">Sub-sub-menu Item One</li>
67                                                 <li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 2!')">Sub-sub-menu Item Two</li>
68                                         </ul>
69                                 </li>
70                         </ul>
71                 </li>
72                 <li dojoType="dijit.PopupMenuItem" disabled="true">
73                         <span>Disabled Submenu</span>
74                         <ul dojoType="dijit.Menu" id="submenu3" style="display: none;">
75                                 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
76                                 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
77                         </ul>
78                 </li>
79         </ul>
80
81         <div dojoType="dijit.Tree" id="tree2"
82                 model="continentModel" showRoot="false" openOnClick="true">
83
84                 <script type="dojo/connect">
85                         var menu = dijit.byId("tree_menu");
86                         // when we right-click anywhere on the tree, make sure we open the menu
87                         menu.bindDomNode(this.domNode);
88
89                         dojo.connect(menu, "_openMyself", this, function(e){
90                                 // get a hold of, and log out, the tree node that was the source of this open event
91                                 var tn = dijit.getEnclosingWidget(e.target);
92                                 console.debug(tn);
93
94                                 // now inspect the data store item that backs the tree node:
95                                 console.debug(tn.item);
96
97                                 // contrived condition: if this tree node doesn't have any children, disable all of the menu items
98                                 menu.getChildren().forEach(function(i){ i.setDisabled(!tn.item.children); });
99
100                                 // IMPLEMENT CUSTOM MENU BEHAVIOR HERE
101                         });
102                 </script>
103                 <script type="dojo/method" event="getIconClass" args="item, opened">
104            return (item == this.model.root || continentStore.getValue(item, "type") == "continent") ?
105                    (opened ? "customFolderOpenedIcon" : "customFolderClosedIcon") :
106                     "noteIcon";
107                 </script>
108                 <script type="dojo/method" event="onClick" args="item">
109                         alert("Execute of node " + this.model.getLabel(item)
110                                 +", population=" + continentStore.getValue(item, "population"));
111                 </script>
112 </div>
113
114 </body>
115 </html>