<?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"/>
	<xsl:import href="tmpl/display-user.xsl"/>
	
	<!-- layout variables -->
	<xsl:variable name="layout.global.nav.page" select="''"/>
	
	<!-- helper vars -->
	<xsl:variable name="user" select="xweb:x-data/xweb:x-model/eat:edit/eat:user"/>
	<xsl:variable name="is-new" select="not(boolean($user/@userId))"/>
	
	<xsl:template match="xweb:x-data" mode="page-title">
		<xsl:choose>
			<xsl:when test="$is-new = 'true'">
				<xsl:value-of select="key('i18n','edit-user.create.title')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="key('i18n','edit-user.edit.title')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="xweb:x-data" mode="page-intro">
		<xsl:choose>
			<xsl:when test="$is-new = 'true'">
	            <xsl:value-of select="key('i18n','edit-user.create.intro')"/>
			</xsl:when>
			<xsl:otherwise>
	            <xsl:value-of select="key('i18n','edit-user.edit.intro')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="xweb:x-data" mode="page-body">
		<xsl:apply-templates select="." mode="page-intro"/>
        
		<form method="post" action="{$web-context}{$ctx/xweb:path}">
			<table class="form">
				<xsl:apply-templates select="$user" mode="edit"/>
				<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>
			<!-- handle contextual navigation -->
			<xsl:apply-templates select="eat:edit/eat:search-results" 
				mode="search-results-contextual-navigation"/>
		</form>
		<script type="text/javascript" xml:space="preserve">
			<xsl:comment>
			document.forms[0].elements['user.name'].focus();
			//</xsl:comment>
		</script>
    </xsl:template>
    
</xsl:stylesheet>
