chiark / gitweb /
route menu selection mode seems to work
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 12 Aug 2009 12:51:41 +0000 (13:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 12 Aug 2009 12:51:41 +0000 (13:51 +0100)
yarrg/web/pirate-route

index 0f2fff729405a4c31bfd6a4f621a28f6d61dab8e..9dfab7e37309726a924f70d4f42a47cf4e86ab09 100644 (file)
@@ -1,5 +1,14 @@
 <html><head><title>Specify route</title></head><body>
 
 <html><head><title>Specify route</title></head><body>
 
+<script type="text/javascript">
+function debug (m) {
+% if ($debug) {
+  var node= document.getElementById('debug_log');
+  node.innerHTML += "\n" + m + "\n";
+% }
+}
+</script>
+
 <%perl>
 my %a;
 my @vars;
 <%perl>
 my %a;
 my @vars;
@@ -56,6 +65,7 @@ foreach my $var (@vars) {
                                }
                        }
                        my $uri= URI->new($m->current_comp()->name());
                                }
                        }
                        my $uri= URI->new($m->current_comp()->name());
+                       $qf{'debug'}=1 if $debug;
                        $uri->query_form(%qf);
                        print '<a href="', $uri->path_query(), '">';
                        $after= '</a>';
                        $uri->query_form(%qf);
                        print '<a href="', $uri->path_query(), '">';
                        $after= '</a>';
@@ -73,6 +83,9 @@ db_setocean($a{Ocean});
 db_connect();
 
 </%perl>
 db_connect();
 
 </%perl>
+<%args>
+$debug => 0
+</%args>
 
 <h1>Specify route</h1>
 <form action="/ucgi/~clareb/mason/something" method="get">
 
 <h1>Specify route</h1>
 <form action="/ucgi/~clareb/mason/something" method="get">
@@ -114,7 +127,7 @@ function tr_Ready() {
     response= tr_request.responseText;
     eval('results='+response);
     toedit= document.getElementById('routeresults');
     response= tr_request.responseText;
     eval('results='+response);
     toedit= document.getElementById('routeresults');
-    toedit.innerHTML= results['show'];
+    toedit.innerHTML= results.show;
   }
   tr_request= false;
   tr_Request();
   }
   tr_request= false;
   tr_Request();
@@ -128,46 +141,67 @@ function tr_Ready() {
 % } else {
 
 <%perl>
 % } else {
 
 <%perl>
-my $sth=$dbh->prepare("SELECT islandid,islandname,archipelago
-                              FROM islands
-                             ORDER BY islandname;");
+my ($sth,$row);;
+my $archlistdata='';
+my %islandlistdata;
+$islandlistdata{'none'}= <<END;
+<option value="none">Select island...</option>
+END
+
+$sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
+                           ORDER BY archipelago;");
 $sth->execute();
 $sth->execute();
-my $row;
-my $islandlistdata='';
-my %archmap=();
+
 while ($row=$sth->fetchrow_arrayref) {
 while ($row=$sth->fetchrow_arrayref) {
-       $islandlistdata.=
+       my ($arch)= @$row;
+       $archlistdata.=
                sprintf('<option value="%s">%s</option>',
                sprintf('<option value="%s">%s</option>',
-                       map { encode_entities($_) } @$row[0..1]);
-       $archmap{$row->[0]}= $row->[2];
+                       map { encode_entities($_) } ($arch,$arch));
+       $islandlistdata{$arch}= <<END;
+<option value="none">Whole arch</option>
+END
 }
 
 }
 
-$sth=$dbh->prepare("SELECT DISTINCT archipelago FROM islands
-                          ORDER BY archipelago;");
+$sth= $dbh->prepare("SELECT islandid,islandname,archipelago
+                            FROM islands
+                           ORDER BY islandname;");
 $sth->execute();
 $sth->execute();
-my $archlistdata='';
 
 while ($row=$sth->fetchrow_arrayref) {
 
 while ($row=$sth->fetchrow_arrayref) {
-       $archlistdata.=
-               sprintf('<option value="%s">%s</option>',
-                       map { encode_entities($_) } (@$row, @$row));
+       my $arch= $row->[2];
+       my $here= sprintf('<option value="%s">%s</option>',
+                       map { encode_entities($_) } @$row[0..1]);
+       $islandlistdata{'none'} .= $here;
+       $islandlistdata{$arch} .= $here;
 }
 }
+
 </%perl>
 
 <script type="text/javascript">
 </%perl>
 
 <script type="text/javascript">
-sel_archmap= <% to_json(\%archmap) %>;
-function setarch(dd) {
+ms_lists= <% to_json(\%islandlistdata) %>;
+function ms_Setarch(dd) {
+  debug('ms_SetArch '+dd+' arch='+arch);
   var arch= document.getElementsByName('archipelago'+dd).item(0).value;
   var arch= document.getElementsByName('archipelago'+dd).item(0).value;
+  var got= ms_lists[arch];
+  if (got == undefined) return; // unknown arch ?  hrm
+  debug('ms_SetArch '+dd+' arch='+arch+' got ok');
   var select= document.getElementsByName('islandid'+dd).item(0);
   var select= document.getElementsByName('islandid'+dd).item(0);
+  select.innerHTML= got;
+  debug('ms_SetArch '+dd+' arch='+arch+' innerHTML set');
+}
+</script>
+
+% if (0) {
   var nodes= select.getElementsByTagName('option');
   var nodes= select.getElementsByTagName('option');
+alert(ms_lists[dd]);
   for (var i=0; i<nodes.length; i++) {
     node= nodes.item(i);
     value= node.getAttribute('value');
   for (var i=0; i<nodes.length; i++) {
     node= nodes.item(i);
     value= node.getAttribute('value');
+    debug('ms_Setarch '+dd+' i='+i+' arch='+arch+' value='+value+'.');
     if (value == 'none') {
       if (arch == 'none') {
        node.innerHTML= 'Select island ...';
       } else {
     if (value == 'none') {
       if (arch == 'none') {
        node.innerHTML= 'Select island ...';
       } else {
-       node.innerHTML= 'Whole arch';
       }
     } else {
 //      alert('node i='+i+' arch='+arch+' value='+value+'.');
       }
     } else {
 //      alert('node i='+i+' arch='+arch+' value='+value+'.');
@@ -175,14 +209,30 @@ function setarch(dd) {
     }
   }
 }
     }
   }
 }
-</script>
+% }
+
+% if (0) {
+<style type="text/css">
+table
+{
+table-layout: fixed;
+color: red;
+}
+pre
+{
+color:yellow;
+}
+</style>
+% }
 
 
-<table>
+<table style="table-layout:fixed; width:90%;">
 
 <tr>
 %      for my $dd (0..$a{Dropdowns}-1) {
 
 <tr>
 %      for my $dd (0..$a{Dropdowns}-1) {
-<td><select name="archipelago<% $dd %>" onchange="setarch(<% $dd %>)">
-<option name="none">Whole ocean</option>
+<td>
+<select  name="archipelago<% $dd %>" onchange="ms_Setarch(<% $dd %>)">
+%# style="min-width:250px;"
+<option value="none">Whole ocean</option>
 <% $archlistdata %></select></td>
 %      }
 </tr>
 <% $archlistdata %></select></td>
 %      }
 </tr>
@@ -190,17 +240,48 @@ function setarch(dd) {
 <tr>
 %      for my $dd (0..$a{Dropdowns}-1) {
 <td><select name="islandid<% $dd %>">
 <tr>
 %      for my $dd (0..$a{Dropdowns}-1) {
 <td><select name="islandid<% $dd %>">
-<option name="none">Select island...</option>
-<% $islandlistdata %></select></td>
+<option value="none">Select island...</option>
+<% $islandlistdata{'none'} %></select></td>
 %      }
 </tr>
 
 </table>
 %      }
 </tr>
 
 </table>
+
+<input type=text name=zork onclick="ms_PrepAll()">
+
+% if (0) {
+<script type="text/javascript">
+function ms_Prep(dd) {
+  //debug('ms_Prep'+dd);
+  var allnode= document.getElementsByName('islandid'+dd).item(0);
+  var newentry= {'none': allnode.innerHTML};
+  
+  ms_lists[dd]= newentry;
+}
+function ms_PrepAll() {
+  //debug('now');
+%      for my $dd (0..$a{Dropdowns}-1) {
+  ms_Prep('<% $dd %>');
+%      }
+  //debug('ms_PrepAll done '+ms_lists);
+}
+ms_PrepAll();
+</script>
+% }
+
 % }
 
 <input type=submit name=submit value="Go">
 </form>
 
 % }
 
 <input type=submit name=submit value="Go">
 </form>
 
+% if ($debug) {
+<p>
+<pre id="debug_log">
+Debug log:
+</pre>
+% }
+
+
 <%init>
 use CommodsWeb;
 use HTML::Entities;
 <%init>
 use CommodsWeb;
 use HTML::Entities;