Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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>Layout Demo</title>
6
 
7
 
8
	<script type="text/javascript" src="../../../dojo/dojo.js"
9
		djConfig="isDebug: true, parseOnLoad: true"></script>
10
	<script type="text/javascript" src="../_testCommon.js"></script>
11
 
12
	<script type="text/javascript">
13
		dojo.require("dijit.layout.LayoutContainer");
14
		dojo.require("dijit.layout.AccordionContainer");
15
		dojo.require("dijit.layout.ContentPane");
16
		dojo.require("dijit.layout.SplitContainer");
17
		dojo.require("dijit.layout.TabContainer");
18
 
19
		// Used in doc0.html
20
	 	dojo.require("dijit.form.ComboBox");
21
	 	dojo.require("dijit.form.Button");
22
 
23
		dojo.require("dojo.parser");	// scan page for widgets and instantiate them
24
 
25
		// Simple layout container layout
26
		var simpleLayout = {
27
			widgetType: "LayoutContainer",
28
			params: { id: "rootWidget" },
29
			style: "border: 3px solid grey; width: 95%; height: 400px;",
30
			children: [
31
				{
32
					widgetType: "ContentPane",
33
					params: {id: "left", layoutAlign: "left"},
34
					style: "width: 100px; background: #ffeeff;",
35
					innerHTML: "this is the left"
36
				},
37
				{
38
					widgetType: "ContentPane",
39
					params: {id: "right", layoutAlign: "right"},
40
					style: "width: 100px; background: #ffeeff;",
41
					innerHTML: "this is the right"
42
				},
43
				{
44
					widgetType: "ContentPane",
45
					params: {id: "top", layoutAlign: "top"},
46
					style: "height: 100px; background: #eeeeee;",
47
					innerHTML: "this is the top"
48
				},
49
				{
50
					widgetType: "ContentPane",
51
					params: {id: "bottom", layoutAlign: "bottom"},
52
					style: "height: 100px; background: #eeeeee;",
53
					innerHTML: "this is the bottom"
54
				},
55
				{
56
					widgetType: "ContentPane",
57
					params: {id: "client", layoutAlign: "client"},
58
					style: "height: 100px; background: #ffffee;",
59
					innerHTML: "this is the client"
60
				}
61
			]
62
		};
63
 
64
		// split container layout
65
		var splitLayout = {
66
			widgetType: "SplitContainer",
67
			params: {id: "rootWidget", orientation: "horizontal"},
68
			style: "border: 3px solid grey; width: 95%; height: 400px;",
69
			children: [
70
				{
71
					widgetType: "ContentPane",
72
					params: {id: "left"},
73
					style: "background: #ffeeff;",
74
					innerHTML: "left pane of split container"
75
				},
76
				{
77
					widgetType: "SplitContainer",
78
					params: {
79
						id: "nested", orientation: "vertical"},
80
					children: [
81
						{
82
							widgetType: "ContentPane",
83
							params: {id: "top"},
84
							style: "background: #eeffee;",
85
							innerHTML: "center-top pane of nested split container"
86
						},
87
						{
88
							widgetType: "ContentPane",
89
							params: {id: "bottom"},
90
							style: "background: #eeffee;",
91
							innerHTML: "center-bottom pane of nested split container"
92
						}
93
					]
94
				},
95
				{
96
					widgetType: "ContentPane",
97
					params: {id: "right"},
98
					style: "background: #ffeeff;",
99
					innerHTML: "right pane of split container"
100
				}
101
			]
102
		};
103
 
104
		// tab container layout
105
		var tabLayout = {
106
			widgetType: "TabContainer",
107
			params: {id: "rootWidget"},
108
			style: "width: 95%; height: 400px;",
109
			children: [
110
				{
111
					widgetType: "ContentPane",
112
					params: {id: "content", title: "Content tab", href: "doc0.html", executeScripts: true},
113
					style: "background: #ffeeff;"
114
				},
115
				{
116
					widgetType: "SplitContainer",
117
					params: {id: "nestedSplit", title: "Split pane tab", orientation: "vertical"},
118
					children: [
119
						{
120
							widgetType: "ContentPane",
121
							params: {id: "top"},
122
							style: "background: #eeffee;",
123
							innerHTML: "top pane of nested split container"
124
						},
125
						{
126
							widgetType: "ContentPane",
127
							params: {id: "bottom"},
128
							style: "background: #eeffee;",
129
							innerHTML: "bottom pane of nested split container"
130
						}
131
					]
132
				},
133
				{
134
					widgetType: "TabContainer",
135
					params: {id: "nestedTab", title: "Nested tabs"},
136
					children: [
137
						{
138
							widgetType: "ContentPane",
139
							params: {id: "left", title: "Nested Tab #1"},
140
							style: "background: #eeffee;",
141
							innerHTML: "tab 1 of nested tabs"
142
						},
143
						{
144
							widgetType: "ContentPane",
145
							params: {
146
								id: "right", title: "Nested Tab #2"},
147
							style: "background: #eeffee;",
148
							innerHTML: "tab 2 of nested tabs"
149
						}
150
					]
151
				}
152
			]
153
		};
154
 
155
/*
156
		// tab container layout
157
		var tabNoLayout = {
158
			widgetType: "TabContainer",
159
			params: {id: "rootWidget", doLayout: false},
160
			children: [
161
				{
162
					widgetType: "ContentPane",
163
					params: {id: "doc0", title: "Doc 0", href: "doc0.html", executeScripts: true},
164
					style: "background: #ffeeff;"
165
				},
166
				{
167
					widgetType: "ContentPane",
168
					params: {id: "doc1", title: "Doc 1", href: "doc1.html", executeScripts: true},
169
					style: "background: #eeffee;"
170
				},
171
				{
172
					widgetType: "ContentPane",
173
					params: {id: "doc2", title: "Doc 2", href: "doc2.html", executeScripts: true},
174
					style: "background: #ffffee;"
175
				}
176
			]
177
		};
178
*/
179
 
180
		// accordion container layout
181
		var accordionLayout = {
182
			widgetType: "AccordionContainer",
183
			params: {id: "rootWidget"},
184
			style: "border: 3px solid grey; width: 95%; height: 400px;",
185
			children: [
186
				{
187
					widgetType: "AccordionPane",
188
					params: {id: "one", title: "Pane #1"},
189
					style: "background: #ffeeff;",
190
					innerHTML: "first pane contents"
191
				},
192
				{
193
					widgetType: "AccordionPane",
194
					params: {id: "two", title: "Pane #2"},
195
					style: "background: #ffeeff;",
196
					innerHTML: "second pane contents"
197
				},
198
				{
199
					widgetType: "AccordionPane",
200
					params: {id: "three", title: "Pane #3"},
201
					style: "background: #ffeeff;",
202
					innerHTML: "third pane contents"
203
				}
204
			]
205
		};
206
 
207
		// Create a widget hierarchy from a JSON structure like
208
		// {widgetType: "LayoutContainer", params: { ... }, children: { ... } }
209
		function createWidgetHierarchy(widgetJson){
210
			// setup input node
211
			var node = document.createElement("div");
212
			document.body.appendChild(node);	// necessary for tab contianer ???
213
			if(widgetJson.style){
214
				node.style.cssText = widgetJson.style;
215
			}
216
			if(widgetJson.innerHTML){
217
				node.innerHTML=widgetJson.innerHTML;
218
			}
219
 
220
			// create the widget
221
			var widget = new dijit.layout[widgetJson.widgetType](widgetJson.params, node);
222
 
223
			// add its children (recursively)
224
			if(widgetJson.children){
225
				dojo.forEach(widgetJson.children,
226
					function(child){ widget.addChild(createWidgetHierarchy(child)); });
227
			}
228
			widget.startup(); //TODO: this is required now, right?
229
 
230
			return widget;
231
		}
232
 
233
		// create the widgets specified in layout and add them to widget "rootWidget"
234
		function create(layout){
235
 
236
			// erase old widget hierarchy (if it exists)
237
			var rootWidget = dijit.byId("rootWidget");
238
			if(rootWidget){
239
				rootWidget.destroyRecursive();
240
			}
241
 
242
			// create new widget
243
			rootWidget = createWidgetHierarchy(layout);
244
 
245
			// and display it
246
			var wrapper = dojo.byId("wrapper");
247
			wrapper.innerHTML="";	// just to erase the initial HTML message
248
			wrapper.appendChild(rootWidget.domNode);
249
	//		rootWidget.onResized();
250
 
251
			// make/update the menu of operations on each widget
252
			makeOperationTable();
253
		}
254
 
255
		// write out a menu of operations on each widget
256
		function makeOperationTable(){
257
			var html = "<table border=1>";
258
			dijit.registry.forEach(function(widget){
259
				html += "<tr><td>" + widget.id + "</td><td>";
260
				html += "<button onclick='removeFromParent(\"" + widget.id + "\");'> destroy </button> ";
261
				if(/Container/.test(widget.declaredClass)){
262
					html += "<button onclick='addChild(\"" + widget.id + "\");'> add a child </button> ";
263
				}
264
				html += "</td></tr>";
265
			});
266
			html += "</table>";
267
			dojo.byId("operations").innerHTML = html;
268
		}
269
 
270
		// remove a widget from it's parent and destroy it
271
		function removeFromParent(widget){
272
			widget = dijit.byId(widget);
273
			if(widget.parent){
274
				widget.parent.removeChild(widget);
275
			}
276
			widget.destroy();
277
 
278
			// reset the operation table so this widget is no longer shown
279
			makeOperationTable();
280
		}
281
 
282
		// add a child to given widget
283
		function addChild(widget){
284
			widget = dijit.byId(widget);
285
 
286
			// setup input node
287
			var node = document.createElement("div");
288
			node.style.cssText = "height: 70px; width: 150px; overflow: auto; background: #cccccc; border: dotted black 2px;";	// necessary if parent is LayoutContainer
289
			// create the widget
290
			var alignments = ["top","bottom","left","right"];
291
			var hrefs = ["doc0.html", "doc1.html", "doc2.html"];
292
			var child = new dijit.layout.ContentPane(
293
				{
294
					title: "Widget " + cnt,	// necessary if parent is tab
295
					layoutAlign: alignments[cnt%4],	// necessary if parent is LayoutContainer
296
					executeScripts: true,
297
					href: hrefs[cnt%3]
298
				},
299
				node);
300
			cnt++;
301
 
302
			if(/AccordionContainer/.test(widget.declaredClass)){
303
				var pane = new dijit.layout.AccordionPane({
304
					title: "AccordionWidget " + cnt
305
				});
306
				pane.setContent(child);
307
				child = pane;
308
			}
309
			// add it to the parent
310
			widget.addChild(child);
311
 
312
			// reset the operation table so the new widget is shown
313
			makeOperationTable();
314
		}
315
		var cnt=1;
316
 
317
		// show a widget
318
		function show(widget){
319
			widget = dijit.byId(widget);
320
			widget.show();
321
		}
322
 
323
		// hide a widget
324
		function hide(widget){
325
			widget = dijit.byId(widget);
326
			widget.hide();
327
		}
328
	</script>
329
	<style type="text/css">
330
		@import "../../../dojo/resources/dojo.css";
331
		@import "css/dijitTests.css";
332
 
333
		html, body{
334
			width: 100%;	/* make the body expand to fill the visible window */
335
			height: 100%;
336
			overflow: hidden;	/* erase window level scrollbars */
337
			padding: 0 0 0 0;
338
			margin: 0 0 0 0;
339
		}
340
		.dijitSplitPane{
341
			margin: 5px;
342
		}
343
		#rightPane {
344
			margin: 0;
345
		}
346
		#creator, #current {
347
			border: 3px solid blue;
348
			padding: 10px;
349
			margin: 10px;
350
		}
351
		#wrapper {
352
			border: 3px solid green;
353
			padding: 10px;
354
			margin: 10px;
355
		}
356
	</style>
357
</head>
358
<body>
359
	<h1>Test of layout code programmatic creation</h1>
360
	<table width="100%">
361
		<tr>
362
			<td id="creator" valign="top">
363
				<h4>Creator</h4>
364
				<p>Pressing a button will programatically add a hierarchy of widgets</p>
365
				<button onClick="create(simpleLayout);">Simple Layout</button>
366
				<button onClick="create(splitLayout);">Split Layout</button>
367
				<button onClick="create(tabLayout);">Tab Layout</button>
368
<!--				<button onClick="create(tabNoLayout);">Tab Non-Layout</button> -->
369
				<button onClick="create(accordionLayout);">Accordion Layout</button>
370
			</td>
371
			<td id="current">
372
				<h4>Current widgets</h4>
373
				This pane will let you try certain operations on each of the widgets.
374
				<div id="operations" style="height: 200px; overflow: auto;"></div>
375
			</td>
376
		</tr>
377
	</table>
378
	<hr>
379
	<div id="wrapper">
380
		When you press a button, this will be filled in with the generated widgets
381
	</div>
382
</body>
383
</html>