aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dijit/tests/test_Tree.html
blob: fc88fc1aa911184ecf52597e4630bfda74ddf1d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Dijit Tree Test</title>

	<style type="text/css">
		@import "../../dojo/resources/dojo.css";
		@import "css/dijitTests.css";
	</style>

	<script type="text/javascript" src="../../dojo/dojo.js"
		djConfig="parseOnLoad: true, isDebug: true"></script>
	<script type="text/javascript" src="_testCommon.js"></script>

	<script language="JavaScript" type="text/javascript">
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.require("dijit.Tree");
		dojo.require("dijit.ColorPalette");
		dojo.require("dijit.Menu");
		dojo.require("dojo.parser");	// scan page for widgets and instantiate them
	</script>

</head>
<body>

	<h1 class="testTitle">Dijit Tree Test</h1>

	<div dojoType="dojo.data.ItemFileReadStore" jsId="continentStore"
		url="_data/countries.json"></div>
	<div dojoType="dijit.tree.ForestStoreModel" jsId="continentModel" 
		store="continentStore" query="{type:'continent'}"
		rootId="continentRoot" rootLabel="Continents" childrenAttrs="children"></div>

	<h3>Tree with hardcoded root node (not corresponding to any item in the store)</h3>
	<p>Clicking a folder node will open/close it (openOnclick==true), and clicking a leaf node will popup an alert.</p>
	<div dojoType="dijit.Tree" id="mytree"
		model="continentModel" openOnClick="true">
		<script type="dojo/method" event="onClick" args="item">
			alert("Execute of node " + continentStore.getLabel(item)
				+", population=" + continentStore.getValue(item, "population"));
		</script>
	</div>

	<button onclick="dijit.byId('mytree').destroyRecursive();">destroy</button>

	<h2>A rootless tree (no "continents" node) with context menus, and custom icons</h2>

	<ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">
		<li dojoType="dijit.MenuItem" onClick="alert('Hello world');">Enabled Item</li>
		<li dojoType="dijit.MenuItem" disabled="true">Disabled Item</li>
		<li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCut"
			onClick="alert('not actually cutting anything, just a test!')">Cut</li>
		<li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCopy"
			onClick="alert('not actually copying anything, just a test!')">Copy</li>
		<li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconPaste"
			onClick="alert('not actually pasting anything, just a test!')">Paste</li>
		<li dojoType="dijit.PopupMenuItem">
			<span>Enabled Submenu</span>
			<ul dojoType="dijit.Menu" id="submenu2">
				<li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
				<li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
				<li dojoType="dijit.PopupMenuItem">
					<span>Deeper Submenu</span>
					<ul dojoType="dijit.Menu" id="submenu4">
						<li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 1!')">Sub-sub-menu Item One</li>
						<li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 2!')">Sub-sub-menu Item Two</li>
					</ul>
				</li>
			</ul>
		</li>
		<li dojoType="dijit.PopupMenuItem" disabled="true">
			<span>Disabled Submenu</span>
			<ul dojoType="dijit.Menu" id="submenu3" style="display: none;">
				<li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
				<li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
			</ul>
		</li>
	</ul>

	<div dojoType="dijit.Tree" id="tree2"
		model="continentModel" showRoot="false" openOnClick="true">

		<script type="dojo/connect">
			var menu = dijit.byId("tree_menu");
			// when we right-click anywhere on the tree, make sure we open the menu
			menu.bindDomNode(this.domNode);

			dojo.connect(menu, "_openMyself", this, function(e){
				// get a hold of, and log out, the tree node that was the source of this open event
				var tn = dijit.getEnclosingWidget(e.target);
				console.debug(tn);

				// now inspect the data store item that backs the tree node:
				console.debug(tn.item);

				// contrived condition: if this tree node doesn't have any children, disable all of the menu items
				menu.getChildren().forEach(function(i){ i.setDisabled(!tn.item.children); });

				// IMPLEMENT CUSTOM MENU BEHAVIOR HERE
			});
		</script>
		<script type="dojo/method" event="getIconClass" args="item, opened">
           return (item == this.model.root || continentStore.getValue(item, "type") == "continent") ?
                   (opened ? "customFolderOpenedIcon" : "customFolderClosedIcon") :
                    "noteIcon";
		</script>
		<script type="dojo/method" event="onClick" args="item">
			alert("Execute of node " + this.model.getLabel(item)
				+", population=" + continentStore.getValue(item, "population"));
		</script>
</div>

</body>
</html>