<?xml version="1.0"?>
<?css-conversion no?>
<?xml-stylesheet type="text/xsl" href="/xsltforms/xsltforms.xsl" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <head>
    <title>DX QRA</title>
    <style type="text/css">
      @namespace xf url('http://www.w3.org/2002/xforms');
      body { font-family: Arial, Helvetica, Sans Serif; }
      .note {float: right; }
      .cell {display: table-cell; width: 15em; text-align:left }
      .xf-repeat-item { display: table-row; }
      xf|switch.inline { display: inline; }
      xf|switch.inline > xf|case { display: inline; }
    </style>
    <model xmlns="http://www.w3.org/2002/xforms">
      <instance id="dxqra">
	<data xmlns="">
	  <prefix />
	  <search />
	  <prefixUpper />
	  <loading/>
	  <loaded/>
	  <qra />
	  <offset>0</offset>
	</data>
      </instance>

      <bind nodeset="instance('dxqra')/prefixUpper"
	    calculate="translate(../prefix, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>	

      <instance id="qraRequest">
	<data xmlns="">
	  <empty />
	</data>
      </instance>
      <submission id="load-qra" action="qra.cgi" replace="instance" instance='qraRequest' ref="instance('qraRequest')" method="get" separator="&amp;">
	<message ev:event="xforms-submit-error" level="modal">Failed to load default QRA</message>
	<!-- If there's a default provided by the server for QRA, skip the edit case -->
	<!--
	    <action ev:event="xforms-submit-done" if="instance('qraRequest')/qra !=''">
	    <toggle case="show-qra" />
	    </action>
	-->
      </submission>

      <instance id="dx">
	<data xmlns="" />
      </instance>
      <submission id="load-dx" action="bearings.cgi" replace="instance" instance="dx" ref="instance('qraRequest')" method="get" separator="&amp;">
	<toggle ev:event="xforms-submit-done" case="show-qra" />
      </submission>

      <!-- Don't offer prefix or search until QRA is set -->
      <bind nodeset="instance('dxqra')/prefix" relevant="instance('dx')/@qra != ''" />
      <bind nodeset="instance('dxqra')/search" relevant="instance('dx')/@qra != ''" />
      <!-- Show loading once when QRA request is non-empty but QRA response is empty -->
      <bind nodeset="instance('dxqra')/loading" relevant="instance('qraRequest')/qra !='' and instance('dx')/@qra != instance('qraRequest')/qra" />
      <!-- Offer instructions once QRA is set -->
      <bind nodeset="instance('dxqra')/loaded" relevant="instance('dx')/@qra" />

      <action ev:event="xforms-model-construct-done">
	<send submission="load-qra" />
      </action>

    </model>
  </head>
  <body>
    <group xmlns="http://www.w3.org/2002/xforms">
      <group class="note" ref="instance('dxqra')/loading">Loading...</group>
      <input id="prefix-input" ref="instance('dxqra')/prefix" incremental="true">
	<label>Prefix: </label>
	<!--<setfocus ev:event="xforms-enabled" control="prefix-input" />-->
      </input>
      <input id="search-input" ref="instance('dxqra')/search" incremental="true">
	<label>Country: </label>
	<!--<setfocus ev:event="xforms-enabled" control="prefix-input" />-->
      </input>
      <switch class="inline" xmlns="http://www.w3.org/2002/xforms">
	<case id="edit-qra">
	  <input ref="instance('qraRequest')/qra">
	    <label>QRA: </label>
	  </input>
	  <input ref="instance('qraRequest')/offset">
	    <label>Rotor offset: </label>
	  </input>
	  <trigger>
	    <label>OK</label>
	    <action ev:event="DOMActivate">
	      <send submission="load-dx" />
	    </action>
	  </trigger>
	  <xhtml:p>Type your home grid square and press OK</xhtml:p>
	</case>
	<case id="show-qra">
	  <trigger>
	    <label>QRA <output ref="instance('qraRequest')/qra" />@<output ref="instance('qraRequest')/offset" /></label>
	    <action ev:event="DOMActivate">
	      <toggle case="edit-qra" />
	    </action>
	  </trigger>
	  <group ref="instance('dxqra')/loaded">
	    Type prefix or country to find bearing and antibearing.
	    Click on QRA to change home.
	  </group>
	</case>
      </switch>
      <group ref="instance('dxqra')/prefix[string-length(.) > 0] | instance('dxqra')/search[string-length(.) > 0]">
	<table xmlns="http://www.w3.org/1999/xhtml">
	  <tr>
	    <th class="cell">Prefix</th>
	    <th class="cell">Entity</th>
	    <th class="cell">Bearing / Anti-Bearing</th>
	  </tr>
	</table>
      </group>
      <repeat nodeset="instance('dx')/entry[string-length(instance('dxqra')/prefix) > 0 and starts-with(prefix, instance('dxqra')/prefixUpper)] | instance('dx')/entry[string-length(instance('dxqra')/search) > 0 and contains(entity, instance('dxqra')/search)]">
	<output class="cell" ref="prefix" />
	<output class="cell" ref="entity" />
	<group class="cell"><output ref="bearing" /> / <output ref="antibearing" /></group>
      </repeat>
    </group>
    <hr />
    <a href="about.html">about</a>&#160;
    <a href="../dxqra-0.4.zip">source</a>&#160;
    <a href="bugs.html">bugs</a>
  </body>
</html>
