chiark / gitweb /
WIP route fixes etc.
[ypp-sc-tools.main.git] / yarrg / web / pirate-route
index 42de303d16caf9bc960077596de6be4ba38d709c..639c8b19d91449ea2b14708ddb89368e0ec1ceab 100644 (file)
@@ -7,7 +7,7 @@ my @vars;
 @vars= ({      Name => 'Ocean',
                Before => 'Ocean: ',
                CmpCanon => sub { ucfirst lc $_[0] },
-               Values => [ qw(Midnight Ice) ]
+               Values => [ ocean_list() ]
        }, {    Name => 'Dropdowns',
                Before => 'Interface: ',
                CmpCanon => sub { !!$_[0] },
@@ -55,7 +55,7 @@ foreach my $var (@vars) {
                                        $qf{$n}= $value;
                                }
                        }
-                       my $uri= URI->new($self_url);
+                       my $uri= URI->new($m->current_comp()->name());
                        $uri->query_form(%qf);
                        print '<a href="', $uri->path_query(), '">';
                        $after= '</a>';
@@ -66,7 +66,10 @@ foreach my $var (@vars) {
        print '<p>';
 }
 
-db_setocean($a{'ocean'});
+die "unknown ocean $a{Ocean} ?"
+       unless grep { $_ eq $a{Ocean} } ocean_list();
+
+db_setocean($a{Ocean});
 db_connect();
 
 </%perl>
@@ -75,10 +78,13 @@ db_connect();
 <form action="/ucgi/~clareb/mason/something" method="get">
 
 % if (!$a{Dropdowns}) {
-Enter route (islands, or archipelagoes, separated by commas;
- abbreviations are OK):<br>
+Enter route (islands, or archipelagoes, separated by |s or commas;
+ abbreviations are OK):<br/>
 
 <script type="text/javascript">
+textRoute_uri= "routetextstring?format=json"
+               + "&ocean=<% uri_escape($a{Ocean}) %>";
+
 textRoute_timeout=false;
 textRoute_request=false;
 textRoute_done='';
@@ -95,19 +101,32 @@ function textRoute_Needed(){
   textRoute_Request();
 }
 function textRoute_Request(){
-  if (textRoute_request || textRoute_needed==textRoute_done) {
-    alert('unneeded');
-    return;
-  }
+  if (textRoute_request || textRoute_needed==textRoute_done) return;
   textRoute_done= textRoute_needed;
-  alert(String.concat('needed! ',textRoute_done));
+  textRoute_request= new XMLHttpRequest();
+  uri= textRoute_uri+'&string='+encodeURIComponent(textRoute_needed);
+  textRoute_request.open('GET', uri);
+  textRoute_request.onreadystatechange= textRoute_Ready;
+  textRoute_request.send(null);
+}
+function textRoute_Ready() {
+  if (textRoute_request.readyState != 4) return;
+  if (textRoute_request.status == 200) {
+    response= textRoute_request.responseText;
+    //alert('got [[ '+response+' ]]');
+    eval('results='+response);
+    toedit= document.getElementsByName('routeresults').item(0);
+    toedit.innerHTML= results['show'];
+  }
+  textRoute_request= false;
+  textRoute_Request();
 }
 </script>
 
 <input type="text" name="routestring" size=80
  onchange="textRoute_element= event.currentTarget; textRoute_Needed();"
  onkeydown="textRoute_element= event.currentTarget; textRoute_Later();"><br>
-<div name="results"></div></br>
+<div name="routeresults">&nbsp;</div><br/>
 
 % } else {
 
@@ -123,18 +142,48 @@ while ($row=$sth->fetchrow_arrayref) {
                sprintf('<option value="%s">%s</option>',
                        map { encode_entities($_) } @$row);
 }
+
+$sth=$dbh->prepare("SELECT DISTINCT archipelago FROM islands
+                          ORDER BY archipelago;");
+$sth->execute();
+my $archlistdata='';
+
+while ($row=$sth->fetchrow_arrayref) {
+       $archlistdata.=
+               sprintf('<option value="%s">%s</option>',
+                       map { encode_entities($_) } (@$row, @$row));
+}
 </%perl>
 
+<script type="text/javascript">
+function setarch(dd) {
+ alert('setarch '+dd);
+}
+function setisland(dd) {
+ alert('setisland '+dd);
+}
+</script>
+
 <table>
+
 <tr>
 %      for my $dd (0..$a{Dropdowns}-1) {
-<td><select name="islandid<% $dd %>">
+<td><select name="archipelago<% $dd %>" onchange="setarch(<% $dd %>)">
+<option name="none">Whole ocean</option>
+<% $archlistdata %></select></td>
+%      }
+</tr>
+
+<tr>
+%      for my $dd (0..$a{Dropdowns}-1) {
+<td><select name="islandid<% $dd %>" onchange="setisland(<% $dd %>)">
 <option name="none">Select island...</option>
 <% $islandlistdata %></select></td>
 %      }
-% }
 </tr>
+
 </table>
+% }
 
 <input type=submit name=submit value="Go">
 </form>
@@ -142,5 +191,6 @@ while ($row=$sth->fetchrow_arrayref) {
 <%init>
 use CommodsWeb;
 use HTML::Entities;
+use URI::Escape;
 
 </%init>