chiark / gitweb /
WIP pirate-route selector
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 11 Aug 2009 14:54:54 +0000 (15:54 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 11 Aug 2009 14:54:54 +0000 (15:54 +0100)
yarrg/web/pirate-route [new file with mode: 0644]

diff --git a/yarrg/web/pirate-route b/yarrg/web/pirate-route
new file mode 100644 (file)
index 0000000..a7d5eb2
--- /dev/null
@@ -0,0 +1,116 @@
+<html><head><title>Specify route</title></head><body>
+
+<%perl>
+my %a;
+my @vars;
+
+@vars= ({      Name => 'Ocean',
+               Before => 'Ocean: ',
+               CmpCanon => sub { ucfirst lc $_[0] },
+               Values => [ qw(Midnight Ice) ]
+       }, {    Name => 'Dropdowns',
+               Before => 'Interface: ',
+               CmpCanon => sub { !!$_[0] },
+               Values => [     [ 0, 'Type in names' ],
+                               [ 4, 'Select from menus' ] ]
+       });
+
+foreach my $var (@vars) {
+       my $name= $var->{Name};
+       $var->{Before}= '' unless exists $var->{Before};
+       $var->{CmpCanon}= sub { $_[0]; } unless exists $var->{CmpCanon};
+       foreach my $val (@{ $var->{Values} }) {
+               next if ref $val;
+               $val= [ $val, encode_entities($val) ];
+       }
+       if (exists $ARGS{lc $name}) {
+               $a{$name}= $ARGS{lc $name};
+       } else {
+               $a{$name}= $var->{Values}[0][0];
+       }
+}
+
+foreach my $var (@vars) {
+       my $name= $var->{Name};
+       my $delim= $var->{Before};
+       my $canon= &{$var->{CmpCanon}}($a{$name});
+       my $cvalix= 0;
+       foreach my $valr (@{ $var->{Values} }) {
+               print $delim;  $delim= "\n|\n";
+               my ($value,$html) = @$valr;
+               my $iscurrent= &{$var->{CmpCanon}}($value) eq $canon;
+               my $after;
+               if ($iscurrent) {
+                       print '<b>';
+                       $after= '</b>';
+               } else {
+                       my %qf= ();
+                       foreach my $innerr (@vars) {
+                               my $n= lc $innerr->{Name};
+                               if ($n ne lc $name) {
+                                       next unless exists $ARGS{$n};
+                                       $qf{$n}= $ARGS{$n};
+                               } else {
+                                       next if !$cvalix;
+                                       $qf{$n}= $value;
+                               }
+                       }
+                       my $uri= URI->new($self_url);
+                       $uri->query_form(%qf);
+                       print '<a href="', $uri->path_query(), '">';
+                       $after= '</a>';
+               }
+               print $html, $after;
+               $cvalix++;
+       }
+       print '<p>';
+}
+
+db_setocean($a{'ocean'});
+db_connect();
+
+</%perl>
+
+<h1>Specify route</h1>
+<form action="/ucgi/~clareb/mason/something" method="get">
+
+% if (!$a{Dropdowns}) {
+Enter route (islands, or archipelagoes, separated by commas;
+ abbreviations are OK):<br>
+<input type="text" name="routestring" size=80><br>
+<div name="results"></div></br>
+% } else {
+
+<%perl>
+my $sth=$dbh->prepare("SELECT islandid,islandname
+                              FROM islands
+                             ORDER BY islandname;");
+$sth->execute();
+my $row;
+my $islandlistdata='';
+while ($row=$sth->fetchrow_arrayref) {
+       $islandlistdata.=
+               sprintf('<option value="%s">%s</option>',
+                       map { encode_entities($_) } @$row);
+}
+</%perl>
+
+<table>
+<tr>
+%      for my $dd (0..$a{Dropdowns}-1) {
+<td><select name="islandid<% $dd %>">
+<option name="none">Select island...</option>
+<% $islandlistdata %></select></td>
+%      }
+% }
+</tr>
+</table>
+
+<input type=submit name=submit value="Go">
+</form>
+
+<%init>
+use CommodsWeb;
+use HTML::Entities;
+
+</%init>