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 items. 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 using ColumnWire</title> |
---|
15 | <style type="text/css"> |
---|
16 | @import "../../../../dijit/themes/tundra/tundra.css"; |
---|
17 | @import "../../../../dojo/resources/dojo.css"; |
---|
18 | @import "../../../../dijit/tests/css/dijitTests.css"; |
---|
19 | @import "../TableContainer.css"; |
---|
20 | </style> |
---|
21 | |
---|
22 | <script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="isDebug: true, parseOnLoad: true"></script> |
---|
23 | <script type="text/javascript"> |
---|
24 | dojo.require("dojo.parser"); |
---|
25 | dojo.require("dojox.wire.ml.Invocation"); |
---|
26 | dojo.require("dojox.wire.ml.DataStore"); |
---|
27 | dojo.require("dojox.wire.ml.Transfer"); |
---|
28 | |
---|
29 | dojo.require("dijit._Widget"); |
---|
30 | dojo.require("dijit._Templated"); |
---|
31 | dojo.require("dojo.data.ItemFileReadStore"); |
---|
32 | dojo.require("dojox.wire"); |
---|
33 | dojo.require("dojox.wire.demos.TableContainer"); |
---|
34 | |
---|
35 | //Toplevel JS Object to contain a few basics for us, such as the request to pass to the store and a stub onItem function |
---|
36 | // to trap on for triggering other events. |
---|
37 | dataHolder = { |
---|
38 | //Simple object definition to get all items and sort it by the attribute 'type'. |
---|
39 | request: {onItem: function(item){}, sort: [{attribute: "type"}]}, |
---|
40 | //Spot to store off data values as they're generated by the declarative binding. |
---|
41 | result: null |
---|
42 | }; |
---|
43 | </script> |
---|
44 | </head> |
---|
45 | |
---|
46 | <body class="tundra"> |
---|
47 | <!-- |
---|
48 | The store that is queried in this demo |
---|
49 | --> |
---|
50 | <div dojoType="dojo.data.ItemFileReadStore" |
---|
51 | data-dojo-id="DataStore1" |
---|
52 | url="countries.json"> |
---|
53 | </div> |
---|
54 | |
---|
55 | <!-- |
---|
56 | On load of the page, invoke the fetch method of the object 'DataStore1', |
---|
57 | get its parameters from the JS object 'sample.request |
---|
58 | --> |
---|
59 | <div dojoType="dojox.wire.ml.Invocation" |
---|
60 | triggerEvent="onLoad" |
---|
61 | object="DataStore1" method="fetch" parameters="dataHolder.request"></div> |
---|
62 | |
---|
63 | <!-- |
---|
64 | Simple container widget for creating a 'table from rows defined by an array |
---|
65 | --> |
---|
66 | <div dojoType="dojox.wire.demos.TableContainer" data-dojo-id="r1" headers="Name,Location Type"></div> |
---|
67 | |
---|
68 | <!-- |
---|
69 | On the call of the onItem function of 'dataHolder', trigger a binding/mapping of the |
---|
70 | item's attribute 'name' and 'type' attributes to specific columns in an array. Note here that since |
---|
71 | sourceStore is set, it treats the arguments as items from that store and accesses the attributes |
---|
72 | appropriately. In this case 'name' becomes array entry 0, type, array entry 1, and so on. |
---|
73 | |
---|
74 | Then take the result of the data mapping and pass it into the invoke of the addRow function on the |
---|
75 | TableContainer widget. |
---|
76 | --> |
---|
77 | <div dojoType="dojox.wire.ml.Action" |
---|
78 | trigger="dataHolder.request" triggerEvent="onItem"> |
---|
79 | <div dojoType="dojox.wire.ml.Transfer" |
---|
80 | source="arguments[0]" sourceStore="DataStore1" |
---|
81 | target="dataHolder.result"> |
---|
82 | <div dojoType="dojox.wire.ml.ColumnWire" attribute="name"></div> |
---|
83 | <div dojoType="dojox.wire.ml.ColumnWire" attribute="type"></div> |
---|
84 | </div> |
---|
85 | <div dojoType="dojox.wire.ml.Invocation" |
---|
86 | object="r1" method="addRow" parameters='dataHolder.result'> |
---|
87 | </div> |
---|
88 | </div> |
---|
89 | </body> |
---|
90 | </html> |
---|