search-recipes.xsl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:eat="http://msqr.us/xsd/ieat"
  4. xmlns:xweb="http://msqr.us/xsd/jaxb-web"
  5. exclude-result-prefixes="eat xweb">
  6. <!-- imports -->
  7. <xsl:import href="tmpl/default-layout.xsl"/>
  8. <!-- layout variables -->
  9. <xsl:variable name="layout.global.nav.page" select="'search'"/>
  10. <!-- helper vars -->
  11. <xsl:variable name="searchResults" select="xweb:x-data/xweb:x-model/eat:search-results"/>
  12. <xsl:variable name="searchCriteria" select="$searchResults/eat:recipe-criteria"/>
  13. <xsl:template match="xweb:x-data" mode="page-title">
  14. <xsl:choose>
  15. <xsl:when test="$searchResults/@mode = 'ingredient'">
  16. <xsl:value-of select="key('i18n','recipe-search-by-ingredient.title')"/>
  17. </xsl:when>
  18. <xsl:otherwise>
  19. <xsl:value-of select="key('i18n','recipe-search.title')"/>
  20. </xsl:otherwise>
  21. </xsl:choose>
  22. </xsl:template>
  23. <xsl:template match="xweb:x-data" mode="page-head-content">
  24. <xsl:choose>
  25. <xsl:when test="$searchResults/@mode = 'ingredient'">
  26. <link rel="stylesheet" type="text/css" href="{$web-context}/css/jquery.autocomplete.css" media="screen" />
  27. <script type="text/javascript" src="{$web-context}/js/jquery-1.3.2.js" xml:space="preserve"> </script>
  28. <script type="text/javascript" src="{$web-context}/js/jquery.ajaxQueue.js" xml:space="preserve"> </script>
  29. <script type="text/javascript" src="{$web-context}/js/jquery.autocomplete.js" xml:space="preserve"> </script>
  30. <script type="text/javascript" src="{$web-context}/js/xweb-locale.js" xml:space="preserve"> </script>
  31. <script type="text/javascript" src="{$web-context}/js/ieat-util.js" xml:space="preserve"> </script>
  32. <script type="text/javascript" src="{$web-context}/js/ingredient-search.js" xml:space="preserve"> </script>
  33. </xsl:when>
  34. <xsl:when test="$searchResults/@mode = 'advanced'">
  35. <script type="text/javascript" src="{$web-context}/js/jquery-1.3.2.js" xml:space="preserve"> </script>
  36. <script type="text/javascript" src="{$web-context}/js/jquery.ajaxQueue.js" xml:space="preserve"> </script>
  37. <script type="text/javascript" src="{$web-context}/js/xweb-locale.js" xml:space="preserve"> </script>
  38. <script type="text/javascript" src="{$web-context}/js/ieat-util.js" xml:space="preserve"> </script>
  39. <script type="text/javascript" src="{$web-context}/js/advanced-search.js" xml:space="preserve"> </script>
  40. <script type="text/javascript" xml:space="preserve">
  41. <xsl:comment>
  42. var numAdvancedCriteria = <xsl:value-of select="count($searchCriteria/eat:advanced)"/>;
  43. if ( numAdvancedCriteria == 0 ) {
  44. numAdvancedCriteria++;
  45. }
  46. var advancedCriteria = [
  47. <xsl:apply-templates select="$searchCriteria/eat:advanced" mode="data"/>
  48. ];
  49. function init() {
  50. for ( var i = 0; i &lt; numAdvancedCriteria; i++ ) {
  51. initAdvancedSearchRow(i);
  52. }
  53. }
  54. window.onload = init;
  55. //</xsl:comment>
  56. </script>
  57. </xsl:when>
  58. </xsl:choose>
  59. </xsl:template>
  60. <xsl:template match="xweb:x-data" mode="action-links">
  61. <xsl:choose>
  62. <xsl:when test="not($searchResults/@mode) or $searchResults/@mode = 'simple'">
  63. <xsl:value-of select="key('i18n','link.recipe.search.simple')"/>
  64. </xsl:when>
  65. <xsl:otherwise>
  66. <a href="{$web-context}{$ctx/xweb:path}?mode=simple" title="{key('i18n','link.recipe.search.simple.title')}">
  67. <xsl:value-of select="key('i18n','link.recipe.search.simple')"/>
  68. </a>
  69. </xsl:otherwise>
  70. </xsl:choose>
  71. <xsl:text> - </xsl:text>
  72. <xsl:choose>
  73. <xsl:when test="$searchResults/@mode = 'ingredient'">
  74. <xsl:value-of select="key('i18n','link.recipe.search.ingredients')"/>
  75. </xsl:when>
  76. <xsl:otherwise>
  77. <a href="{$web-context}{$ctx/xweb:path}?mode=ingredient" title="{key('i18n','link.recipe.search.ingredients.title')}">
  78. <xsl:value-of select="key('i18n','link.recipe.search.ingredients')"/>
  79. </a>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. <xsl:if test="$acting-user">
  83. <xsl:text> - </xsl:text>
  84. <xsl:choose>
  85. <xsl:when test="$searchResults/@mode = 'advanced'">
  86. <xsl:value-of select="key('i18n','link.recipe.search.advanced')"/>
  87. </xsl:when>
  88. <xsl:otherwise>
  89. <a href="{$web-context}{$ctx/xweb:path}?mode=advanced" title="{key('i18n','link.recipe.search.advanced.title')}">
  90. <xsl:value-of select="key('i18n','link.recipe.search.advanced')"/>
  91. </a>
  92. </xsl:otherwise>
  93. </xsl:choose>
  94. </xsl:if>
  95. </xsl:template>
  96. <xsl:template match="xweb:x-data" mode="page-body">
  97. <div class="intro">
  98. <xsl:choose>
  99. <xsl:when test="$searchResults/@mode = 'ingredient'">
  100. <xsl:value-of select="key('i18n','recipe-search-by-ingredient.intro')"
  101. disable-output-escaping="yes" />
  102. </xsl:when>
  103. <xsl:when test="$searchResults/@mode = 'advanced'">
  104. <xsl:value-of select="key('i18n','recipe-search-advanced.intro')"
  105. disable-output-escaping="yes" />
  106. </xsl:when>
  107. <xsl:otherwise>
  108. <xsl:value-of select="key('i18n','recipe-search.intro')"
  109. disable-output-escaping="yes"/>
  110. </xsl:otherwise>
  111. </xsl:choose>
  112. </div>
  113. <xsl:choose>
  114. <xsl:when test="$searchResults/@mode = 'ingredient'">
  115. <xsl:apply-templates select="." mode="search-for-recipes-by-ingredient"/>
  116. </xsl:when>
  117. <xsl:when test="$searchResults/@mode = 'advanced'">
  118. <xsl:apply-templates select="." mode="search-for-recipes-advanced"/>
  119. </xsl:when>
  120. <xsl:otherwise>
  121. <xsl:apply-templates select="." mode="search-for-recipes"/>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:template>
  125. <xsl:template match="xweb:x-data" mode="search-for-recipes">
  126. <form method="post" action="{$web-context}{$ctx/xweb:path}">
  127. <table class="form">
  128. <tr>
  129. <th>
  130. <xsl:value-of select="key('i18n','query.displayName')"/>
  131. </th>
  132. <td colspan="3">
  133. <input type="text" name="criteria.simpleQuery" value="{$searchCriteria/eat:simpleQuery}"/>
  134. </td>
  135. </tr>
  136. <tr>
  137. <th/>
  138. <td>
  139. <input type="submit" value="{key('i18n','search.displayName')}"/>
  140. </td>
  141. </tr>
  142. </table>
  143. <input type="hidden" name="criteria.mode" value="simple"/>
  144. </form>
  145. <script type="text/javascript" xml:space="preserve">
  146. document.forms[0].elements['criteria.simpleQuery'].focus();
  147. </script>
  148. <xsl:if test="$searchCriteria">
  149. <xsl:apply-templates select="$searchResults" mode="search-for-recipes"/>
  150. </xsl:if>
  151. </xsl:template>
  152. <xsl:template match="xweb:x-data" mode="search-for-recipes-by-ingredient">
  153. <form method="post" action="{$web-context}{$ctx/xweb:path}">
  154. <!--
  155. Recipe ingredients
  156. -->
  157. <div class="formLabel">
  158. <xsl:value-of select="key('i18n','recipe.ingredients.displayName')"/>:
  159. </div>
  160. <table class="form" id="ingredient_table">
  161. <xsl:for-each select="$searchCriteria/eat:ingredient">
  162. <xsl:call-template name="recipe-ingredient"/>
  163. </xsl:for-each>
  164. <xsl:if test="not($searchCriteria/eat:ingredient)">
  165. <xsl:call-template name="recipe-ingredient">
  166. <xsl:with-param name="index" select="0"/>
  167. </xsl:call-template>
  168. </xsl:if>
  169. <tr id="ingredient_add_row">
  170. <td>
  171. <a href="#"
  172. id="ingredient_add_link"
  173. title="{key('i18n','recipe.ingredients.add')}" class="plus">
  174. <span class="alt">
  175. <xsl:value-of select="key('i18n','recipe.ingredients.add')"/>
  176. </span>
  177. </a>
  178. </td>
  179. <td></td>
  180. </tr>
  181. </table>
  182. <table class="form">
  183. <tr>
  184. <th/>
  185. <td>
  186. <input type="submit" value="{key('i18n','search.displayName')}"/>
  187. <xsl:text> </xsl:text>
  188. <input type="submit" name="_cancel" value="{key('i18n','cancel.displayName')}"/>
  189. </td>
  190. </tr>
  191. </table>
  192. <input type="hidden" name="criteria.mode" value="ingredient"/>
  193. </form>
  194. <xsl:if test="$searchCriteria">
  195. <xsl:apply-templates select="$searchResults" mode="search-for-recipes"/>
  196. </xsl:if>
  197. </xsl:template>
  198. <xsl:template match="xweb:x-data" mode="search-for-recipes-advanced">
  199. <form method="post" action="{$web-context}{$ctx/xweb:path}" id="advancedSearchForm">
  200. <table id="criteria_table" class="form">
  201. <tbody>
  202. <xsl:for-each select="$searchCriteria/eat:advanced">
  203. <xsl:call-template name="advanced-criteria"/>
  204. </xsl:for-each>
  205. <xsl:if test="not($searchCriteria/eat:advanced)">
  206. <xsl:call-template name="advanced-criteria">
  207. <xsl:with-param name="index" select="0"/>
  208. </xsl:call-template>
  209. </xsl:if>
  210. <tr id="criteria_add_row">
  211. <td colspan="3">
  212. <a href="javascript:addAdvancedSearchCriteria()"
  213. title="{key('i18n','recipe.search.advanced.criteria.add')}"
  214. class="plus">
  215. <span class="alt">
  216. <xsl:value-of select="key('i18n','recipe.search.advanced.criteria.add')"/>
  217. </span>
  218. </a>
  219. </td>
  220. </tr>
  221. </tbody>
  222. </table>
  223. <div>
  224. <input type="submit" value="{key('i18n','search.displayName')}"/>
  225. </div>
  226. <input type="hidden" name="criteria.mode" value="advanced"/>
  227. </form>
  228. <script type="text/javascript" xml:space="preserve">
  229. document.forms[0].elements['criteria.advanced[0].type'].focus();
  230. </script>
  231. <xsl:if test="$searchCriteria">
  232. <xsl:apply-templates select="$searchResults" mode="search-for-recipes"/>
  233. </xsl:if>
  234. </xsl:template>
  235. <xsl:template match="eat:recipe" mode="search-for-recipes">
  236. <li>
  237. <a>
  238. <xsl:attribute name="href">
  239. <xsl:value-of select="$web-context"/>
  240. <xsl:text>/recipe.do?recipeId=</xsl:text>
  241. <xsl:value-of select="@recipeId"/>
  242. <xsl:text>&amp;criteria.mode=</xsl:text>
  243. <xsl:value-of select="preceding-sibling::eat:recipe-criteria/@mode"/>
  244. <xsl:text>&amp;criteria.simpleQuery=</xsl:text>
  245. <xsl:value-of select="preceding-sibling::eat:recipe-criteria/eat:simpleQuery"/>
  246. </xsl:attribute>
  247. <xsl:value-of select="eat:name"/>
  248. </a>
  249. <p>
  250. <xsl:apply-templates select="eat:excerpt"/>
  251. </p>
  252. </li>
  253. </xsl:template>
  254. <xsl:template name="recipe-ingredient">
  255. <xsl:param name="index"/>
  256. <xsl:variable name="row-index">
  257. <xsl:choose>
  258. <xsl:when test="string-length($index) &gt; 0">
  259. <xsl:value-of select="$index"/>
  260. </xsl:when>
  261. <xsl:otherwise>
  262. <xsl:value-of select="position() - 1"/>
  263. </xsl:otherwise>
  264. </xsl:choose>
  265. </xsl:variable>
  266. <tr valign="middle" class="recipe-ingredient">
  267. <xsl:if test="not(self::eat:ingredient) or position() = 1">
  268. <xsl:attribute name="id">ingredient_row</xsl:attribute>
  269. </xsl:if>
  270. <td>
  271. <!--select name="criteria.ingredient[{$row-index}].ingredient.ingredientId">
  272. <option value="0"></option>
  273. <xsl:for-each select="$aux/eat:ui/eat:ingredient">
  274. <xsl:call-template name="ingredient-ingredient">
  275. <xsl:with-param name="ingredient" select="$me"/>
  276. </xsl:call-template>
  277. </xsl:for-each>
  278. </select-->
  279. <input type="text"
  280. name="criteria.ingredient[{$row-index}].ingredient.name"
  281. id="criteria.ingredient[{$row-index}].ingredient.name"
  282. class="ingredient-autocomplete"
  283. value="{eat:ingredient/eat:name}" />
  284. <input type="hidden"
  285. name="criteria.ingredient[{$row-index}].ingredient.ingredientId"
  286. id="criteria.ingredient[{$row-index}].ingredient.ingredientId">
  287. <xsl:attribute name="value">
  288. <xsl:choose>
  289. <xsl:when test="number(eat:ingredient/@ingredientId) &gt; 0">
  290. <xsl:value-of select="eat:ingredient/@ingredientId"/>
  291. </xsl:when>
  292. <xsl:otherwise>0</xsl:otherwise>
  293. </xsl:choose>
  294. </xsl:attribute>
  295. </input>
  296. </td>
  297. <td>
  298. <input type="checkbox" name="criteria.ingredient[{$row-index}].optional"
  299. value="true">
  300. <xsl:if test="@optional = 'true'">
  301. <xsl:attribute name="checked">checked</xsl:attribute>
  302. </xsl:if>
  303. </input>
  304. </td>
  305. <td>
  306. <a href="#"
  307. title="{key('i18n','recipe.ingredients.remove')}" class="minus">
  308. <xsl:if test="not(self::eat:ingredient) or position() = 1">
  309. <xsl:attribute name="style">display: none</xsl:attribute>
  310. </xsl:if>
  311. <span class="alt">
  312. <xsl:value-of select="key('i18n','recipe.ingredients.remove')"/>
  313. </span>
  314. </a>
  315. </td>
  316. </tr>
  317. </xsl:template>
  318. <xsl:template name="ingredient-ingredient">
  319. <xsl:param name="ingredient"/>
  320. <option value="{@ingredientId}">
  321. <xsl:if test="@ingredientId = $ingredient/eat:ingredient/@ingredientId">
  322. <xsl:attribute name="selected">selected</xsl:attribute>
  323. </xsl:if>
  324. <xsl:value-of select="eat:name"/>
  325. </option>
  326. </xsl:template>
  327. <xsl:template name="advanced-criteria">
  328. <xsl:param name="index"/>
  329. <xsl:variable name="row-index">
  330. <xsl:choose>
  331. <xsl:when test="string-length($index) &gt; 0">
  332. <xsl:value-of select="$index"/>
  333. </xsl:when>
  334. <xsl:otherwise>
  335. <xsl:value-of select="position() - 1"/>
  336. </xsl:otherwise>
  337. </xsl:choose>
  338. </xsl:variable>
  339. <xsl:variable name="me" select="."/>
  340. <tr>
  341. <xsl:if test="not(self::eat:advanced) or position() = 1">
  342. <xsl:attribute name="id">criteria_row</xsl:attribute>
  343. </xsl:if>
  344. <td>
  345. <select name="criteria.advanced[{$row-index}].type">
  346. <xsl:text> </xsl:text>
  347. </select>
  348. <select name="criteria.advanced[{$row-index}].op">
  349. <xsl:text> </xsl:text>
  350. </select>
  351. <select name="criteria.advanced[{$row-index}].choice">
  352. <xsl:text> </xsl:text>
  353. </select>
  354. <input type="text" name="criteria.advanced[{$row-index}].query" />
  355. </td>
  356. <td>
  357. <input type="checkbox" name="criteria.advanced[{$row-index}].required"
  358. value="true"/>
  359. </td>
  360. <td>
  361. <a href="javascript:removeAdvancedSearchCriteria({$row-index})"
  362. title="{key('i18n','recipe.search.advanced.criteria.remove')}" class="minus">
  363. <xsl:if test="not(self::eat:advanced) or position() = 1">
  364. <xsl:attribute name="style">display: none</xsl:attribute>
  365. </xsl:if>
  366. <span class="alt">
  367. <xsl:value-of select="key('i18n','recipe.search.advanced.criteria.remove')"/>
  368. </span>
  369. </a>
  370. </td>
  371. </tr>
  372. </xsl:template>
  373. <xsl:template match="eat:advanced" mode="data">
  374. <xsl:text>['</xsl:text>
  375. <xsl:value-of select="@type"/>
  376. <xsl:text>',</xsl:text>
  377. <xsl:value-of select="@op"/>
  378. <xsl:text>,'</xsl:text>
  379. <xsl:value-of select="@choice"/>
  380. <xsl:text>','</xsl:text>
  381. <xsl:value-of select="eat:query"/>
  382. <xsl:text>',</xsl:text>
  383. <xsl:choose>
  384. <xsl:when test="@required = 'true'">
  385. <xsl:text>true</xsl:text>
  386. </xsl:when>
  387. <xsl:otherwise>
  388. <xsl:text>false</xsl:text>
  389. </xsl:otherwise>
  390. </xsl:choose>
  391. <xsl:text>]</xsl:text>
  392. <xsl:if test="position()!=last()">
  393. <xsl:text>,
  394. </xsl:text>
  395. </xsl:if>
  396. </xsl:template>
  397. </xsl:stylesheet>