chiark / gitweb /
Tickbox for each line
[ypp-sc-tools.web-live.git] / yarrg / web / query_route
index f409e704b4d01345db3cb14feca6f08c9d55ed3b..18c3ecb1390af1f2d3a3fc4f2108d2a64f5c90ce 100644 (file)
@@ -1,31 +1,83 @@
+<%doc>
+
+ This is part of the YARRG website.  YARRG is a tool and website
+ for assisting players of Yohoho Puzzle Pirates.
+
+ Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
+ Copyright (C) 2009 Clare Boothby
+
+  YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
+  The YARRG website is covered by the GNU Affero GPL v3 or later, which
+   basically means that every installation of the website will let you
+   download the source.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
+ are used without permission.  This program is not endorsed or
+ sponsored by Three Rings.
+
+
+ This Mason component generates the core of the `trade route' query.
+
+
+</%doc>
 <%args>
 $quri
-$qa
+$dbh
+$prselector
 $routestring => '';
+$someresults
+$emsgokorprint
 </%args>
-<%perl>
 
+<%perl>
+my $emsg;
 my @archipelagoes;
 my @islandids;
 my %islandid2;
 
+my $qa= \%ARGS;
 </%perl>
 
+<h1>Specify route</h1>
+
+% $prselector->('ShowStalls');
+
 %#---------- textbox, user enters route as string ----------
 % if (!$qa->{Dropdowns}) {
 
-<h1>Specify route</h1>
+Enter route (islands, or archipelagoes, separated by |s or commas;
+ abbreviations are OK):<br>
 
 <form action="<% $quri->() |h %>" method="get">
 
-<&| qtextstring, qa => $qa, thingstring => 'routestring' &>
+<&| qtextstring, qa => $qa, dbh => $dbh,
+    thingstring => 'routestring', emsgstore => \$emsg,
+    perresult => sub {
+       my ($canonname, $island, $arch) = @_;
+       push @islandids, $island;
+       push @archipelagoes, defined $island ? undef : $arch;
+    }
+ &>
  size=80
 </&>
 
 % } else { #---------- dropdowns, user selects from menus ----------
 
 <%perl>
-my ($sth,$row);;
+my ($sth,$row);
 my @archlistdata;
 my %islandlistdata;
 $islandlistdata{'none'}= [ [ "none", "Select island..." ] ];
@@ -43,8 +95,6 @@ my $optionlistmap= sub {
        return $out;
 };
 
-my $dbh= dbw_connect($qa->{Ocean});
-
 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
                            ORDER BY archipelago;");
 $sth->execute();
@@ -75,8 +125,6 @@ foreach my $arch (keys %islandlistdata) {
 
 </%perl>
 
-<input type=hidden name=dropdowns value="<% $qa->{Dropdowns} |h %>">
-
 <&| script &>
 ms_lists= <% to_json_protecttags(\%resetislandlistdata) %>;
 function ms_Setarch(dd) {
@@ -118,38 +166,13 @@ function ms_Setarch(dd) {
 % } #---------- end of dropdowns, now common middle of page code ----------
 
 <input type=submit name=submit value="Go">
-</form>
+% my $ours= sub { $_[0] =~ m/^island|^archipelago|^routestring|^rtsel[ag]_/; };
+<& "lookup:formhidden", ours => $ours &>
 
 <%perl>
-#========== result computations ==========
+#========== results ==========
 
-my $results_head;
-$results_head= sub {
-       print "<h1>Results</h1>\n";
-       $results_head= sub { };
-};
-
-#---------- result computation - textstring ----------
-if (!$qa->{Dropdowns}) {
-  if (length $routestring) {
-       $results_head->();
-       my $rsr= $m->comp('routetextstring',
-               ocean => $qa->{Ocean},
-               string => $routestring,
-               format => 'return'
-       );
-       if (length $rsr->{Error}) {
-               print encode_entities($rsr->{Error});
-       } else {
-               foreach my $entry (@{ $rsr->{Results} }) {
-                       push @archipelagoes,
-                               defined $entry->[1] ? undef : $entry->[0];
-                       push @islandids, $entry->[1];
-               } 
-       }
-  }
-
-} else { #---------- results - dropdowns ----------
+$emsgokorprint->($emsg) or @islandids=();
 
 my $argorundef= sub {
        my ($dd,$base) = @_;
@@ -166,7 +189,7 @@ for my $dd (0..$qa->{Dropdowns}-1) {
                my $ii= $islandid2{$island};
                my $iarch= $ii->{Arch};
                if ($iarch ne $arch) {
-                       $results_head->();
+                       $someresults->();
 </%perl>
  Specified archipelago <% $arch %> but
  island <% $ii->{Name} %>
@@ -179,12 +202,15 @@ for my $dd (0..$qa->{Dropdowns}-1) {
        push @islandids, $island;
 }
 
-}#---------- result processing, common stuff
 </%perl>
 
 % if (@islandids) {
-%      $results_head->();
-
-<& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &>
-
+%      $someresults->();
+<& routetrade,
+   dbh => $dbh,
+   islandids => \@islandids,
+   archipelagoes => \@archipelagoes,
+   qa => $qa
+ &>
+</form>
 % }