6 use CGI::Carp qw(fatalsToBrowser);
15 use WebPAC::Output::TT;
17 my $abs_path = abs_path($0);
18 $abs_path =~ s#/[^/]*$#/../#;
20 my $db_path = $abs_path . '/db/';
21 my $template_path = "$abs_path/conf/output/tt";
22 opendir(my $dir, $template_path) || die "can't open template path $template_path: $!";
23 my @templates = grep { /\.tt$/i } readdir($dir);
24 my $css_file = 'user.css';
26 my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
27 my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
29 my $db = new WebPAC::DB(
35 my $out = new WebPAC::Output::TT(
36 include_path => $template_path,
37 filters => { foo => sub { shift } },
40 my $q = new CGI::Simple;
41 my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
43 my $rec = $q->param('rec') || 1;
44 my $template_filename = $q->param('template') || $templates[0];
46 print $q->header( -charset => 'utf-8' );
48 ##---- some handy subs
51 my ($path, $content) = @_;
53 $content = $iconv_loc->convert( $content ) || die "no content?";
56 my $t = shift || return;
57 return $iconv_loc->convert(chr(hex($t)));
59 $content =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
60 $content =~ s/^[\n\r]+//s;
61 $content =~ s/[\n\r]+$//s;
63 write_file($path . '.new', $content) || die "can't save ${path}.new $!";
64 rename $path . '.new', $path || die "can't rename to $path: $!";
67 sub get_file_in_html($) {
70 die "no path?" unless ($path);
72 my $content = read_file($path) || die "can't read $path: $!";
73 $content = $q->escapeHTML($iconv_utf8->convert($content));
80 if ($q->path_info =~ m#xml#) {
82 my $ds = $db->load_ds($rec);
86 <action type='html' target='div_record' errorCode='' errorMessage='' >
87 }, $iconv_utf8->convert( $out->apply(
88 template => $template_filename,
93 <action type='javascript' errorCode='' errorMessage='' >
95 var el = iwfGetById('div_record_nr');
96 if (el) el.innerHTML = '# <b>$rec</b>';
97 //iwfShow('div_record');
98 iwfOpacity('div_record', 100);
106 <action type='html' target='div_record' errorCode='' errorMessage='' >
108 <b>Record $rec not found!</b>
110 <action type='javascript' errorCode='' errorMessage='' >
112 var el = iwfGetById('div_record_nr');
113 if (el) el.innerHTML = '<strike> $rec </strike>';
121 } elsif ($q->path_info =~ m#template#) {
123 my $template_path = $out->{'include_path'} . '/' . $template_filename;
125 if ($q->param('save_template')) {
127 update_file($template_path, $q->param('tt_template'));
130 <action type='html' target='div_template_status' errorCode='' errorMessage='' >
131 <tt>$template_filename</tt> saved
135 iwfShow('div_template_status', 1);
137 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
146 my $tmpl = get_file_in_html($template_path);
149 <action type='html' target='div_template' errorCode='' errorMessage='' >
151 <form name="frmEditor" action="$self" method="post" iwfTarget="div_template_status" >
153 <textarea name="tt_template" cols="80" rows="10" style="display: block;">
158 <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
160 <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
162 <span id="div_template_status" style="color: #808080;">idle</span>
164 <input type='hidden' value='hidden post value' name='hidValue' />
170 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
178 } elsif ($q->path_info =~ m#css#) {
180 my $css_path = $abs_path . '/web/' . $css_file;
183 if ($q->param('save_css')) {
184 update_file($css_path, $q->param('user_css'));
187 <action type='html' target='div_css_status' errorCode='' errorMessage='' >
188 <tt>$css_file</tt> saved
192 iwfShow('div_css_status', 1);
195 iwfLog('loading user.css?'+css_rnd);
196 iwfGetById('user_css_link').href = 'user.css?'+css_rnd;
197 iwfHideGentlyDelay('div_css_status', 2, 2000, 1);
206 my $user_css = get_file_in_html($css_path);
209 <action type='html' target='div_css' errorCode='' errorMessage='' >
211 <form name="frmCSSEditor" action="$self" method="post" iwfTarget="div_css_status" >
213 <textarea name="user_css" cols="80" rows="10" style="display: block; width: 100%;">
218 <input type="button" name="save_css" value="Save" onclick="javascript:iwfRequest(this);" />
219 <span id="div_css_status" style="color: #808080;">idle</span>
224 iwfLog('loaded CSS template');
234 my $template_form = qq{
235 <form action="$self" method="get" style="display: inline;">
236 <select name="template">
238 foreach my $t (@templates) {
240 $s = ' selected' if ($t eq $template_filename);
241 $template_form .= qq{<option$s>$t</option>};
243 $template_form .= qq{
245 <input type="submit" name="ch_template" value="Switch"/>
249 print <<"_END_OF_HEAD_";
252 <title>WebPAC simple browse interface</title>
254 <link id="user_css_link" href="user.css" type="text/css" rel="stylesheet">
256 <script type='text/javascript' src='iwf/iwfcore.js'></script>
257 <script type='text/javascript' src='iwf/iwfgui.js'></script>
258 <script type='text/javascript' src='iwf/iwfxml.js'></script>
259 <script type='text/javascript' src='iwf/iwfajax.js'></script>
260 <script type='text/javascript' src='iwf/iwconfig.js'></script>
261 <script type='text/javascript'>
265 var template_filename = '$template_filename';
269 function update_status(text) {
270 var el = iwfGetById('div_record_nr');
271 if (el) el.innerHTML = text;
274 function load_rec(nr) {
276 iwfHide('a_left_arr', 1);
278 iwfShow('a_left_arr', 1);
280 update_status(nr+'...');
281 iwfRequest( url+'/xml/?template='+template_filename+'&rec='+nr, 'div_record' );
282 iwfOpacity('div_record', 30);
299 function reload_rec() {
304 function edit_template() {
305 iwfHideGently('div_css', 30, 1);
306 iwfShowGently('div_template', 30, 1);
310 function edit_css() {
311 iwfHideGently('div_template', 30, 1);
312 iwfShowGently('div_css', 30, 1);
316 function init_page() {
317 iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
318 iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template'));
320 iwfX('div_css', iwfX('div_template'));
321 iwfY('div_css', iwfY('div_template'));
323 iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
327 // load template editor
328 iwfRequest( url+'/template/?template='+template_filename, 'div_template' );
330 iwfRequest( url+'/css/', 'div_css' );
336 <body onload="init_page();">
341 db_path = <tt>$db_path</tt><br/>
342 template = $template_form<br/>
343 css = <tt>$css_file</tt>
345 <div style="background: #e0e0e0; padding: 0.5em; display: block;">
346 <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">⇦</a>
347 <span id="div_record_nr"> none </span>
349 <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a>
350 <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a>
351 <a href="#" onClick="iwfShowLog(); return false;">▤</a>
357 <div style="display: block;">
359 <a id="a_template" href="#" onClick="return edit_template();">template</a>
360 <a id="a_css" href="#" onClick="return edit_css();">css</a>
362 <div id="div_template">
363 <span style="color: #808080;"> no template loaded yet. </span>
366 <div id="div_css" style="position: absolute; display: none;">
367 <span style="color: #808080;"> no CSS loaded yet. </span>
372 <div id="div_record" style="display: block;">
373 <span style="color: #808080;"> no record loaded yet. </span>