Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
<!--
2
  This file demonstrates how the dojox.wire code can be used to do declarative
3
  wiring of events on one item to trigger event on other widgets.  It also shows
4
  how you can use the Transfer object to morph data values from one format to
5
  another.  In this specific case, it maps the values from a dojo.data Datastore
6
  item into values stored in a JavaScript Array, which is the format required for
7
  the addRow method of the demonstration TableContainer.
8
 
9
  Note that this demo expects dojo, digit, and dojox to all be peers in the same directory
10
  in order for it to execute.
11
-->
12
<html>
13
<head>
14
	<title>Sample declarative data binding</title>
15
	<style type="text/css">
16
 
17
		@import "../../../../dijit/themes/tundra/tundra.css";
18
		@import "../../../../dojo/resources/dojo.css";
19
		@import "../../../../dijit/tests/css/dijitTests.css";
20
		@import "../TableContainer.css";
21
 
22
		.splitView {
23
			width: 90%;
24
			height: 90%;
25
			border: 1px solid #bfbfbf;
26
			border-collapse: separate;
27
		}
28
	</style>
29
 
30
	<script type="text/javascript" src="../../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
31
	<script type="text/javascript">
32
		dojo.require("dojo.parser");
33
		dojo.require("dojox.wire.ml.Invocation");
34
		dojo.require("dojox.wire.ml.DataStore");
35
		dojo.require("dojox.wire.ml.Transfer");
36
 
37
		dojo.require("dijit.layout.SplitContainer");
38
		dojo.require("dijit.layout.LayoutContainer");
39
		dojo.require("dijit.layout.ContentPane");
40
		dojo.require("dijit.form.Button");
41
		dojo.require("dijit.form.TextBox");
42
 
43
		dojo.require("dojo.data.ItemFileReadStore");
44
		dojo.require("dojox.wire");
45
		dojo.require("dojox.wire.demos.TableContainer");
46
 
47
		//Toplevel JS Object to contain a few basics for us, such as the request to pass to the store and a stub onItem function
48
		// to trap on for triggering other events.
49
		dataHolder = {
50
			//Simple object definition to get all items and sort it by the attribute 'type'.
51
			request: {query: {name: "*"}, onItem: function(item, req){}, sort: [{attribute: "type"}]},
52
			//Spot to store off data values as they're generated by the declarative binding.
53
			result: null
54
		};
55
 
56
	</script>
57
</head>
58
 
59
<body class="tundra">
60
 
61
	<!-- The following is the basic layout.  A split container with a button and a text field.  Data will be displayed on the right. -->
62
	<div dojoType="dijit.layout.SplitContainer"
63
		orientation="horizontal"
64
		sizerWidth="7"
65
		activeSizing="true"
66
		class="splitView">
67
		<div dojoType="dijit.layout.ContentPane" sizeMin="50" sizeShare="50">
68
			<font size="3"><b>Demo Searcher (Searches on Attribute 'name'):</b></font><br/><br/>
69
			<b>Usage:</b><br/>
70
			Enter the name you want to search the store for.  Wildcards * (multiple character), and ? (single character), are allowed.
71
			<br/>
72
			<br/>
73
			<table style="width: 90%;">
74
				<tr>
75
					<td align="left">
76
						<div dojoType="dijit.form.Button" jsId="searchButton">Search Datastore</div>
77
					</td>
78
					<td align="right">
79
						<div dojoType="dijit.form.TextBox" jsId="inputField" value="*"></div>
80
					</td>
81
				</tr>
82
			</table>
83
		</div>
84
		<div dojoType="dijit.layout.ContentPane" sizeMin="50" sizeShare="50">
85
			<div class="dataTable" dojoType="dojox.wire.demos.TableContainer" jsId="dataTable" headers="Name,Location Type"></div>
86
		</div>
87
	</div>
88
 
89
 
90
	<!-------------------------------- Using dojox.wire, declaratively wire up the widgets. --------------------------->
91
 
92
	<!-- The store that is queried in this demo -->
93
	<div dojoType="dojo.data.ItemFileReadStore"
94
		jsId="DataStore1"
95
		url="countries.json">
96
	</div>
97
 
98
	<!--
99
		When the search button is clicked, clear existing rows from table,
100
		Then invoke the fetch to repopulate the table.
101
	-->
102
	<div dojoType="dojox.wire.ml.Action"
103
		trigger="searchButton"
104
		triggerEvent="onClick">
105
		<div dojoType="dojox.wire.ml.Invocation" object="dataTable"  method="clearTable"></div>
106
		<div dojoType="dojox.wire.ml.Invocation" object="DataStore1" method="fetch" parameters="dataHolder.request"></div>
107
	</div>
108
 
109
	<!--
110
		Link existing of the text box to transfering the search string to the query param.
111
		We are wiring the value of TextBox value of the widget to the name property of our request
112
		object.  The copy of values to the search should occur on each keyup event (each keypress)
113
	 -->
114
	<div dojoType="dojox.wire.ml.Transfer"
115
		trigger="inputField" triggerEvent="onkeyup"
116
		source="inputField.textbox.value"
117
		target="dataHolder.request.query.name">
118
	</div>
119
 
120
	<!--
121
	  On the call of the onItem function of 'dataHolder', trigger a binding/mapping of the
122
	  item's attribute 'name' and 'type' attributes to specific columns in an array.  Note here that since
123
	  sourceStore is set, it treats the arguments as items from that store and accesses the attributes
124
	  appropriately.  In this case 'name' becomes array entry 0, type, array entry 1, and so on.
125
 
126
	  Then take the result of the data mapping and pass it into the invoke of the addRow function on the
127
	  TableContainer widget.
128
	-->
129
	<div dojoType="dojox.wire.ml.Action"
130
		trigger="dataHolder.request" triggerEvent="onItem">
131
		<div dojoType="dojox.wire.ml.Transfer"
132
			source="arguments[0]" sourceStore="DataStore1"
133
			target="dataHolder.result">
134
			<div dojoType="dojox.wire.ml.ColumnWire" attribute="name"></div>
135
			<div dojoType="dojox.wire.ml.ColumnWire" attribute="type"></div>
136
		</div>
137
		<div dojoType="dojox.wire.ml.Invocation"
138
			object="dataTable" method="addRow" parameters='dataHolder.result'>
139
		</div>
140
	</div>
141
</body>
142
</html>