1 <html><head><title>Specify route</title></head><body>
3 <script type="text/javascript">
6 var node= document.getElementById('debug_log');
7 node.innerHTML += "\n" + m + "\n";
16 @vars= ({ Name => 'Ocean',
18 CmpCanon => sub { ucfirst lc $_[0] },
19 Values => [ ocean_list() ]
20 }, { Name => 'Dropdowns',
21 Before => 'Interface: ',
22 CmpCanon => sub { !!$_[0] },
23 Values => [ [ 0, 'Type in names' ],
24 [ 4, 'Select from menus' ] ]
27 foreach my $var (@vars) {
28 my $name= $var->{Name};
29 $var->{Before}= '' unless exists $var->{Before};
30 $var->{CmpCanon}= sub { $_[0]; } unless exists $var->{CmpCanon};
31 foreach my $val (@{ $var->{Values} }) {
33 $val= [ $val, encode_entities($val) ];
35 if (exists $ARGS{lc $name}) {
36 $a{$name}= $ARGS{lc $name};
38 $a{$name}= $var->{Values}[0][0];
42 foreach my $var (@vars) {
43 my $name= $var->{Name};
44 my $delim= $var->{Before};
45 my $canon= &{$var->{CmpCanon}}($a{$name});
47 foreach my $valr (@{ $var->{Values} }) {
48 print $delim; $delim= "\n|\n";
49 my ($value,$html) = @$valr;
50 my $iscurrent= &{$var->{CmpCanon}}($value) eq $canon;
57 foreach my $innerr (@vars) {
58 my $n= lc $innerr->{Name};
60 next unless exists $ARGS{$n};
67 my $uri= URI->new($m->current_comp()->name());
68 $qf{'debug'}=1 if $debug;
69 $uri->query_form(%qf);
70 print '<a href="', $uri->path_query(), '">';
79 die "unknown ocean $a{Ocean} ?"
80 unless grep { $_ eq $a{Ocean} } ocean_list();
82 db_setocean($a{Ocean});
90 <h1>Specify route</h1>
91 <form action="/ucgi/~clareb/mason/something" method="get">
93 % if (!$a{Dropdowns}) {
94 Enter route (islands, or archipelagoes, separated by |s or commas;
95 abbreviations are OK):<br/>
97 <script type="text/javascript">
98 tr_uri= "routetextstring?format=json&type=text/xml"
99 + "&ocean=<% uri_escape($a{Ocean}) %>";
106 window.clearTimeout(tr_timeout);
107 tr_timeout = window.setTimeout(tr_Needed, 500);
109 function tr_Needed(){
110 window.clearTimeout(tr_timeout);
111 tr_element= document.getElementById('routestring');
112 tr_needed= tr_element.value;
115 function tr_Request(){
116 if (tr_request || tr_needed==tr_done) return;
118 tr_request= new XMLHttpRequest();
119 uri= tr_uri+'&string='+encodeURIComponent(tr_needed);
120 tr_request.open('GET', uri);
121 tr_request.onreadystatechange= tr_Ready;
122 tr_request.send(null);
124 function tr_Ready() {
125 if (tr_request.readyState != 4) return;
126 if (tr_request.status == 200) {
127 response= tr_request.responseText;
128 eval('results='+response);
129 toedit= document.getElementById('routeresults');
130 toedit.innerHTML= results.show;
137 <input type="text" id="routestring" name="routestring" size=80
138 onchange="tr_Needed();"
139 onkeyup="tr_Later();"><br>
140 <div id="routeresults"> </div><br/>
147 $islandlistdata{'none'}= <<END;
148 <option value="none">Select island...</option>
151 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
152 ORDER BY archipelago;");
155 while ($row=$sth->fetchrow_arrayref) {
158 sprintf('<option value="%s">%s</option>',
159 map { encode_entities($_) } ($arch,$arch));
160 $islandlistdata{$arch}= <<END;
161 <option value="none">Whole arch</option>
165 $sth= $dbh->prepare("SELECT islandid,islandname,archipelago
167 ORDER BY islandname;");
170 while ($row=$sth->fetchrow_arrayref) {
172 my $here= sprintf('<option value="%s">%s</option>',
173 map { encode_entities($_) } @$row[0..1]);
174 $islandlistdata{'none'} .= $here;
175 $islandlistdata{$arch} .= $here;
180 <script type="text/javascript">
181 ms_lists= <% to_json(\%islandlistdata) %>;
182 function ms_Setarch(dd) {
183 debug('ms_SetArch '+dd+' arch='+arch);
184 var arch= document.getElementsByName('archipelago'+dd).item(0).value;
185 var got= ms_lists[arch];
186 if (got == undefined) return; // unknown arch ? hrm
187 debug('ms_SetArch '+dd+' arch='+arch+' got ok');
188 var select= document.getElementsByName('islandid'+dd).item(0);
189 select.innerHTML= got;
190 debug('ms_SetArch '+dd+' arch='+arch+' innerHTML set');
195 var nodes= select.getElementsByTagName('option');
197 for (var i=0; i<nodes.length; i++) {
199 value= node.getAttribute('value');
200 debug('ms_Setarch '+dd+' i='+i+' arch='+arch+' value='+value+'.');
201 if (value == 'none') {
202 if (arch == 'none') {
203 node.innerHTML= 'Select island ...';
207 // alert('node i='+i+' arch='+arch+' value='+value+'.');
208 node.setAttribute('disabled', !(arch=='none' || value==arch));
215 <style type="text/css">
228 <table style="table-layout:fixed; width:90%;">
231 % for my $dd (0..$a{Dropdowns}-1) {
233 <select name="archipelago<% $dd %>" onchange="ms_Setarch(<% $dd %>)">
234 %# style="min-width:250px;"
235 <option value="none">Whole ocean</option>
236 <% $archlistdata %></select></td>
241 % for my $dd (0..$a{Dropdowns}-1) {
242 <td><select name="islandid<% $dd %>">
243 <option value="none">Select island...</option>
244 <% $islandlistdata{'none'} %></select></td>
250 <input type=text name=zork onclick="ms_PrepAll()">
253 <script type="text/javascript">
254 function ms_Prep(dd) {
255 //debug('ms_Prep'+dd);
256 var allnode= document.getElementsByName('islandid'+dd).item(0);
257 var newentry= {'none': allnode.innerHTML};
259 ms_lists[dd]= newentry;
261 function ms_PrepAll() {
263 % for my $dd (0..$a{Dropdowns}-1) {
264 ms_Prep('<% $dd %>');
266 //debug('ms_PrepAll done '+ms_lists);
274 <input type=submit name=submit value="Go">