<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:eat="http://msqr.us/xsd/ieat"
	xmlns:xweb="http://msqr.us/xsd/jaxb-web"
	exclude-result-prefixes="eat xweb">
	
    <!-- imports -->
	<xsl:import href="tmpl/default-layout.xsl"/>
	
	<!-- layout variables -->
	<xsl:variable name="layout.global.nav.page" select="''"/>
	
	<!-- helper vars -->
	<xsl:variable name="ingredient" select="xweb:x-data/xweb:x-model/eat:edit/eat:ingredient"/>
	<xsl:variable name="is-new" select="boolean($ingredient/@ingredientId)"/>

	<xsl:template match="xweb:x-data" mode="page-title">
		<xsl:choose>
			<xsl:when test="$is-new = 'false'">
				<xsl:value-of select="key('i18n','edit-ingredient.edit.title')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="key('i18n','edit-ingredient.create.title')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="xweb:x-data" mode="page-global-nav"/>
	
	<xsl:template match="xweb:x-data" mode="page-head-content">
		<script type="text/javascript" src="{$web-context}/js/jquery-1.3.2.js" xml:space="preserve"> </script>
		<script type="text/javascript" src="{$web-context}/js/xweb-locale.js" xml:space="preserve"> </script>
		<script type="text/javascript" src="{$web-context}/js/ieat-util.js" xml:space="preserve"> </script>
		<script type="text/javascript" src="{$web-context}/js/edit-recipe.js" xml:space="preserve"> </script>
	</xsl:template>
	
	<xsl:template match="xweb:x-data" mode="page-body">
        <div class="intro">
			<xsl:choose>
				<xsl:when test="$is-new = 'false'">
                		<xsl:value-of select="key('i18n','edit-ingredient.edit.intro')"/>
				</xsl:when>
				<xsl:otherwise>
                		<xsl:value-of select="key('i18n','edit-ingredient.create.intro')"/>
				</xsl:otherwise>
			</xsl:choose>
        </div>
        
		<form method="post" action="{$web-context}{$ctx/xweb:path}">
			<input type="hidden" name="ignoreWarnings" value="false"/>
                <xsl:if test="$is-new = 'false'">
                	<input type="hidden" name="ingredient.ingredientId" value="{$ingredient/@ingredientId}"/>
                </xsl:if>
			<table class="form">
				<tr>
					<th>
						<xsl:if test="$err[@field='ingredient.name']">
							<xsl:attribute name="class">error</xsl:attribute>
						</xsl:if>
						<xsl:value-of select="key('i18n','name.displayName')"/>
					</th>
					<td colspan="3">
						<input type="text" name="ingredient.name" value="{$ingredient/eat:name}"/>
					</td>
				</tr>
				<tr>
					<th>
						<xsl:if test="$err[@field='ingredient.description']">
							<xsl:attribute name="class">error</xsl:attribute>
						</xsl:if>
						<xsl:value-of select="key('i18n','description.displayName')"/>
					</th>
					<td colspan="3">
						<input type="text" name="ingredient.description" 
							value="{$ingredient/eat:description}"/>
					</td>
				</tr>
				<xsl:if test="xweb:x-model/eat:edit/@ignoreWarnings = 'true' and $err[@field='ingredient.name']">
					<tr>
						<th>
							<xsl:value-of select="key('i18n','ingredient.ignoreWarnings.displayName')"/>
						</th>
						<td>
							<input type="checkbox" onclick="handleChangeIgnoreWarnings(this)"/>
							<xsl:text> </xsl:text>
							<span class="caption">
								<xsl:value-of select="key('i18n','edit-ingredient.ignoreWarnings.caption')"/>
							</span>
						</td>
					</tr>
				</xsl:if>
				<tr>
					<th/>
					<td>
						<input type="submit" name="_target1" value="{key('i18n','continue.displayName')}"/>
						<xsl:text> </xsl:text>
						<input type="submit" name="_cancel" value="{key('i18n','cancel.displayName')}"/>
					</td>
				</tr>
			</table>
		</form>
		<script type="text/javascript" xml:space="preserve">
			<xsl:comment>
			document.forms[0].elements['ingredient.name'].focus();
			//</xsl:comment>
		</script>
    </xsl:template>
    
    <xsl:template match="eat:ui/eat:ingredient">
	    	<option value="{@ingredientId}">
	    		<xsl:value-of select="."/>
	    	</option>
    </xsl:template>
    
</xsl:stylesheet>
