1 <html><head><title>Specify route</title></head><body>
7 @vars= ({ Name => 'Ocean',
9 CmpCanon => sub { ucfirst lc $_[0] },
10 Values => [ ocean_list() ]
11 }, { Name => 'Dropdowns',
12 Before => 'Interface: ',
13 CmpCanon => sub { !!$_[0] },
14 Values => [ [ 0, 'Type in names' ],
15 [ 4, 'Select from menus' ] ]
18 foreach my $var (@vars) {
19 my $name= $var->{Name};
20 $var->{Before}= '' unless exists $var->{Before};
21 $var->{CmpCanon}= sub { $_[0]; } unless exists $var->{CmpCanon};
22 foreach my $val (@{ $var->{Values} }) {
24 $val= [ $val, encode_entities($val) ];
26 if (exists $ARGS{lc $name}) {
27 $a{$name}= $ARGS{lc $name};
29 $a{$name}= $var->{Values}[0][0];
33 foreach my $var (@vars) {
34 my $name= $var->{Name};
35 my $delim= $var->{Before};
36 my $canon= &{$var->{CmpCanon}}($a{$name});
38 foreach my $valr (@{ $var->{Values} }) {
39 print $delim; $delim= "\n|\n";
40 my ($value,$html) = @$valr;
41 my $iscurrent= &{$var->{CmpCanon}}($value) eq $canon;
48 foreach my $innerr (@vars) {
49 my $n= lc $innerr->{Name};
51 next unless exists $ARGS{$n};
58 my $uri= URI->new($m->current_comp()->name());
59 $uri->query_form(%qf);
60 print '<a href="', $uri->path_query(), '">';
69 die "unknown ocean $a{Ocean} ?"
70 unless grep { $_ eq $a{Ocean} } ocean_list();
72 db_setocean($a{Ocean});
77 <h1>Specify route</h1>
78 <form action="/ucgi/~clareb/mason/something" method="get">
80 % if (!$a{Dropdowns}) {
81 Enter route (islands, or archipelagoes, separated by |s or commas;
82 abbreviations are OK):<br/>
84 <script type="text/javascript">
85 textRoute_uri= "routetextstring?format=json"
86 + "&ocean=<% uri_escape($a{Ocean}) %>";
88 textRoute_timeout=false;
89 textRoute_request=false;
92 function textRoute_Later(){
93 window.clearTimeout(textRoute_timeout);
94 textRoute_timeout = window.setTimeout(textRoute_Needed, 500);
96 function textRoute_Needed(){
97 window.clearTimeout(textRoute_timeout);
98 //textRoute_element= document.getElementsByName('routestring').item(0);
99 //alert(textRoute_element.name);
100 textRoute_needed= textRoute_element.value;
103 function textRoute_Request(){
104 if (textRoute_request || textRoute_needed==textRoute_done) return;
105 textRoute_done= textRoute_needed;
106 textRoute_request= new XMLHttpRequest();
107 uri= textRoute_uri+'&string='+encodeURIComponent(textRoute_needed);
108 textRoute_request.open('GET', uri);
109 textRoute_request.onreadystatechange= textRoute_Ready;
110 textRoute_request.send(null);
112 function textRoute_Ready() {
113 if (textRoute_request.readyState != 4) return;
114 if (textRoute_request.status == 200) {
115 response= textRoute_request.responseText;
116 //alert('got [[ '+response+' ]]');
117 eval('results='+response);
118 toedit= document.getElementsByName('routeresults').item(0);
119 toedit.innerHTML= results['show'];
121 textRoute_request= false;
126 <input type="text" name="routestring" size=80
127 onchange="textRoute_element= event.currentTarget; textRoute_Needed();"
128 onkeydown="textRoute_element= event.currentTarget; textRoute_Later();"><br>
129 <div name="routeresults"> </div><br/>
134 my $sth=$dbh->prepare("SELECT islandid,islandname
136 ORDER BY islandname;");
139 my $islandlistdata='';
140 while ($row=$sth->fetchrow_arrayref) {
142 sprintf('<option value="%s">%s</option>',
143 map { encode_entities($_) } @$row);
146 $sth=$dbh->prepare("SELECT DISTINCT archipelago FROM islands
147 ORDER BY archipelago;");
151 while ($row=$sth->fetchrow_arrayref) {
153 sprintf('<option value="%s">%s</option>',
154 map { encode_entities($_) } (@$row, @$row));
158 <script type="text/javascript">
159 function setarch(dd) {
160 alert('setarch '+dd);
162 function setisland(dd) {
163 alert('setisland '+dd);
170 % for my $dd (0..$a{Dropdowns}-1) {
171 <td><select name="archipelago<% $dd %>" onchange="setarch(<% $dd %>)">
172 <option name="none">Whole ocean</option>
173 <% $archlistdata %></select></td>
178 % for my $dd (0..$a{Dropdowns}-1) {
179 <td><select name="islandid<% $dd %>" onchange="setisland(<% $dd %>)">
180 <option name="none">Select island...</option>
181 <% $islandlistdata %></select></td>
188 <input type=submit name=submit value="Go">