/public/javascripts/dojo/release/dojo/dojox/wire/demos/markup/demo_FlickrStoreWire.html

http://enginey.googlecode.com/ · HTML · 227 lines · 173 code · 18 blank · 36 comment · 0 complexity · d2b56e0ec834b58aea99ecbd13cca385 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. //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
  29. // to trap on for triggering other events.
  30. var dataHolder = {
  31. //Simple stub datastore request
  32. request: {query: {}}
  33. };
  34. //Function to convert the input from a widget into a comma separated list.
  35. //that is the format of the store parameter.
  36. var tagsInputConverter = function(tags){
  37. if(tags && tags !== ""){
  38. var tagsArray = tags.split(" ");
  39. tags = "";
  40. for(var i = 0; i < tagsArray.length; i++){
  41. tags = tags + tagsArray[i];
  42. if(i < (tagsArray.length - 1)){
  43. tags += ","
  44. }
  45. }
  46. }
  47. return tags
  48. }
  49. </script>
  50. </head>
  51. <body class="tundra">
  52. <h1>
  53. DEMO: FlickrStore Search
  54. </h1>
  55. <hr>
  56. <h3>
  57. Description:
  58. </h3>
  59. <p>
  60. This simple demo shows how services, such as Flickr, can be wrapped by the datastore API. In this demo, you can search public
  61. Flickr images through a simple FlickrStore by specifying a series of tags (separated by spaces) to search on. The results
  62. will be displayed below the search box. This demo is the same as the example demo provided in dojox/data/demos/demo_FlickrStore.html,
  63. except that all the interactions are implemented via Wire instead of a script that runs at dojo.addOnLoad().
  64. </p>
  65. <p>
  66. For fun, search on the 3dny tag!
  67. </p>
  68. <blockquote>
  69. <!--
  70. Layout.
  71. -->
  72. <table>
  73. <tbody>
  74. <tr>
  75. <td>
  76. <b>Status:</b>
  77. </td>
  78. <td>
  79. <div dojoType="dijit.form.TextBox" size="50" id="status" jsId="statusWidget" disabled="true"></div>
  80. </td>
  81. </tr>
  82. <tr>
  83. <td>
  84. <b>ID:</b>
  85. </td>
  86. <td>
  87. <div dojoType="dijit.form.TextBox" size="50" id="userid" jsId="idWidget"></div>
  88. </td>
  89. </tr>
  90. <tr>
  91. <td>
  92. <b>Tags:</b>
  93. </td>
  94. <td>
  95. <div dojoType="dijit.form.TextBox" size="50" id="tags" jsId="tagsWidget" value="3dny"></div>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td>
  100. <b>Tagmode:</b>
  101. </td>
  102. <td>
  103. <select id="tagmode"
  104. jsId="tagmodeWidget"
  105. dojoType="dijit.form.ComboBox"
  106. autocomplete="false"
  107. value="any"
  108. >
  109. <option>any</option>
  110. <option>all</option>
  111. </select>
  112. </td>
  113. </tr>
  114. <tr>
  115. <td>
  116. <b>Number of Pictures:</b>
  117. </td>
  118. <td>
  119. <div
  120. id="count"
  121. jsId="countWidget"
  122. dojoType="dijit.form.NumberSpinner"
  123. value="20"
  124. constraints="{min:1,max:20,places:0}"
  125. ></div>
  126. </td>
  127. </tr>
  128. <tr>
  129. <td>
  130. </td>
  131. <td>
  132. <div dojoType="dijit.form.Button" label="Search" id="searchButton" jsId="searchButtonWidget"></div>
  133. </td>
  134. </tr>
  135. </tbody>
  136. </table>
  137. </blockquote>
  138. <!--
  139. The store instance used by this demo.
  140. -->
  141. <div dojoType="dojox.data.FlickrStore" jsId="flickrStore" label="title"></div>
  142. <div dojoType="dojox.data.demos.widgets.FlickrViewList" store="flickrStore" id="flickrViews" jsId="flickrViewsWidget"></div>
  143. <!-------------------------------- Using dojox.wire, declaratively wire up the widgets. --------------------------->
  144. <!--
  145. This is an example of using the declarative data value definition.
  146. These are effectively declarative variables to act as placeholders
  147. for data values.
  148. -->
  149. <div dojoType="dojox.wire.ml.Data"
  150. id="messageData"
  151. jsId="messageData">
  152. <div dojoType="dojox.wire.ml.DataProperty"
  153. name="processingStart"
  154. value="PROCESSING REQUEST">
  155. </div>
  156. <div dojoType="dojox.wire.ml.DataProperty"
  157. name="processingDone"
  158. value="PROCESSING COMPLETE">
  159. </div>
  160. </div>
  161. <!--
  162. When the search button is clicked, do the following in order:
  163. 1.) Map the widget values over to the request properties.
  164. 2.) Set the status to processing
  165. 3.) Invoke the fetch on the FLickrList to repopulate the table.
  166. -->
  167. <div dojoType="dojox.wire.ml.Action"
  168. trigger="searchButtonWidget"
  169. triggerEvent="onClick">
  170. <!--
  171. Read in the values from the widgets and bind them to the appropriate data locations
  172. The Transfer tag looks for a getter property before using direct access, so it calls
  173. getValue() to get the data from the widget, which works well for the dijit.form.* widgets.
  174. -->
  175. <div dojoType="dojox.wire.ml.Transfer"
  176. source="idWidget.value"
  177. target="dataHolder.request.query.id">
  178. </div>
  179. <!--
  180. For the tags, we need to get the value and then perform a conversion on the result
  181. This is done by doing a transfer through a converter.
  182. -->
  183. <div dojoType="dojox.wire.ml.Transfer"
  184. source="tagsWidget.value"
  185. target="dataHolder.request.query.tags"
  186. converter="tagsInputConverter">
  187. </div>
  188. <div dojoType="dojox.wire.ml.Transfer"
  189. source="tagmodeWidget.value"
  190. target="dataHolder.request.query.tagmode">
  191. </div>
  192. <div dojoType="dojox.wire.ml.Transfer"
  193. source="countWidget.value"
  194. target="dataHolder.request.count">
  195. </div>
  196. <!-- Now invoke the actions in order. -->
  197. <div dojoType="dojox.wire.ml.Transfer" target="statusWidget.value" source="messageData.processingStart"></div>
  198. <div dojoType="dojox.wire.ml.Invocation" object="flickrViewsWidget" method="fetch" parameters="dataHolder.request"></div>
  199. </div>
  200. <!--
  201. When the fetch processing finishes (onComplete is called), then set status to complete.
  202. -->
  203. <div dojoType="dojox.wire.ml.Action"
  204. trigger="flickrViewsWidget"
  205. triggerEvent="onComplete">
  206. <div dojoType="dojox.wire.ml.Transfer" target="statusWidget.value" source="messageData.processingDone"></div>
  207. </div>
  208. </body>
  209. </html>