/[webpac2]/trunk/web/browse.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/web/browse.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (show annotations)
Tue Nov 15 14:30:50 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 5264 byte(s)
 r8882@llin:  dpavlin | 2005-11-14 21:21:56 +0100
 fade out status message

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Cwd qw/abs_path/;
6 use CGI::Carp qw(fatalsToBrowser);
7 use CGI::Simple;
8 use File::Slurp;
9 use Data::Dumper;
10 use Text::Iconv;
11
12 use lib '../lib';
13
14 use WebPAC::DB;
15 use WebPAC::Output::TT;
16
17 my $abs_path = abs_path($0);
18 $abs_path =~ s#/[^/]*$#/../#;
19
20 my $db_path = $abs_path . '/db/';
21 my $template = 'html_ffzg.tt';
22
23 my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
24 my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
25
26 my $db = new WebPAC::DB(
27 path => $db_path,
28 read_only => 1,
29 debug => 1,
30 );
31
32 my $out = new WebPAC::Output::TT(
33 include_path => "$abs_path/conf/output/tt",
34 filters => { foo => sub { shift } },
35 );
36
37 my $q = new CGI::Simple;
38 my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
39
40 my $rec = $q->param('rec') || 1;
41
42 print $q->header( -charset => 'utf-8' );
43
44 if ($q->path_info =~ m#xml#) {
45
46 my @ds = $db->load_ds($rec);
47
48 if (@ds && $#ds > 0) {
49 print qq{<response>
50 <action type='html' target='div_record' errorCode='' errorMessage='' >
51 }, $iconv_utf8->convert( $out->apply(
52 template => $template,
53 data => \@ds,
54 ) ), qq{
55
56 </action>
57 <action type='javascript' errorCode='' errorMessage='' >
58 <!--
59 var el = iwfGetById('div_record_nr');
60 if (el) el.innerHTML = '# <b>$rec</b>';
61 //iwfShow('div_record');
62 iwfOpacity('div_record', 100);
63 //-->
64 </action>
65 </response>
66 };
67 exit;
68 } else {
69 print qq{<response>
70 <action type='html' target='div_record' errorCode='' errorMessage='' >
71
72 <b>Record $rec not found!</b>
73 </action>
74 <action type='javascript' errorCode='' errorMessage='' >
75 <!--
76 var el = iwfGetById('div_record_nr');
77 if (el) el.innerHTML = '<strike>&nbsp;$rec&nbsp;</strike>';
78 //-->
79 </action>
80 </response>
81 };
82 exit;
83 }
84
85 } elsif ($q->path_info =~ m#template#) {
86
87 my @actions;
88
89 if ($q->param('save_template')) {
90
91 my $tmpl = $iconv_loc->convert( $q->param('tt_template') ) || die "no template?";
92 sub _conv_js {
93 my $t = shift || return;
94 return $iconv_loc->convert(chr(hex($t)));
95 }
96 $tmpl =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
97
98 my $tmpl_file = $out->{'include_path'} . '/' . $template;
99 write_file($tmpl_file . '.new', $tmpl) || die "can't save $tmpl_file: $!";
100 rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!";
101
102 print qq{<response>
103 <action type='html' target='div_status' errorCode='' errorMessage='' >
104 <tt>$template</tt> saved
105 </action>
106 <action type='js'>
107 <!--
108 iwfShow('div_status', 1);
109 reload_rec();
110 iwfHideGentlyDelay('div_status', 2, 2000, 1);
111 -->
112 </action>
113 </response>
114 };
115 exit;
116
117 }
118
119 my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
120 $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
121
122 print qq{<response>
123 <action type='html' target='div_template' errorCode='' errorMessage='' >
124 <pre>}, Dumper($q->Vars), qq{</pre>
125
126 <form name="frmEditor" action="$self" method="post"
127 iwfTarget="div_status"
128 >
129
130 <textarea name="tt_template" cols="80" rows="10" style="display: block;">
131 $tmpl
132 </textarea>
133
134 <br/>
135 <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
136 <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" />
137 <span id="div_status" style="color: #808080;">idle</span>
138
139 <input type='hidden' value='hidden post value' name='hidValue' />
140
141 </form>
142 </action>
143 </response>
144 };
145
146 exit;
147
148 } else {
149 print qq{
150 <html>
151 <head>
152 <title>WebPAC simple browse interface</title>
153 <script type='text/javascript' src='iwf/iwfcore.js'></script>
154 <script type='text/javascript' src='iwf/iwfgui.js'></script>
155 <script type='text/javascript' src='iwf/iwfxml.js'></script>
156 <script type='text/javascript' src='iwf/iwfajax.js'></script>
157 <script type='text/javascript'>
158
159 var rec = $rec ;
160 var url = '$self';
161
162 function update_status(text) {
163 var el = iwfGetById('div_record_nr');
164 if (el) el.innerHTML = text;
165 }
166
167 function load_rec(nr) {
168 if (nr == 1) {
169 iwfHide('a_left_arr', 1);
170 } else {
171 iwfShow('a_left_arr', 1);
172 }
173 update_status(nr+'...');
174 iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
175 iwfOpacity('div_record', 30);
176 }
177
178 function inc_rec() {
179 rec++;
180 load_rec(rec);
181 return false;
182 }
183
184 function dec_rec() {
185 if (rec > 1) {
186 rec--;
187 load_rec(rec);
188 }
189 return false;
190 }
191
192 function reload_rec() {
193 load_rec(rec);
194 return false;
195 }
196
197 function init_page() {
198 load_rec(rec);
199 // load template
200 iwfRequest( url+'/template/', 'div_template' );
201 }
202
203 </script>
204 </head>
205 <body onload="init_page();">
206
207 db_path = <tt>$db_path</tt><br/>
208 template = <tt>$template</tt><br/>
209
210 <div id="iwfLog" style="display: none;">
211 </div>
212
213 <div style="background: #e0e0e0; padding: 0.5em; display: block;">
214 <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>
215 <span id="div_record_nr"> none </span>
216
217 <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>
218 <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>
219 <a href="#" onClick="iwfRefreshLog(); return false;">&#9636;</a>
220
221 </div>
222
223 <div id="div_template">
224 <span style="color: #808080;"> no template loaded yet. </span>
225 </div>
226
227 <div id="div_record" style="display: block;">
228 <span style="color: #808080;"> no record loaded yet. </span>
229 </div>
230
231
232 </body>
233 </html>};
234
235 };

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26