chiark / gitweb /
wip arch list change
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 12 Aug 2009 01:25:41 +0000 (02:25 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 12 Aug 2009 01:25:41 +0000 (02:25 +0100)
yarrg/web/pirate-route

index 639c8b1..e414e6e 100644 (file)
@@ -82,65 +82,67 @@ Enter route (islands, or archipelagoes, separated by |s or commas;
  abbreviations are OK):<br/>
 
 <script type="text/javascript">
-textRoute_uri= "routetextstring?format=json"
+tr_uri= "routetextstring?format=json"
                + "&ocean=<% uri_escape($a{Ocean}) %>";
 
-textRoute_timeout=false;
-textRoute_request=false;
-textRoute_done='';
-textRoute_needed='';
-function textRoute_Later(){
-  window.clearTimeout(textRoute_timeout);
-  textRoute_timeout = window.setTimeout(textRoute_Needed, 500);
+tr_timeout=false;
+tr_request=false;
+tr_done='';
+tr_needed='';
+function tr_Later(){
+  window.clearTimeout(tr_timeout);
+  tr_timeout = window.setTimeout(tr_Needed, 500);
 }
-function textRoute_Needed(){
-  window.clearTimeout(textRoute_timeout);
-  //textRoute_element= document.getElementsByName('routestring').item(0);
-  //alert(textRoute_element.name);
-  textRoute_needed= textRoute_element.value;
-  textRoute_Request();
+function tr_Needed(){
+  window.clearTimeout(tr_timeout);
+  //tr_element= document.getElementsByName('routestring').item(0);
+  //alert(tr_element.name);
+  tr_needed= tr_element.value;
+  tr_Request();
 }
-function textRoute_Request(){
-  if (textRoute_request || textRoute_needed==textRoute_done) return;
-  textRoute_done= textRoute_needed;
-  textRoute_request= new XMLHttpRequest();
-  uri= textRoute_uri+'&string='+encodeURIComponent(textRoute_needed);
-  textRoute_request.open('GET', uri);
-  textRoute_request.onreadystatechange= textRoute_Ready;
-  textRoute_request.send(null);
+function tr_Request(){
+  if (tr_request || tr_needed==tr_done) return;
+  tr_done= tr_needed;
+  tr_request= new XMLHttpRequest();
+  uri= tr_uri+'&string='+encodeURIComponent(tr_needed);
+  tr_request.open('GET', uri);
+  tr_request.onreadystatechange= tr_Ready;
+  tr_request.send(null);
 }
-function textRoute_Ready() {
-  if (textRoute_request.readyState != 4) return;
-  if (textRoute_request.status == 200) {
-    response= textRoute_request.responseText;
+function tr_Ready() {
+  if (tr_request.readyState != 4) return;
+  if (tr_request.status == 200) {
+    response= tr_request.responseText;
     //alert('got [[ '+response+' ]]');
     eval('results='+response);
     toedit= document.getElementsByName('routeresults').item(0);
     toedit.innerHTML= results['show'];
   }
-  textRoute_request= false;
-  textRoute_Request();
+  tr_request= false;
+  tr_Request();
 }
 </script>
 
 <input type="text" name="routestring" size=80
- onchange="textRoute_element= event.currentTarget; textRoute_Needed();"
- onkeydown="textRoute_element= event.currentTarget; textRoute_Later();"><br>
+ onchange="tr_element= event.currentTarget; tr_Needed();"
+ onkeydown="tr_element= event.currentTarget; tr_Later();"><br>
 <div name="routeresults">&nbsp;</div><br/>
 
 % } else {
 
 <%perl>
-my $sth=$dbh->prepare("SELECT islandid,islandname
+my $sth=$dbh->prepare("SELECT islandid,islandname,archipelago
                               FROM islands
                              ORDER BY islandname;");
 $sth->execute();
 my $row;
 my $islandlistdata='';
+my %archmap=();
 while ($row=$sth->fetchrow_arrayref) {
        $islandlistdata.=
                sprintf('<option value="%s">%s</option>',
-                       map { encode_entities($_) } @$row);
+                       map { encode_entities($_) } @$row[0..1]);
+       $archmap{$row->[0]}= $row->[2];
 }
 
 $sth=$dbh->prepare("SELECT DISTINCT archipelago FROM islands
@@ -156,11 +158,25 @@ while ($row=$sth->fetchrow_arrayref) {
 </%perl>
 
 <script type="text/javascript">
+sel_archmap= <% to_json(\%archmap) %>;
 function setarch(dd) {
- alert('setarch '+dd);
-}
-function setisland(dd) {
- alert('setisland '+dd);
+  var arch= document.getElementsByName('archipelago'+dd).item(0).value;
+  var select= document.getElementsByName('islandid'+dd).item(0);
+  var nodes= select.getElementsByTagName('option');
+  for (var i=0; i<nodes.length; i++) {
+    node= nodes.item(i);
+    value= node.getAttribute('value');
+    if (value == 'none') {
+      if (arch == 'none') {
+       node.innerHTML= 'Select island ...';
+      } else {
+       node.innerHTML= 'Whole arch';
+      }
+    } else {
+//      alert('node i='+i+' arch='+arch+' value='+value+'.');
+      node.setAttribute('disabled', !(arch=='none' || value==arch));
+    }
+  }
 }
 </script>
 
@@ -176,7 +192,7 @@ function setisland(dd) {
 
 <tr>
 %      for my $dd (0..$a{Dropdowns}-1) {
-<td><select name="islandid<% $dd %>" onchange="setisland(<% $dd %>)">
+<td><select name="islandid<% $dd %>">
 <option name="none">Select island...</option>
 <% $islandlistdata %></select></td>
 %      }