2c8e2aa8a29b4ce57d969271dd4d3476fe37ec74.svn-base 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 FlickrRestStore</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("dijit.Tree");
  23. dojo.require("dojox.data.FlickrStore");
  24. dojo.require("dojox.data.FlickrRestStore");
  25. dojo.require("dojox.data.demos.widgets.FlickrViewList");
  26. dojo.require("dojox.data.demos.widgets.FlickrView");
  27. function init(){
  28. var fViewWidgets = [];
  29. //Set up an onComplete handler for flickrData
  30. function onComplete(items, request){
  31. flickrViewsWidget.clearList();
  32. if(items.length > 0){
  33. for(var i = 0; i < items.length; i++){
  34. var flickrData = {
  35. title: flickrStore.getValue(items[i],"title"),
  36. author: flickrStore.getValue(items[i],"author"),
  37. iconUrl: flickrStore.getValue(items[i],"imageUrlSmall"),
  38. imageUrl: flickrStore.getValue(items[i],"imageUrl")
  39. }
  40. flickrViewsWidget.addView(flickrData);
  41. }
  42. }
  43. statusWidget.setValue("PROCESSING COMPLETE.");
  44. }
  45. //What to do if a search fails...
  46. function onError(error, request){
  47. flickrViewsWidget.clearList();
  48. statusWidget.setValue("PROCESSING ERROR.");
  49. }
  50. //Function to invoke the search of the FlickrStore
  51. function invokeSearch(){
  52. var request = {
  53. query: {
  54. apikey: "8c6803164dbc395fb7131c9d54843627"
  55. },
  56. onComplete: onComplete,
  57. onError: onError
  58. };
  59. if(idWidget){
  60. var userid = idWidget.getValue();
  61. if(userid && userid !== ""){
  62. request.query.userid = userid;
  63. }
  64. }
  65. if(tagsWidget){
  66. var tags = tagsWidget.getValue();
  67. if(tags && tags !== ""){
  68. var tagsArray = tags.split(" ");
  69. tags = "";
  70. for(var i = 0; i < tagsArray.length; i++){
  71. tags = tags + tagsArray[i];
  72. if(i < (tagsArray.length - 1)){
  73. tags += ","
  74. }
  75. }
  76. request.query.tags = tags;
  77. }
  78. }
  79. if(tagmodeWidget){
  80. var tagmode = tagmodeWidget.getValue();
  81. if(tagmode !== ""){
  82. request.query.tagmode = tagmode;
  83. }
  84. }
  85. if(setIdWidget){
  86. var setId = setIdWidget.getValue();
  87. if(setId != ""){
  88. request.query.setId = setId;
  89. }
  90. }
  91. if(fullTextWidget){
  92. var fullText = fullTextWidget.getValue();
  93. if(fullText != ""){
  94. request.query.text = fullText;
  95. }
  96. }
  97. if(sortTypeWidget && sortDirWidget){
  98. var sortType = sortTypeWidget.getValue();
  99. var sortDirection = sortDirWidget.getValue();
  100. if(sortType != "" && sortDirection != ""){
  101. request.query.sort = [
  102. {
  103. attribute: sortType,
  104. descending: (sortDirection.toLowerCase() == "descending")
  105. }
  106. ];
  107. }
  108. }
  109. if(countWidget){
  110. request.count = countWidget.getValue();
  111. }
  112. if(pageWidget){
  113. request.start = request.count * (pageWidget.getValue() -1);
  114. }
  115. if(statusWidget){
  116. statusWidget.setValue("PROCESSING REQUEST");
  117. }
  118. flickrStore.fetch(request);
  119. }
  120. //Lastly, link up the search event.
  121. var button = dijit.byId("searchButton");
  122. dojo.connect(button, "onClick", invokeSearch);
  123. }
  124. dojo.addOnLoad(init);
  125. </script>
  126. </head>
  127. <body class="tundra">
  128. <h1>
  129. DEMO: FlickrRestStore Search
  130. </h1>
  131. <hr>
  132. <h3>
  133. Description:
  134. </h3>
  135. <p>
  136. This simple demo shows how services, such as Flickr, can be wrapped by the datastore API.
  137. In this demo, you can search public Flickr images through a FlickrRestStore by specifying
  138. a series of tags (separated by spaces) to search on. The results will be displayed below the search box.
  139. </p>
  140. <p>
  141. For fun, search on the 3dny tag!
  142. </p>
  143. <blockquote>
  144. <!--
  145. The store instance used by this demo.
  146. -->
  147. <table>
  148. <tbody>
  149. <tr>
  150. <td>
  151. <b>Status:</b>
  152. </td>
  153. <td>
  154. <div dojoType="dijit.form.TextBox" size="50" id="status" jsId="statusWidget" disabled="true"></div>
  155. </td>
  156. <td></td>
  157. <td></td>
  158. </tr>
  159. <tr>
  160. <td>
  161. <b>User ID:</b>
  162. </td>
  163. <td>
  164. <div dojoType="dijit.form.TextBox" size="50" id="userid" jsId="idWidget" value="44153025@N00"></div>
  165. </td>
  166. <td>
  167. <b>Set ID</b>
  168. </td>
  169. <td>
  170. <div dojoType="dijit.form.TextBox" size="50" id="setid" jsId="setIdWidget"></div>
  171. </td>
  172. </tr>
  173. <tr>
  174. <td>
  175. <b>Tags:</b>
  176. </td>
  177. <td>
  178. <div dojoType="dijit.form.TextBox" size="50" id="tags" jsId="tagsWidget" value="rollingstones,kinsale"></div>
  179. </td>
  180. <td>
  181. <b>Full Text</b>
  182. </td>
  183. <td>
  184. <div dojoType="dijit.form.TextBox" size="50" id="fulltext" jsId="fullTextWidget"></div>
  185. </td>
  186. </tr>
  187. <tr>
  188. <td>
  189. <b>Tagmode:</b>
  190. </td>
  191. <td>
  192. <select id="tagmode"
  193. jsId="tagmodeWidget"
  194. dojoType="dijit.form.ComboBox"
  195. autocomplete="false"
  196. value="any"
  197. >
  198. <option>any</option>
  199. <option>all</option>
  200. </select>
  201. </td>
  202. <td>
  203. <b>Sort</b>
  204. </td>
  205. <td>
  206. <select dojoType="dijit.form.ComboBox" size="15" id="sorttype" jsId="sortTypeWidget">
  207. <option>date-posted</option>
  208. <option>date-taken</option>
  209. <option>interestingness</option>
  210. </select>
  211. <select dojoType="dijit.form.ComboBox" size="15" id="sortdirection" jsId="sortDirWidget">
  212. <option>ascending</option>
  213. <option>descending</option>
  214. </select>
  215. </td>
  216. </tr>
  217. <tr>
  218. <td>
  219. <b>Number of Pictures:</b>
  220. </td>
  221. <td>
  222. <div
  223. id="count"
  224. jsId="countWidget"
  225. dojoType="dijit.form.NumberSpinner"
  226. value="20"
  227. constraints="{min:1,max:20,places:0}"
  228. ></div>
  229. </td>
  230. <td>
  231. <b>Page:</b>
  232. </td>
  233. <td>
  234. <div
  235. id="page"
  236. jsId="pageWidget"
  237. dojoType="dijit.form.NumberSpinner"
  238. value="1"
  239. constraints="{min:1,max:5,places:0}"
  240. ></div>
  241. </td>
  242. </tr>
  243. <tr>
  244. <td>
  245. </td>
  246. <td>
  247. <div dojoType="dijit.form.Button" label="Search" id="searchButton" jsId="searchButtonWidget"></div>
  248. </td>
  249. </tr>
  250. </tbody>
  251. </table>
  252. <hr/>
  253. <div dojoType="dojox.data.FlickrRestStore" jsId="flickrStore" label="title"></div>
  254. <div dojoType="dojox.data.demos.widgets.FlickrViewList" id="flickrViews" jsId="flickrViewsWidget"></div>
  255. </body>
  256. </html>