edit-meal.xsl 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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="''"/>
  10. <!-- helper vars -->
  11. <xsl:variable name="meal" select="xweb:x-data/xweb:x-model/eat:edit/eat:meal"/>
  12. <xsl:variable name="is-new" select="not(boolean($meal/@mealId))"/>
  13. <xsl:template match="xweb:x-data" mode="page-title">
  14. <xsl:choose>
  15. <xsl:when test="$is-new = 'true'">
  16. <xsl:value-of select="key('i18n','edit-meal.create.title')"/>
  17. </xsl:when>
  18. <xsl:otherwise>
  19. <xsl:value-of select="key('i18n','edit-meal.edit.title')"/>
  20. </xsl:otherwise>
  21. </xsl:choose>
  22. </xsl:template>
  23. <xsl:template match="xweb:x-data" mode="page-head-content">
  24. <script type="text/javascript" src="{$web-context}/js/jquery-1.3.2.js" xml:space="preserve"> </script>
  25. <script type="text/javascript" src="{$web-context}/js/jquery.ajaxQueue.js" xml:space="preserve"> </script>
  26. <script type="text/javascript" src="{$web-context}/js/xweb-locale.js" xml:space="preserve"> </script>
  27. <script type="text/javascript" src="{$web-context}/js/ieat-util.js" xml:space="preserve"> </script>
  28. <script type="text/javascript" src="{$web-context}/js/edit-meal.js" xml:space="preserve"> </script>
  29. <script type="text/javascript">
  30. <xsl:comment>
  31. var msg_setRecipe = '<xsl:value-of select="key('i18n','meal.recipe.change')"/>';
  32. var numRecipes = <xsl:value-of select="count($meal/eat:recipe)"/>;
  33. if ( numRecipes == 0 ) {
  34. numRecipes++;
  35. }
  36. function doChooseRecipe(rowIndex) {
  37. searchForRecipe(webContext,rowIndex);
  38. }
  39. //</xsl:comment>
  40. </script>
  41. </xsl:template>
  42. <xsl:template match="xweb:x-data" mode="page-body">
  43. <div class="intro">
  44. <xsl:choose>
  45. <xsl:when test="$is-new = 'true'">
  46. <xsl:value-of select="key('i18n','edit-meal.create.intro')"/>
  47. </xsl:when>
  48. <xsl:otherwise>
  49. <xsl:value-of select="key('i18n','edit-meal.edit.intro')"/>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. </div>
  53. <form method="post" action="{$web-context}{$ctx/xweb:path}">
  54. <xsl:attribute name="action">
  55. <xsl:value-of select="$web-context"/>
  56. <xsl:choose>
  57. <xsl:when test="$is-new = 'true'">
  58. <xsl:text>/addMeal.do</xsl:text>
  59. </xsl:when>
  60. <xsl:otherwise>
  61. <xsl:text>/editMeal.do</xsl:text>
  62. </xsl:otherwise>
  63. </xsl:choose>
  64. </xsl:attribute>
  65. <table class="form">
  66. <tr>
  67. <th>
  68. <xsl:if test="$err[@field='meal.name']">
  69. <xsl:attribute name="class">error</xsl:attribute>
  70. </xsl:if>
  71. <xsl:value-of select="key('i18n','meal.name.displayName')"/>
  72. </th>
  73. <td>
  74. <input type="text" name="meal.name" value="{$meal/eat:name}"
  75. maxlength="128"/>
  76. <br/>
  77. <span class="caption">
  78. <xsl:value-of select="key('i18n','meal.name.caption')"/>
  79. </span>
  80. </td>
  81. </tr>
  82. </table>
  83. <p>
  84. <xsl:value-of select="key('i18n','meal.recipes.explain')"
  85. disable-output-escaping="yes"/>
  86. </p>
  87. <div class="formLabel">
  88. <xsl:choose>
  89. <xsl:when test="$err[starts-with(@field,'meal.recipe')]">
  90. <span class="error">
  91. <xsl:value-of select="key('i18n','meal.recipes.displayName')"/>
  92. </span>
  93. </xsl:when>
  94. <xsl:otherwise>
  95. <xsl:value-of select="key('i18n','meal.recipes.displayName')"/>:
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </div>
  99. <table class="form" id="recipe_table">
  100. <xsl:for-each select="$meal/eat:recipe">
  101. <xsl:call-template name="meal-recipe"/>
  102. </xsl:for-each>
  103. <xsl:if test="not($meal/eat:recipe)">
  104. <xsl:call-template name="meal-recipe">
  105. <xsl:with-param name="index" select="0"/>
  106. </xsl:call-template>
  107. </xsl:if>
  108. <tr id="recipe_add_row">
  109. <td>
  110. <a href="javascript:addRecipe()"
  111. title="{key('i18n','meal.recipes.add')}" class="plus">
  112. <span class="alt">
  113. <xsl:value-of select="key('i18n','meal.recipes.add')"/>
  114. </span>
  115. </a>
  116. </td>
  117. <td></td>
  118. </tr>
  119. </table>
  120. <hr class="sep"/>
  121. <table class="form">
  122. <tr>
  123. <th/>
  124. <td>
  125. <input type="submit" name="_target1" value="{key('i18n','continue.displayName')}"/>
  126. <xsl:text> </xsl:text>
  127. <input type="submit" name="_cancel" value="{key('i18n','cancel.displayName')}"/>
  128. </td>
  129. </tr>
  130. </table>
  131. </form>
  132. </xsl:template>
  133. <xsl:template name="meal-recipe">
  134. <xsl:param name="index"/>
  135. <xsl:variable name="row-index">
  136. <xsl:choose>
  137. <xsl:when test="string-length($index) &gt; 0">
  138. <xsl:value-of select="$index"/>
  139. </xsl:when>
  140. <xsl:otherwise>
  141. <xsl:value-of select="position() - 1"/>
  142. </xsl:otherwise>
  143. </xsl:choose>
  144. </xsl:variable>
  145. <xsl:variable name="me" select="."/>
  146. <tr valign="middle">
  147. <xsl:if test="not(self::eat:recipe) or position() = 1">
  148. <xsl:attribute name="id">recipe_row</xsl:attribute>
  149. </xsl:if>
  150. <xsl:variable name="errkey">
  151. <xsl:text>meal.recipe[</xsl:text>
  152. <xsl:value-of select="$row-index"/>
  153. <xsl:text>]</xsl:text>
  154. </xsl:variable>
  155. <td>
  156. <xsl:if test="$err[starts-with(@field,$errkey)]">
  157. <span class="error">*</span>
  158. <xsl:text> </xsl:text>
  159. </xsl:if>
  160. <input type="text" name="meal.recipe[{$row-index}].quantity" class="smallnum"
  161. value="{@quantity}" maxlength="8"/>
  162. </td>
  163. <td>
  164. <select name="meal.recipe[{$row-index}].course.courseId">
  165. <option value="0"></option>
  166. <xsl:for-each select="$aux/eat:ui/eat:course">
  167. <xsl:call-template name="recipe-course">
  168. <xsl:with-param name="recipe" select="$me"/>
  169. </xsl:call-template>
  170. </xsl:for-each>
  171. </select>
  172. </td>
  173. <td class="read-only">
  174. <input type="hidden" name="meal.recipe[{$row-index}].recipe.recipeId">
  175. <xsl:attribute name="value">
  176. <xsl:choose>
  177. <xsl:when test="eat:recipe/@recipeId">
  178. <xsl:value-of select="eat:recipe/@recipeId"/>
  179. </xsl:when>
  180. <xsl:otherwise>0</xsl:otherwise>
  181. </xsl:choose>
  182. </xsl:attribute>
  183. </input>
  184. <a id="meal.recipe[{$row-index}].recipe.name" href="javascript:doChooseRecipe({$row-index})">
  185. <xsl:choose>
  186. <xsl:when test="eat:recipe/@recipeId &gt; 0">
  187. <xsl:variable name="recipe-id" select="eat:recipe/@recipeId"></xsl:variable>
  188. <xsl:value-of select="$aux/eat:ui/eat:recipe[@recipeId = $recipe-id]/eat:name"/>
  189. </xsl:when>
  190. <xsl:otherwise>
  191. <span class="hilite">
  192. <xsl:text>(</xsl:text>
  193. <xsl:value-of select="key('i18n','meal.recipe.change')"/>
  194. <xsl:text>)</xsl:text>
  195. </span>
  196. </xsl:otherwise>
  197. </xsl:choose>
  198. </a>
  199. </td>
  200. <td>
  201. <a href="javascript:removeRecipe({$row-index})"
  202. title="{key('i18n','meal.recipes.remove')}" class="minus">
  203. <span class="alt">
  204. <xsl:value-of select="key('i18n','meal.recipes.remove')"/>
  205. </span>
  206. </a>
  207. </td>
  208. </tr>
  209. </xsl:template>
  210. <xsl:template name="recipe-course">
  211. <xsl:param name="recipe"/>
  212. <option value="{@courseId}">
  213. <xsl:if test="@courseId = $recipe/eat:course/@courseId">
  214. <xsl:attribute name="selected">selected</xsl:attribute>
  215. </xsl:if>
  216. <xsl:value-of select="."/>
  217. </option>
  218. </xsl:template>
  219. </xsl:stylesheet>