global.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. <xsl:import href="global-variables.xsl"/>
  7. <xsl:import href="util.xsl"/>
  8. <xsl:output method="html" omit-xml-declaration="yes"/>
  9. <xsl:template name="error-intro">
  10. <xsl:param name="errors-node"/>
  11. <xsl:if test="$errors-node/xweb:error">
  12. <div class="error-intro">
  13. <xsl:if test="$errors-node/xweb:error[not(@field)]">
  14. <!--<xsl:value-of select="$messages[@key='global.error.intro']"/>
  15. <xsl:text> </xsl:text>-->
  16. <xsl:apply-templates select="$errors-node/xweb:error[not(@field)]"/>
  17. </xsl:if>
  18. <xsl:if test="$errors-node/xweb:error[@field]">
  19. <xsl:value-of select="key('i18n','field.error.intro')"/>
  20. <ul>
  21. <xsl:for-each select="$errors-node/xweb:error[@field]">
  22. <li><xsl:value-of select="."/></li>
  23. </xsl:for-each>
  24. </ul>
  25. </xsl:if>
  26. </div>
  27. </xsl:if>
  28. </xsl:template>
  29. <!--
  30. Global Nav template
  31. Global vars:
  32. acting-user: the logged in user, if logged in
  33. web-context: the web context
  34. -->
  35. <xsl:template name="global-nav">
  36. <xsl:param name="page"/>
  37. <div class="nav-banner">
  38. <xsl:if test="$acting-user or key('appenv','feature.anonymous') = 'true'">
  39. <xsl:choose>
  40. <xsl:when test="$page = 'home'">
  41. <xsl:value-of select="key('i18n','link.home')"/>
  42. </xsl:when>
  43. <xsl:otherwise>
  44. <a href="{$web-context}/home.do" title="{key('i18n','link.home.title')}">
  45. <xsl:value-of select="key('i18n','link.home')"/>
  46. </a>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. <xsl:text> - </xsl:text>
  50. <xsl:choose>
  51. <xsl:when test="$page = 'index'">
  52. <xsl:value-of select="key('i18n','link.recipe.index')"/>
  53. </xsl:when>
  54. <xsl:otherwise>
  55. <a href="{$web-context}/index.do" title="{key('i18n','link.recipe.index.title')}">
  56. <xsl:value-of select="key('i18n','link.recipe.index')"/>
  57. </a>
  58. </xsl:otherwise>
  59. </xsl:choose>
  60. <xsl:text> - </xsl:text>
  61. <xsl:choose>
  62. <xsl:when test="$page = 'search'">
  63. <xsl:value-of select="key('i18n','link.recipe.search')"/>
  64. </xsl:when>
  65. <xsl:otherwise>
  66. <a href="{$web-context}/search.do" title="{key('i18n','link.recipe.search.title')}">
  67. <xsl:value-of select="key('i18n','link.recipe.search')"/>
  68. </a>
  69. </xsl:otherwise>
  70. </xsl:choose>
  71. </xsl:if>
  72. <xsl:if test="$acting-user">
  73. <xsl:text> - </xsl:text>
  74. <xsl:choose>
  75. <xsl:when test="$page = 'add-recipe'">
  76. <xsl:value-of select="key('i18n','link.recipe.add')"/>
  77. </xsl:when>
  78. <xsl:otherwise>
  79. <a href="{$web-context}/addRecipe.do" title="{key('i18n','link.recipe.add.title')}">
  80. <xsl:value-of select="key('i18n','link.recipe.add')"/>
  81. </a>
  82. </xsl:otherwise>
  83. </xsl:choose>
  84. <xsl:text> - </xsl:text>
  85. <xsl:choose>
  86. <xsl:when test="$page = 'meals'">
  87. <xsl:value-of select="key('i18n','link.meals')"/>
  88. </xsl:when>
  89. <xsl:otherwise>
  90. <a href="{$web-context}/meals.do" title="{key('i18n','link.meals.title')}">
  91. <xsl:value-of select="key('i18n','link.meals')"/>
  92. </a>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. </xsl:if>
  96. <xsl:if test="$acting-user or key('appenv','feature.anonymous') = 'true'">
  97. <xsl:text> - </xsl:text>
  98. </xsl:if>
  99. <xsl:choose>
  100. <xsl:when test="$acting-user">
  101. <xsl:if test="$acting-user/../@admin = 'true'">
  102. <xsl:choose>
  103. <xsl:when test="$page = 'admin-home'">
  104. <xsl:value-of select="key('i18n','link.admin')"/>
  105. </xsl:when>
  106. <xsl:otherwise>
  107. <a href="{$web-context}/admin.do" title="{key('i18n','link.admin.title')}">
  108. <xsl:value-of select="key('i18n','link.admin')"/>
  109. </a>
  110. </xsl:otherwise>
  111. </xsl:choose>
  112. <xsl:text> - </xsl:text>
  113. </xsl:if>
  114. <a href="{$web-context}/logoff.do" title="{key('i18n','link.logout.title')}">
  115. <xsl:value-of select="key('i18n','link.logout')"/>
  116. </a>
  117. <xsl:text> (</xsl:text>
  118. <xsl:value-of select="$acting-user/eat:name"/>
  119. <xsl:text>)</xsl:text>
  120. </xsl:when>
  121. <xsl:when test="$page = 'logon'">
  122. <xsl:value-of select="key('i18n','link.logon')"/>
  123. </xsl:when>
  124. <xsl:otherwise>
  125. <a href="{$web-context}/logon.do" title="{key('i18n','link.logon.title')}">
  126. <xsl:value-of select="key('i18n','link.logon')"/>
  127. </a>
  128. </xsl:otherwise>
  129. </xsl:choose>
  130. </div>
  131. </xsl:template>
  132. <!--
  133. Search results hidden form element templates.
  134. -->
  135. <xsl:template match="eat:search-results" mode="search-results-contextual-navigation">
  136. <xsl:if test="@pageSize &gt; 0">
  137. <input type="hidden" name="searchResults.pageSize" value="{@pageSize}"/>
  138. </xsl:if>
  139. <xsl:if test="@pageStart &gt; 0">
  140. <input type="hidden" name="searchResults.pageStart" value="{@pageStart}"/>
  141. </xsl:if>
  142. <xsl:apply-templates select="eat:ui-index/eat:index-section[@selected='true']"
  143. mode="search-results-contextual-navigation"/>
  144. <xsl:apply-templates select="eat:recipe-criteria"
  145. mode="search-results-contextual-navigation"/>
  146. </xsl:template>
  147. <xsl:template match="eat:ui-index/eat:index-section" mode="search-results-contextual-navigation">
  148. <input type="hidden" name="searchResults.uiIndex.indexSection[{position() - 1}].indexKey"
  149. value="{@index-key}"/>
  150. </xsl:template>
  151. <xsl:template match="eat:recipe-criteria" mode="search-results-contextual-navigation">
  152. <input type="hidden" name="searchResults.criteria.mode" value="{@mode}"/>
  153. <xsl:if test="eat:simpleQuery">
  154. <input type="hidden" name="searchResults.criteria.simpleQuery"
  155. value="{eat:simpleQuery}"/>
  156. </xsl:if>
  157. </xsl:template>
  158. <xsl:template match="eat:search-results" mode="contextual-navigation">
  159. <xsl:if test="@pageSize &gt; 0">
  160. <input type="hidden" name="index.pageSize" value="{@pageSize}"/>
  161. </xsl:if>
  162. <xsl:if test="@pageStart &gt; 0">
  163. <input type="hidden" name="index.pageStart" value="{@pageStart}"/>
  164. </xsl:if>
  165. <xsl:apply-templates select="eat:ui-index/eat:index-section[@selected='true']"
  166. mode="contextual-navigation"/>
  167. <xsl:apply-templates select="eat:recipe-criteria" mode="contextual-navigation"/>
  168. </xsl:template>
  169. <xsl:template match="eat:ui-index/eat:index-section" mode="contextual-navigation">
  170. <input type="hidden" name="index.displaySection" value="{@index-key}"/>
  171. </xsl:template>
  172. <xsl:template match="eat:recipe-criteria" mode="contextual-navigation">
  173. <input type="hidden" name="criteria.mode" value="{@mode}"/>
  174. <xsl:if test="eat:simpleQuery">
  175. <input type="hidden" name="criteria.simpleQuery" value="{eat:simpleQuery}"/>
  176. </xsl:if>
  177. </xsl:template>
  178. <!--
  179. Render index page navigation
  180. -->
  181. <xsl:template name="render-ui-index">
  182. <xsl:param name="ui-index"/>
  183. <xsl:param name="link"/>
  184. <table class="recipe-index">
  185. <tbody>
  186. <tr>
  187. <xsl:for-each select="$ui-index/eat:index-section">
  188. <xsl:call-template name="render-index-section">
  189. <xsl:with-param name="index-section" select="."/>
  190. <xsl:with-param name="link" select="$link"/>
  191. </xsl:call-template>
  192. </xsl:for-each>
  193. </tr>
  194. </tbody>
  195. </table>
  196. </xsl:template>
  197. <xsl:template name="render-index-section">
  198. <xsl:param name="index-section"/>
  199. <xsl:param name="link"/>
  200. <td>
  201. <xsl:if test="$index-section/@selected">
  202. <xsl:attribute name="class">selected</xsl:attribute>
  203. </xsl:if>
  204. <xsl:choose>
  205. <xsl:when test="$index-section/@selected">
  206. <xsl:value-of select="$index-section/@index-key"/>
  207. </xsl:when>
  208. <xsl:otherwise>
  209. <a>
  210. <xsl:attribute name="href">
  211. <xsl:value-of select="$web-context"/>
  212. <xsl:value-of select="$link"/>
  213. <xsl:text>?displaySection=</xsl:text>
  214. <xsl:value-of select="$index-section/@index-key"/>
  215. <xsl:if test="not($index-section/../../@pageSize = $index-section/../../eat:pagination/@defaultPageSize)">
  216. <xsl:text>&amp;pageSize=</xsl:text>
  217. <xsl:value-of select="$index-section/../../@pageSize"/>
  218. </xsl:if>
  219. </xsl:attribute>
  220. <xsl:value-of select="$index-section/@index-key"/>
  221. </a>
  222. </xsl:otherwise>
  223. </xsl:choose>
  224. <xsl:text> (</xsl:text>
  225. <xsl:value-of select="$index-section/@count"/>
  226. <xsl:text>)</xsl:text>
  227. </td>
  228. </xsl:template>
  229. <xsl:template name="render-index-navigation">
  230. <xsl:param name="search-results"/>
  231. <xsl:param name="curr-page" select="0"/>
  232. <xsl:param name="max-page"/>
  233. <xsl:param name="link"/>
  234. <xsl:if test="$curr-page &gt; 0">
  235. <xsl:text> - </xsl:text>
  236. </xsl:if>
  237. <xsl:choose>
  238. <xsl:when test="$search-results/@pageStart = $curr-page">
  239. <span class="selected-page">
  240. <xsl:value-of select="$curr-page + 1"/>
  241. </span>
  242. </xsl:when>
  243. <xsl:otherwise>
  244. <a>
  245. <xsl:attribute name="href">
  246. <xsl:value-of select="$web-context"/>
  247. <xsl:value-of select="$link"/>
  248. <xsl:text>?displaySection=</xsl:text>
  249. <xsl:value-of select="$search-results/eat:ui-index/eat:index-section[@selected]/@index-key"/>
  250. <xsl:text>&amp;pageSize=</xsl:text>
  251. <xsl:value-of select="$search-results/@pageSize"/>
  252. <xsl:if test="$curr-page &gt; 0">
  253. <xsl:text>&amp;pageStart=</xsl:text>
  254. <xsl:value-of select="$curr-page"/>
  255. </xsl:if>
  256. </xsl:attribute>
  257. <xsl:value-of select="$curr-page + 1"/>
  258. </a>
  259. </xsl:otherwise>
  260. </xsl:choose>
  261. <xsl:if test="$curr-page &lt; ($max-page - 1)">
  262. <xsl:call-template name="render-index-navigation">
  263. <xsl:with-param name="search-results" select="$search-results"/>
  264. <xsl:with-param name="curr-page" select="$curr-page + 1"/>
  265. <xsl:with-param name="max-page" select="$max-page"/>
  266. <xsl:with-param name="link" select="$link"/>
  267. </xsl:call-template>
  268. </xsl:if>
  269. </xsl:template>
  270. <xsl:template match="eat:search-results" mode="render-index-pagination-menu">
  271. <xsl:if test="eat:pagination/eat:allowablePageSize">
  272. <div class="pagination">
  273. <form action="{$web-context}{$ctx/xweb:path}" method="post">
  274. <xsl:value-of select="key('i18n','pagination.size.displayName')"/>
  275. <xsl:text>: </xsl:text>
  276. <select name="pageSize" id="pagination-select">
  277. <xsl:for-each select="eat:pagination/eat:allowablePageSize">
  278. <option value="{.}">
  279. <xsl:if test="string(.) = ../../@pageSize">
  280. <xsl:attribute name="selected">selected</xsl:attribute>
  281. </xsl:if>
  282. <xsl:value-of select="."/>
  283. </option>
  284. </xsl:for-each>
  285. <xsl:if test="eat:pagination/@allowUnlimited = 'true'">
  286. <option value="-1">
  287. <xsl:if test="'-1' = ../../@pageSize">
  288. <xsl:attribute name="selected">selected</xsl:attribute>
  289. </xsl:if>
  290. <xsl:value-of select="key('i18n','unlimited')"/>
  291. </option>
  292. </xsl:if>
  293. <xsl:apply-templates select="eat:allowablePageSize"></xsl:apply-templates>
  294. </select>
  295. <input type="hidden" name="pageStart" value="0"/>
  296. <input type="hidden" name="displaySection"
  297. value="{eat:ui-index/eat:index-section[@selected='true']/@index-key}"/>
  298. </form>
  299. </div>
  300. </xsl:if>
  301. </xsl:template>
  302. <xsl:template match="eat:index-section" mode="href">
  303. <xsl:text>&amp;index.displaySection=</xsl:text>
  304. <xsl:value-of select="@index-key"/>
  305. <xsl:if test="../../@pageSize">
  306. <xsl:text>&amp;index.pageSize=</xsl:text>
  307. <xsl:value-of select="../../@pageSize"/>
  308. </xsl:if>
  309. <xsl:if test="../../@pageStart &gt; 0">
  310. <xsl:text>&amp;index.pageStart=</xsl:text>
  311. <xsl:value-of select="../../@pageStart"/>
  312. </xsl:if>
  313. </xsl:template>
  314. <xsl:template match="eat:index-section" mode="href-direct">
  315. <xsl:text>&amp;displaySection=</xsl:text>
  316. <xsl:value-of select="@index-key"/>
  317. <xsl:if test="../../@pageSize">
  318. <xsl:text>&amp;pageSize=</xsl:text>
  319. <xsl:value-of select="../../@pageSize"/>
  320. </xsl:if>
  321. <xsl:if test="../../@pageStart &gt; 0">
  322. <xsl:text>&amp;pageStart=</xsl:text>
  323. <xsl:value-of select="../../@pageStart"/>
  324. </xsl:if>
  325. </xsl:template>
  326. <xsl:template match="eat:recipe-criteria" mode="href">
  327. <xsl:text>&amp;criteria.mode=</xsl:text>
  328. <xsl:value-of select="@mode"/>
  329. </xsl:template>
  330. <!--
  331. Search for recipes form template
  332. -->
  333. <xsl:template match="xweb:x-data" mode="search-for-recipes">
  334. <xsl:variable name="rCriteria" select="xweb:x-model/eat:search-results/eat:recipe-criteria"/>
  335. <form method="post" action="{$web-context}{$ctx/xweb:path}">
  336. <table class="form">
  337. <tr>
  338. <th>
  339. <xsl:value-of select="key('i18n','name.displayName')"/>
  340. </th>
  341. <td colspan="3">
  342. <input type="text" name="criteria.name" value="{$rCriteria/eat:name}"/>
  343. </td>
  344. </tr>
  345. <tr>
  346. <th/>
  347. <td>
  348. <input type="submit" value="{key('i18n','search.displayName')}"/>
  349. <xsl:text> </xsl:text>
  350. <input type="submit" name="_cancel" value="{key('i18n','cancel.displayName')}"/>
  351. </td>
  352. </tr>
  353. </table>
  354. <input type="hidden" name="mode" value="{xweb:x-model/eat:search-results/@mode}"/>
  355. </form>
  356. <script type="text/javascript" xml:space="preserve">
  357. document.forms[0].elements['criteria.name'].focus();
  358. </script>
  359. <xsl:if test="xweb:x-model/eat:search-results/eat:recipe-criteria">
  360. <xsl:apply-templates select="xweb:x-model/eat:search-results" mode="search-for-recipes"/>
  361. </xsl:if>
  362. </xsl:template>
  363. <xsl:template match="eat:search-results" mode="search-for-recipes">
  364. <hr />
  365. <xsl:choose>
  366. <xsl:when test="@totalResults &gt; 0">
  367. <table class="recipe-index">
  368. <tbody>
  369. <tr>
  370. <th>
  371. <xsl:value-of select="key('i18n','search.results.results')"/>
  372. <xsl:text>: </xsl:text>
  373. <xsl:value-of select="@totalResults"/>
  374. <xsl:text> </xsl:text>
  375. <xsl:choose>
  376. <xsl:when test="@totalResults &gt; 1">
  377. <xsl:value-of select="key('i18n','search.results.match.plural')"/>
  378. </xsl:when>
  379. <xsl:otherwise>
  380. <xsl:value-of select="key('i18n','search.results.match')"/>
  381. </xsl:otherwise>
  382. </xsl:choose>
  383. </th>
  384. </tr>
  385. </tbody>
  386. </table>
  387. <ol>
  388. <xsl:apply-templates select="eat:recipe" mode="search-for-recipes"/>
  389. </ol>
  390. </xsl:when>
  391. <xsl:otherwise>
  392. <p>
  393. <xsl:value-of select="key('i18n','search.noresults')"/>
  394. </p>
  395. </xsl:otherwise>
  396. </xsl:choose>
  397. </xsl:template>
  398. <xsl:template match="eat:recipe" mode="search-for-recipes">
  399. <li>
  400. <a>
  401. <xsl:attribute name="href">
  402. <xsl:text>javascript:chooseRecipe(</xsl:text>
  403. <xsl:value-of select="@recipeId"/>
  404. <xsl:text>,'</xsl:text>
  405. <xsl:call-template name="single-quote-string">
  406. <xsl:with-param name="output-string" select="eat:name"/>
  407. </xsl:call-template>
  408. <xsl:text>')</xsl:text>
  409. </xsl:attribute>
  410. <xsl:value-of select="eat:name"/>
  411. </a>
  412. <p>
  413. <xsl:call-template name="truncate-at-word">
  414. <xsl:with-param name="text" select="eat:excerpt"/>
  415. <xsl:with-param name="max-length" select="100"/>
  416. </xsl:call-template>
  417. </p>
  418. </li>
  419. </xsl:template>
  420. </xsl:stylesheet>