chiark / gitweb /
WIP routesearch UI: entry improvements re advanced options
[ypp-sc-tools.main.git] / yarrg / web / query_route
1 <%doc>
2
3  This is part of the YARRG website.  YARRG is a tool and website
4  for assisting players of Yohoho Puzzle Pirates.
5
6  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7  Copyright (C) 2009 Clare Boothby
8
9   YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10   The YARRG website is covered by the GNU Affero GPL v3 or later, which
11    basically means that every installation of the website will let you
12    download the source.
13
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Affero General Public License as
16  published by the Free Software Foundation, either version 3 of the
17  License, or (at your option) any later version.
18
19  This program is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  GNU Affero General Public License for more details.
23
24  You should have received a copy of the GNU Affero General Public License
25  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28  are used without permission.  This program is not endorsed or
29  sponsored by Three Rings.
30
31
32  This Mason component generates the core of the `trade route' query.
33
34
35 </%doc>
36 <%args>
37 $quri
38 $dbh
39 $prselector
40 $routestring => '';
41 $capacitystring => '';
42 $lossperleague => '';
43 $capitalstring => '';
44 $someresults
45 $emsgokorprint
46 </%args>
47
48 <%perl>
49 my $emsg;
50 my @warningfs;
51 my @archipelagoes;
52 my @islandids;
53
54 my $qa= \%ARGS;
55
56 my $be_post;
57 my $startform= sub {
58         ($be_post)= @_;
59 </%perl>
60 <form action="<% $quri->() |h %>" method="<% $be_post ? 'post' : 'get' %>">
61 <%perl>
62 };
63 my $goupdate= sub { $be_post ? 'Update' : 'Go' };
64
65 </%perl>
66
67 <h1>Specify route</h1>
68
69 % # Sadly we need to do this rather hacky thing to make it be a POST
70 % #  form if the user has already selected some thing(s)
71 % if (!$qa->{Dropdowns}) {
72 %     $startform->($routestring =~ m/\S/);
73 % } else {
74 %     $startform->(grep {
75 %               defined $qa->{"archipelago$_"} ||
76 %               defined $qa->{"islandid$_"}
77 %       } (0..$qa->{Dropdowns}-1));
78 % }
79
80 % $prselector->('ShowStalls');
81
82 <& enter_route, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
83         warningfs_r => \@warningfs,
84         enterwhat => 'Enter route',
85         islandids_r => \@islandids,
86         archipelagoes_r => \@archipelagoes
87  &>
88
89 %#---------- textboxes, user enters details as strings ----------
90 % my $routeparams= { EmsgRef => \$emsg };
91 % if (!$qa->{Dropdowns}) {
92
93 <& enter_advrouteopts, qa=>$qa, dbh=>$dbh, routeparams=>$routeparams &>
94
95 % } #---------- end of dropdowns, now common middle of page code ----------
96
97 <input type=submit name=submit value="<% $goupdate->() %>">
98 % my $ours= sub { $_[0] =~
99 %  m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^capitalstring|^[RT]/;
100 % };
101 <& "lookup:formhidden", ours => $ours &>
102
103 <%perl>
104 #========== results ==========
105
106 $emsgokorprint->($emsg) or @islandids=();
107
108 foreach my $warningf (@warningfs) {
109         $someresults->();
110         $warningf->();
111 }
112
113 </%perl>
114
115 % if (@islandids) {
116 %       $someresults->('Relevant trades');
117 <& routetrade,
118    dbh => $dbh,
119    islandids => \@islandids,
120    archipelagoes => \@archipelagoes,
121    qa => $qa,
122    routeparams => $routeparams
123  &>
124 % }
125 </form>