/branches/versions/aipo702b/design/htmlmock/javascript/dojox/wire/demos/markup/demo_FlickrStoreWire.html

http://aipo.googlecode.com/ · HTML · 281 lines · 203 code · 24 blank · 54 comment · 0 complexity · 0532bdf03218866959b8418672e71519 MD5 · raw file

  1. <!--
  2. This file is a demo of the FlickrStore, a simple wrapper to the public feed service
  3. of Flickr. This just does very basic queries against Flickr and loads the results
  4. into a list viewing widget.
  5. -->
  6. <html>
  7. <head>
  8. <title>Demo of FlickrStore</title>
  9. <style type="text/css">
  10. @import "../../../../dijit/themes/tundra/tundra.css";
  11. @import "../../../../dojo/resources/dojo.css";
  12. @import "../../../../dijit/tests/css/dijitTests.css";
  13. @import "./flickrDemo.css";
  14. </style>
  15. <script type="text/javascript" src="../../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
  16. <script type="text/javascript">
  17. dojo.require("dojo.parser");
  18. dojo.require("dijit.form.TextBox");
  19. dojo.require("dijit.form.Button");
  20. dojo.require("dijit.form.ComboBox");
  21. dojo.require("dijit.form.NumberSpinner");
  22. dojo.require("dojox.data.FlickrStore");
  23. dojo.require("dojox.wire.ml.Invocation");
  24. dojo.require("dojox.wire.ml.Transfer");
  25. dojo.require("dojox.wire.ml.Data");
  26. dojo.require("dojox.wire");
  27. dojo.require("dojox.data.demos.widgets.FlickrViewList");
  28. dojo.require("dojox.data.demos.widgets.FlickrView");
  29. //Toplevel JS Object to contain a few basics for us, such as the request to pass to the store and a stub onItem and onComplete function
  30. // to trap on for triggering other events.
  31. var dataHolder = {
  32. //Simple stub datastore request
  33. request: {query: {}, onItem: function(item, req){}, onComplete: function(items, req){}},
  34. //Spot to store off data values as they're generated by the declarative binding.
  35. result: null
  36. };
  37. //Function to convert the input from a widget into a comma separated list.
  38. //that is the format of the store parameter.
  39. var tagsInputConverter = function(tags){
  40. if(tags && tags !== ""){
  41. var tagsArray = tags.split(" ");
  42. tags = "";
  43. for(var i = 0; i < tagsArray.length; i++){
  44. tags = tags + tagsArray[i];
  45. if(i < (tagsArray.length - 1)){
  46. tags += ","
  47. }
  48. }
  49. }
  50. return tags
  51. }
  52. </script>
  53. </head>
  54. <body class="tundra">
  55. <h1>
  56. DEMO: FlickrStore Search
  57. </h1>
  58. <hr>
  59. <h3>
  60. Description:
  61. </h3>
  62. <p>
  63. This simple demo shows how services, such as Flickr, can be wrapped by the datastore API. In this demo, you can search public
  64. Flickr images through a simple FlickrStore by specifying a series of tags (separated by spaces) to search on. The results
  65. will be displayed below the search box. This demo is the same as the example demo provided in dojox/data/demos/demo_FlickrStore.html,
  66. except that all the interactions are implemented via Wire instead of a script that runs at dojo.addOnLoad().
  67. </p>
  68. <p>
  69. For fun, search on the 3dny tag!
  70. </p>
  71. <blockquote>
  72. <!--
  73. Layout.
  74. -->
  75. <table>
  76. <tbody>
  77. <tr>
  78. <td>
  79. <b>Status:</b>
  80. </td>
  81. <td>
  82. <div dojoType="dijit.form.TextBox" size="50" id="status" jsId="statusWidget" disabled="true"></div>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td>
  87. <b>ID:</b>
  88. </td>
  89. <td>
  90. <div dojoType="dijit.form.TextBox" size="50" id="userid" jsId="idWidget"></div>
  91. </td>
  92. </tr>
  93. <tr>
  94. <td>
  95. <b>Tags:</b>
  96. </td>
  97. <td>
  98. <div dojoType="dijit.form.TextBox" size="50" id="tags" jsId="tagsWidget" value="3dny"></div>
  99. </td>
  100. </tr>
  101. <tr>
  102. <td>
  103. <b>Tagmode:</b>
  104. </td>
  105. <td>
  106. <select id="tagmode"
  107. jsId="tagmodeWidget"
  108. dojoType="dijit.form.ComboBox"
  109. autocomplete="false"
  110. value="any"
  111. >
  112. <option>any</option>
  113. <option>all</option>
  114. </select>
  115. </td>
  116. </tr>
  117. <tr>
  118. <td>
  119. <b>Number of Pictures:</b>
  120. </td>
  121. <td>
  122. <div
  123. id="count"
  124. jsId="countWidget"
  125. dojoType="dijit.form.NumberSpinner"
  126. value="20"
  127. constraints="{min:1,max:20,places:0}"
  128. ></div>
  129. </td>
  130. </tr>
  131. <tr>
  132. <td>
  133. </td>
  134. <td>
  135. <div dojoType="dijit.form.Button" label="Search" id="searchButton" jsId="searchButtonWidget"></div>
  136. </td>
  137. </tr>
  138. </tbody>
  139. </table>
  140. </blockquote>
  141. <!--
  142. The store instance used by this demo.
  143. -->
  144. <div dojoType="dojox.data.FlickrStore" jsId="flickrStore" label="title"></div>
  145. <div dojoType="dojox.data.demos.widgets.FlickrViewList" id="flickrViews" jsId="flickrViewsWidget"></div>
  146. <!-------------------------------- Using dojox.wire, declaratively wire up the widgets. --------------------------->
  147. <!--
  148. This is an example of using the declarative data value definition.
  149. These are effectively declarative variables to act as placeholders
  150. for data values.
  151. -->
  152. <div dojoType="dojox.wire.ml.Data"
  153. id="messageData"
  154. jsId="messageData">
  155. <div dojoType="dojox.wire.ml.DataProperty"
  156. name="processingStart"
  157. value="PROCESSING REQUEST">
  158. </div>
  159. <div dojoType="dojox.wire.ml.DataProperty"
  160. name="processingDone"
  161. value="PROCESSING COMPLETE">
  162. </div>
  163. </div>
  164. <!--
  165. When the search button is clicked, do the following in order:
  166. 1.) Map the widget values over to the request properties.
  167. 2.) Clear existing rows from table,
  168. 3.) Set the status to processing
  169. 4.) Invoke the fetch to repopulate the table.
  170. -->
  171. <div dojoType="dojox.wire.ml.Action"
  172. trigger="searchButtonWidget"
  173. triggerEvent="onClick">
  174. <!--
  175. Read in the values from the widgets and bind them to the appropriate data locations
  176. For basic properties, you could use transfer directly, but since the text boxes are
  177. designed to be accessed through getValue/setValue, it's better to do these as
  178. Invocations on widget methods.
  179. -->
  180. <div dojoType="dojox.wire.ml.Invocation"
  181. object="idWidget"
  182. method="getValue"
  183. result="dataHolder.request.query.id">
  184. </div>
  185. <!--
  186. For the tags, we need to get the value and then perform a conversion on the result
  187. This is done by doing an invoke, then a transfer through a converter.
  188. -->
  189. <div dojoType="dojox.wire.ml.Invocation"
  190. object="tagsWidget"
  191. method="getValue"
  192. result="dataHolder.request.query.tags">
  193. </div>
  194. <div dojoType="dojox.wire.ml.Transfer"
  195. source="dataHolder.request.query.tags"
  196. target="dataHolder.request.query.tags"
  197. converter="tagsInputConverter">
  198. </div>
  199. <div dojoType="dojox.wire.ml.Invocation"
  200. object="tagmodeWidget"
  201. method="getValue"
  202. result="dataHolder.request.query.tagmode">
  203. </div>
  204. <div dojoType="dojox.wire.ml.Invocation"
  205. object="countWidget"
  206. method="getValue"
  207. result="dataHolder.request.count">
  208. </div>
  209. <!-- Now invoke the actions in order. -->
  210. <div dojoType="dojox.wire.ml.Invocation" object="flickrViewsWidget" method="clearList"></div>
  211. <div dojoType="dojox.wire.ml.Invocation" object="statusWidget" method="setValue" parameters="messageData.processingStart"></div>
  212. <div dojoType="dojox.wire.ml.Invocation" object="flickrStore" method="fetch" parameters="dataHolder.request"></div>
  213. </div>
  214. <!--
  215. When the fetch processing finishes (onComplete is called), then set status to complete.
  216. -->
  217. <div dojoType="dojox.wire.ml.Action"
  218. trigger="dataHolder.request"
  219. triggerEvent="onComplete">
  220. <div dojoType="dojox.wire.ml.Invocation" object="statusWidget" method="setValue" parameters="messageData.processingDone"></div>
  221. </div>
  222. <!--
  223. On the call of the onItem function of 'dataHolder', trigger a binding/mapping of the
  224. item's attributes to the requires parameters that are passed into addView. In this case
  225. FlikrItemAttribute -> viewItemParam
  226. title title
  227. imageUrlSmall iconUrl
  228. imageUrl imageUrl
  229. author author
  230. Then take the result of the data mapping and pass it into the invoke of the addView function on the
  231. FlickerViews widget.
  232. -->
  233. <div dojoType="dojox.wire.ml.Action"
  234. trigger="dataHolder.request" triggerEvent="onItem">
  235. <div dojoType="dojox.wire.ml.Transfer"
  236. source="arguments[0]" sourceStore="flickrStore"
  237. target="dataHolder.result">
  238. <!--
  239. Map the attributes of the items to the property name defined
  240. in the wire on the object in the target
  241. -->
  242. <div dojoType="dojox.wire.ml.ChildWire"
  243. name="title" attribute="title"></div>
  244. <div dojoType="dojox.wire.ml.ChildWire"
  245. name="imageUrl" attribute="imageUrl"></div>
  246. <div dojoType="dojox.wire.ml.ChildWire"
  247. name="iconUrl" attribute="imageUrlSmall"></div>
  248. <div dojoType="dojox.wire.ml.ChildWire"
  249. name="author" attribute="author"></div>
  250. </div>
  251. <div dojoType="dojox.wire.ml.Invocation"
  252. object="flickrViewsWidget" method="addView" parameters='dataHolder.result'>
  253. </div>
  254. </div>
  255. </body>
  256. </html>