import-recipe-ingredients.xsl 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 variables -->
  11. <xsl:variable name="originalRecipe" select="$aux/eat:ui/eat:recipe[1]"/>
  12. <xsl:variable name="recipe" select="$aux/eat:ui/eat:recipe[2]"/>
  13. <xsl:template match="xweb:x-data" mode="page-title">
  14. <xsl:value-of select="key('i18n','import-recipe-ingredients.title')"/>
  15. </xsl:template>
  16. <xsl:template match="xweb:x-data" mode="page-head-content">
  17. <link rel="stylesheet" type="text/css" href="{$web-context}/css/edit-recipe.css" media="screen" />
  18. <link rel="stylesheet" type="text/css" href="{$web-context}/css/jquery.autocomplete.css" media="screen" />
  19. <script type="text/javascript" src="{$web-context}/js/jquery-1.3.2.js" xml:space="preserve"> </script>
  20. <script type="text/javascript" src="{$web-context}/js/jquery.ajaxQueue.js" xml:space="preserve"> </script>
  21. <script type="text/javascript" src="{$web-context}/js/jquery.autocomplete.js" xml:space="preserve"> </script>
  22. <script type="text/javascript" src="{$web-context}/js/xweb-locale.js" xml:space="preserve"> </script>
  23. <script type="text/javascript" src="{$web-context}/js/ieat-util.js" xml:space="preserve"> </script>
  24. <script type="text/javascript" src="{$web-context}/js/edit-recipe.js" xml:space="preserve"> </script>
  25. </xsl:template>
  26. <xsl:template match="xweb:x-data" mode="page-body">
  27. <div class="intro">
  28. <xsl:value-of select="key('i18n','import-recipe-ingredients.intro')"/>
  29. </div>
  30. <form method="post" action="{$web-context}{$ctx/xweb:path}">
  31. <table class="form">
  32. <tr>
  33. <th>
  34. <xsl:value-of select="key('i18n','recipe.name.displayName')"/>
  35. </th>
  36. <td>
  37. <xsl:value-of select="$recipe/eat:name"/>
  38. </td>
  39. </tr>
  40. <tr>
  41. <th>
  42. <xsl:if test="$err[@field='recipe.system.systemId']">
  43. <xsl:attribute name="class">error</xsl:attribute>
  44. </xsl:if>
  45. <xsl:value-of select="key('i18n','recipe.system.displayName')"/>
  46. </th>
  47. <td>
  48. <select name="recipe.system.systemId">
  49. <option/>
  50. <xsl:apply-templates select="$aux/eat:ui/eat:system"/>
  51. </select>
  52. </td>
  53. </tr>
  54. </table>
  55. <table class="form" id="ingredient_table">
  56. <xsl:apply-templates select="$recipe/eat:ingredient"/>
  57. </table>
  58. <input type="submit" name="_target2"
  59. value="{key('i18n','continue.displayName')}"/>
  60. <xsl:text> </xsl:text>
  61. <input type="submit" name="_cancel"
  62. value="{key('i18n','cancel.displayName')}"/>
  63. </form>
  64. </xsl:template>
  65. <xsl:template match="eat:recipe/eat:ingredient">
  66. <xsl:variable name="myPosition" select="position()"/>
  67. <xsl:variable name="row-index" select="$myPosition - 1"/>
  68. <xsl:variable name="me" select="."/>
  69. <xsl:variable name="errkey">
  70. <xsl:text>recipe.ingredient[</xsl:text>
  71. <xsl:value-of select="$row-index"/>
  72. <xsl:text>]</xsl:text>
  73. </xsl:variable>
  74. <tr valign="top">
  75. <xsl:attribute name="class">
  76. <xsl:text>recipe-ingredient</xsl:text>
  77. <xsl:if test="($myPosition mod 2) = 0">
  78. <xsl:text> even</xsl:text>
  79. </xsl:if>
  80. </xsl:attribute>
  81. <th rowspan="2">
  82. <xsl:value-of select="$myPosition"/>
  83. </th>
  84. <td>
  85. <i>
  86. <xsl:value-of select="key('i18n','imported-ingredient-original-value.displayName')"/>
  87. <xsl:text>: </xsl:text>
  88. </i>
  89. </td>
  90. <td>
  91. <xsl:value-of select="$originalRecipe/eat:ingredient[$myPosition]/@quantity"/>
  92. </td>
  93. <td>
  94. <xsl:value-of select="$originalRecipe/eat:ingredient[$myPosition]/eat:unit"/>
  95. </td>
  96. <td>
  97. <xsl:value-of select="$originalRecipe/eat:ingredient[$myPosition]/eat:ingredient"/>
  98. </td>
  99. <td>
  100. <xsl:value-of select="$originalRecipe/eat:ingredient[$myPosition]/@qualifier"/>
  101. </td>
  102. </tr>
  103. <tr>
  104. <xsl:if test="($myPosition mod 2) = 0">
  105. <xsl:attribute name="class">even</xsl:attribute>
  106. </xsl:if>
  107. <td>
  108. <i>
  109. <xsl:choose>
  110. <xsl:when test="$err[starts-with(@field,$errkey)]">
  111. <span class="error">
  112. <b>
  113. <xsl:value-of
  114. select="key('i18n','imported-ingredient-imported-value.displayName')"/>
  115. <xsl:text>: </xsl:text>
  116. </b>
  117. </span>
  118. </xsl:when>
  119. <xsl:otherwise>
  120. <xsl:value-of
  121. select="key('i18n','imported-ingredient-imported-value.displayName')"/>
  122. <xsl:text>: </xsl:text>
  123. </xsl:otherwise>
  124. </xsl:choose>
  125. </i>
  126. </td>
  127. <td>
  128. <input type="text" name="recipe.ingredient[{$row-index}].quantity" class="smallnum"
  129. value="{@quantity}" maxlength="8"/>
  130. </td>
  131. <td>
  132. <select name="recipe.ingredient[{$row-index}].unit.unitId">
  133. <option value="0"></option>
  134. <xsl:call-template name="recipe-ingredient">
  135. <xsl:with-param name="ingredient" select="."/>
  136. </xsl:call-template>
  137. </select>
  138. </td>
  139. <td>
  140. <a class="ingredient-type-chooser ingredient" href="#"
  141. title="Click to use a recipe for this ingredient">
  142. <xsl:attribute name="class">
  143. <xsl:text>ingredient-type-chooser </xsl:text>
  144. <xsl:choose>
  145. <xsl:when test="eat:recipe/@recipeId">
  146. <xsl:text>recipe</xsl:text>
  147. </xsl:when>
  148. <xsl:otherwise>
  149. <xsl:text>ingredient</xsl:text>
  150. </xsl:otherwise>
  151. </xsl:choose>
  152. </xsl:attribute>
  153. <xsl:attribute name="title">
  154. <xsl:choose>
  155. <xsl:when test="eat:recipe/@recipeId">
  156. <xsl:value-of select="key('i18n','edit.recipe.ingredientTypeChooser.recipe.title')"/>
  157. </xsl:when>
  158. <xsl:otherwise>
  159. <xsl:value-of select="key('i18n','edit.recipe.ingredientTypeChooser.ingredient.title')"/>
  160. </xsl:otherwise>
  161. </xsl:choose>
  162. </xsl:attribute>
  163. <span class="alt">
  164. <xsl:value-of select="key('i18n','ingredient.type.chooser.displayName')"/>
  165. </span>
  166. </a>
  167. <div id="recipe.ingredient[{$row-index}].ingredient">
  168. <xsl:attribute name="style">
  169. <xsl:text>float: left;</xsl:text>
  170. <xsl:if test="eat:recipe/@recipeId">
  171. <xsl:text> display: none;</xsl:text>
  172. </xsl:if>
  173. </xsl:attribute>
  174. <input type="text"
  175. name="recipe.ingredient[{$row-index}].ingredient.name"
  176. id="recipe.ingredient[{$row-index}].ingredient.name"
  177. class="ingredient-autocomplete">
  178. <xsl:choose>
  179. <xsl:when test="eat:recipe/@recipeId">
  180. <xsl:attribute name="disabled">
  181. <xsl:text>disabled</xsl:text>
  182. </xsl:attribute>
  183. </xsl:when>
  184. <xsl:otherwise>
  185. <xsl:attribute name="value">
  186. <xsl:value-of select="eat:ingredient/eat:name"/>
  187. </xsl:attribute>
  188. </xsl:otherwise>
  189. </xsl:choose>
  190. </input>
  191. <input type="hidden"
  192. name="recipe.ingredient[{$row-index}].ingredient.ingredientId"
  193. id="recipe.ingredient[{$row-index}].ingredient.ingredientId">
  194. <xsl:choose>
  195. <xsl:when test="eat:recipe/@recipeId">
  196. <xsl:attribute name="disabled">
  197. <xsl:text>disabled</xsl:text>
  198. </xsl:attribute>
  199. </xsl:when>
  200. <xsl:otherwise>
  201. <xsl:attribute name="value">
  202. <xsl:value-of select="eat:ingredient/@ingredientId"/>
  203. </xsl:attribute>
  204. </xsl:otherwise>
  205. </xsl:choose>
  206. </input>
  207. </div>
  208. <div id="recipe.ingredient[{$row-index}].recipe">
  209. <xsl:attribute name="style">
  210. <xsl:text>float: left;</xsl:text>
  211. <xsl:if test="not(eat:recipe/@recipeId)">
  212. <xsl:text> display: none;</xsl:text>
  213. </xsl:if>
  214. </xsl:attribute>
  215. <input type="text"
  216. name="recipe.ingredient[{$row-index}].recipe.name"
  217. id="recipe.ingredient[{$row-index}].recipe.name"
  218. class="recipe-autocomplete">
  219. <xsl:choose>
  220. <xsl:when test="eat:recipe/@recipeId">
  221. <xsl:attribute name="value">
  222. <xsl:value-of select="eat:recipe/eat:name"/>
  223. </xsl:attribute>
  224. </xsl:when>
  225. <xsl:otherwise>
  226. <xsl:attribute name="disabled">
  227. <xsl:text>disabled</xsl:text>
  228. </xsl:attribute>
  229. </xsl:otherwise>
  230. </xsl:choose>
  231. </input>
  232. <input type="hidden"
  233. name="recipe.ingredient[{$row-index}].recipe.recipeId"
  234. id="recipe.ingredient[{$row-index}].recipe.recipeId">
  235. <xsl:choose>
  236. <xsl:when test="eat:recipe/@recipeId">
  237. <xsl:attribute name="value">
  238. <xsl:value-of select="eat:recipe/@recipeId"/>
  239. </xsl:attribute>
  240. </xsl:when>
  241. <xsl:otherwise>
  242. <xsl:attribute name="disabled">
  243. <xsl:text>disabled</xsl:text>
  244. </xsl:attribute>
  245. </xsl:otherwise>
  246. </xsl:choose>
  247. </input>
  248. </div>
  249. </td>
  250. <td>
  251. <input type="text" name="recipe.ingredient[{$row-index}].qualifier"
  252. value="{@qualifier}" maxlength="128"/>
  253. </td>
  254. </tr>
  255. </xsl:template>
  256. <xsl:template match="eat:system">
  257. <option value="{@systemId}">
  258. <xsl:if test="@systemId = $recipe/eat:system/@systemId">
  259. <xsl:attribute name="selected">selected</xsl:attribute>
  260. </xsl:if>
  261. <xsl:value-of select="."/>
  262. </option>
  263. </xsl:template>
  264. <xsl:template name="ingredient-ingredient">
  265. <xsl:param name="ingredient"/>
  266. <option value="{@ingredientId}">
  267. <xsl:if test="@ingredientId = $ingredient/eat:ingredient/@ingredientId">
  268. <xsl:attribute name="selected">selected</xsl:attribute>
  269. </xsl:if>
  270. <xsl:value-of select="eat:name"/>
  271. </option>
  272. </xsl:template>
  273. <xsl:template name="recipe-ingredient">
  274. <xsl:param name="ingredient"/>
  275. <xsl:for-each select="$aux/eat:ui/eat:unit">
  276. <option value="{@unitId}">
  277. <xsl:if test="(@unitId = $ingredient/eat:unit/@unitId)
  278. or (@abbreviation = $ingredient/eat:unit/@abbreviation)">
  279. <xsl:attribute name="selected">selected</xsl:attribute>
  280. </xsl:if>
  281. <xsl:value-of select="."/>
  282. </option>
  283. </xsl:for-each>
  284. </xsl:template>
  285. </xsl:stylesheet>