<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;
}
}
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>';
db_connect();
</%perl>
+<%args>
+$debug => 0
+</%args>
<h1>Specify route</h1>
<form action="/ucgi/~clareb/mason/something" method="get">
response= tr_request.responseText;
eval('results='+response);
toedit= document.getElementById('routeresults');
- toedit.innerHTML= results['show'];
+ toedit.innerHTML= results.show;
}
tr_request= false;
tr_Request();
% } 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();
-my $row;
-my $islandlistdata='';
-my %archmap=();
+
while ($row=$sth->fetchrow_arrayref) {
- $islandlistdata.=
+ my ($arch)= @$row;
+ $archlistdata.=
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();
-my $archlistdata='';
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">
-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 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);
+ select.innerHTML= got;
+ debug('ms_SetArch '+dd+' arch='+arch+' innerHTML set');
+}
+</script>
+
+% if (0) {
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');
+ debug('ms_Setarch '+dd+' i='+i+' arch='+arch+' value='+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+'.');
}
}
}
-</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) {
-<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>
<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>
+
+<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>
+% if ($debug) {
+<p>
+<pre id="debug_log">
+Debug log:
+</pre>
+% }
+
+
<%init>
use CommodsWeb;
use HTML::Entities;