3 This is part of the YARRG website. YARRG is a tool and website
4 for assisting players of Yohoho Puzzle Pirates.
6 Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7 Copyright (C) 2009 Clare Boothby
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
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.
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.
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/>.
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.
32 This Mason component generates form contents for selecting a list
33 of locations (eg, a route).
48 %#---------- textbox, user enters route as string ----------
49 % if (!$qa->{Dropdowns}) {
52 % if (defined($archipelagoes_r)) {
53 (islands, or archipelagoes,
57 separated by |s or commas; abbreviations are OK):<br>
59 <&| qtextstring, qa => $qa, dbh => $dbh, emsgstore => $emsg_r,
60 thingstring => defined($archipelagoes_r) ? 'routestring' : 'islandstring',
64 my ($canonname, $island, $arch) = @$_;
65 push @$islandids_r, $island;
66 push @$archipelagoes_r, defined $island ? undef : $arch
67 if defined $archipelagoes_r;
74 % } else { #---------- dropdowns, user selects from menus ----------
81 $islandlistdata{'none'}= [ [ "none", "Select island..." ] ];
83 my $optionlistmap= sub {
84 my ($optlist, $selected) = @_;
86 foreach my $entry (@$optlist) {
87 $out.= sprintf('<option value="%s" %s>%s</option>',
88 encode_entities($entry->[0]),
89 defined $selected && $entry->[0] eq $selected
91 encode_entities($entry->[1]));
96 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
97 ORDER BY archipelago;");
100 while ($row=$sth->fetchrow_arrayref) {
102 push @archlistdata, [ $arch, $arch ];
103 $islandlistdata{$arch}= [ [ "none", "Whole arch" ] ];
106 $sth= $dbh->prepare("SELECT islandid,islandname,archipelago
108 ORDER BY islandname;");
111 while ($row=$sth->fetchrow_arrayref) {
113 push @{ $islandlistdata{'none'} }, [ @$row ];
114 push @{ $islandlistdata{$arch} }, [ @$row ];
115 $islandid2{$row->[0]}= { Name => $row->[1], Arch => $arch };
118 my %resetislandlistdata;
119 foreach my $arch (keys %islandlistdata) {
120 $resetislandlistdata{$arch}=
121 $optionlistmap->($islandlistdata{$arch}, '');
127 ms_lists= <% to_json_protecttags(\%resetislandlistdata) %>;
128 function ms_Setarch(dd) {
129 debug('ms_SetArch '+dd+' arch='+arch);
130 var arch= document.getElementsByName('archipelago'+dd).item(0).value;
131 var got= ms_lists[arch];
132 if (got == undefined) return; // unknown arch ? hrm
133 debug('ms_SetArch '+dd+' arch='+arch+' got ok');
134 var select= document.getElementsByName('islandid'+dd).item(0);
135 select.innerHTML= got;
136 debug('ms_SetArch '+dd+' arch='+arch+' innerHTML set');
140 <table style="table-layout:fixed; width:90%;">
143 % for my $dd (0..$qa->{Dropdowns}-1) {
145 <select name="archipelago<% $dd %>" onchange="ms_Setarch(<% $dd %>)">
146 <option value="none">Whole ocean</option>
147 <% $optionlistmap->(\@archlistdata, $qa->{"archipelago$dd"}) %></select></td>
152 % for my $dd (0..$qa->{Dropdowns}-1) {
153 % my $arch= $qa->{"archipelago$dd"};
154 % $arch= 'none' if !defined $arch;
156 <select name="islandid<% $dd %>">
157 <% $optionlistmap->($islandlistdata{$arch}, $qa->{"islandid$dd"}) %>
166 my $argorundef= sub {
168 my $thing= $qa->{"${base}${dd}"};
169 $thing= undef if defined $thing and $thing eq 'none';
173 for my $dd (0..$qa->{Dropdowns}-1) {
174 my $arch= $argorundef->($dd,'archipelago');
175 my $island= $argorundef->($dd,'islandid');
176 next unless defined $arch or defined $island;
177 if (defined $island and defined $arch) {
178 my $ii= $islandid2{$island};
179 my $iarch= $ii->{Arch};
180 if ($iarch ne $arch) {
181 push @$warningfs_r, sub {
183 Specified archipelago <% $arch %> but
184 island <% $ii->{Name} %>
185 which is in <% $iarch %>; using the island.<p>
191 push @$archipelagoes_r, $arch;
192 push @$islandids_r, $island;