6e19786fdfd19917665ae4a27689d3b5fee38a4f.svn-base 5.3 KB

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