chiark / gitweb /
Remove stale fixme comment
[ypp-sc-tools.db-live.git] / yarrg / web / qtextstring
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 handles analysis of text string entries, including
33  both the AJAX calls from web page javascript and the entry validation
34  and processing calls from other components.
35
36
37 </%doc>
38 <%args>
39 $qa => $m->caller_args(1)->{'qa'}
40 $dbh
41 $thingstring
42 $emsgstore
43 $perresult
44 </%args>
45 <%perl>
46 my $stringval= $qa->{$thingstring};
47 $stringval='' if !defined $stringval;
48 </%perl>
49
50 <&| script &>
51 ts_uri= "qtextstringcheck?format=application/json&ctype=text/xml"
52                 + "&what=<% $thingstring %>"
53                 + "&ocean=<% uri_escape($qa->{Ocean}) %>";
54
55 ts_timeout=false;
56 ts_request=false;
57 ts_done='';
58 ts_needed='';
59 function ts_Later(){
60   window.clearTimeout(ts_timeout);
61   ts_timeout = window.setTimeout(ts_Needed, 500);
62 }
63 function ts_Needed(){
64   window.clearTimeout(ts_timeout);
65   ts_element= document.getElementById('<% $thingstring %>');
66   ts_needed= ts_element.value;
67   ts_Request();
68 }
69 function ts_Request(){
70   if (ts_request || ts_needed==ts_done) return;
71   ts_done= ts_needed;
72   ts_request= new XMLHttpRequest();
73   uri= ts_uri+'&string='+encodeURIComponent(ts_needed);
74   ts_request.open('GET', uri);
75   ts_request.onreadystatechange= ts_Ready;
76   ts_request.send(null);
77 }
78 function ts_Ready() {
79   if (ts_request.readyState != 4) return;
80   if (ts_request.status == 200) {
81     response= ts_request.responseText;
82     debug('got '+response);
83     eval('results='+response);
84     toedit= document.getElementById('ts_results');
85     toedit.innerHTML= results.show;
86   }
87   ts_request= false;
88   ts_Request();
89 }
90 register_onload(ts_Needed);
91 </&script>
92
93 <input type="text" <% $m->content %>
94  id="<% $thingstring %>" name="<% $thingstring %>"
95  onchange="ts_Needed();" onkeyup="ts_Later();"
96  value="<% $stringval |h %>"
97  >
98 <br>
99 <div id="ts_results">&nbsp;</div><br>
100
101 <%perl>
102 if (length $thingstring) {
103         my ($emsg,$canonstring,$results)= $m->comp('qtextstringcheck',
104                 what => $thingstring,
105                 ocean => $qa->{Ocean},
106                 string => $stringval,
107                 format => 'return'
108         );
109         $$emsgstore= $emsg;
110
111         foreach my $entry (@$results) {
112                 $perresult->(@$entry);
113         }
114 }
115 </%perl>