<?xml-stylesheet href="../../xsltforms/xsltforms.xsl" type="text/xsl"?>
<?xsltforms-options debug="no"?>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://www.w3.org/1999/xhtml" 
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:math="http://exslt.org/math"
>
<head>
   <title>Process improvement</title>
   <style type="text/css">
      body {font-family: sans-serif; margin-left: 2em; max-width: 40em;}
      .xforms-label {display: inline-block; font-weight: bold;}
      .xforms-group {}
      .xforms-group > .xforms-label {background-color: blue; color: white; padding-left: 1em; padding-right: 1em; margin-bottom: 1em; margin-top: 1em; width: 40em;}
      .xforms-textarea {display: block; width: 40em;}
      .xforms-textarea > .xforms-label{display: block; width: 40em;}
      .xforms-select, .xforms-select1 {display: block}
      .case, .more {border-left: 1em solid #66f; padding-left: 1em; }
      .xforms-submit, .xforms-trigger {display: block}
      textarea{width: 35em; height: 4em; font-family: serif;}
      .text {font-style: italic; margin-bottom: 1em; display: block}
      .lang {float: right}
   </style>
   <model xmlns="http://www.w3.org/2002/xforms">

      <instance id="data" src="data.xml"/>
      <bind ref="answer" relevant="@choice=../choice"/>
      <submission id="restart" method="get" resource="data.xml"
		  replace="instance" instance="data"/>

      <instance id="admin">
	 <admin xmlns="">
	    <submit/>
	    <submitted/>
	    <thanks/>
	 </admin>
      </instance>
      <bind ref="instance('admin')/submit" relevant="instance('data')/choice != '' and ../submitted!='yes'"/>
      <bind ref="instance('admin')/thanks" relevant="../submitted='yes'"/>


      <instance id="m" src="lang-en.xml"/>
      <submission id="change-language" replace="instance" instance="m" method="get">
	<resource value="concat('lang-', lang, '.xml')"/>
      </submission>

      <instance id="languages" src="languages.xml"/>
      
</model>
</head>
<body>
<group xmlns="http://www.w3.org/2002/xforms">
   <label><output ref="instance('m')/label"/></label>

   <select1 class="lang" ref="lang">
      <label>🗨</label>
      <itemset ref="instance('languages')/item"><label ref="."/><value ref="@code"/></itemset>
      <action ev:event="xforms-value-changed">
	<send submission="change-language"/>
      </action>
   </select1>

   <output ref="instance('m')/intro"/>

   <select1 ref="choice" appearance="full">
      <label ref="instance('m')/choice"/>
      <itemset ref="instance('m')/answer"><label ref="label"/><value ref="@choice"/></itemset>
   </select1>

   <group ref="answer[@choice=../choice]">
      <label><output ref="instance('m')/answer[@choice=context()/@choice]/label"/></label>
      <textarea ref="problem"><label ref="instance('m')/answer[@choice=context()/../@choice]/problem"/></textarea>
      <select1 ref="likely">
	 <label ref="instance('m')/answer[@choice=context()/../@choice]/likely/label"/>
	 <itemset ref="instance('m')/answer[@choice=context()/../@choice]/likely/item">
	    <label ref="."/><value ref="@value"/>
	 </itemset>
      </select1>
      <textarea ref="who"><label ref="instance('m')/answer[@choice=context()/../@choice]/who"/></textarea>
      <textarea ref="solution"><label ref="instance('m')/answer[@choice=context()/../@choice]/solution"/></textarea>
   </group>

   <trigger ref="instance('admin')/submit">
      <label ref="instance('m')/submit"/>
      <action ev:event="DOMActivate">
	 <setvalue ref="instance('admin')/submitted" value="'yes'"/>
      </action>
   </trigger>

   <group ref="instance('admin')/thanks">
      <label><output ref="instance('m')/thanks"/></label>
      <trigger>
	 <label ref="instance('m')/another"/>
	 <action ev:event="DOMActivate">
            <send submission="restart"/>
            <setvalue ref="instance('admin')/submitted"/>
	 </action>
      </trigger>
   </group>

</group>
</body>
</html>

