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));
78 sub template_list_html($) {
79 my $current = shift || die;
81 my $html = qq{ Template\n<ul> };
83 foreach my $t (sort @templates) {
85 $html .= qq{ <li><b>$t</b></li> };
87 $html .= qq{ <li><a href="#" onClick="load_template('$t'); return false;">$t</a></li> };
97 if ($q->path_info =~ m#xml#) {
99 my $ds = $db->load_ds($rec);
103 <action type='html' target='div_record' errorCode='' errorMessage='' >
104 }, $iconv_utf8->convert( $out->apply(
105 template => $template_filename,
110 <action type='javascript' errorCode='' errorMessage='' >
112 var el = iwfGetById('div_record_nr');
113 if (el) el.innerHTML = '# <b>$rec</b>';
114 //iwfShow('div_record');
115 iwfOpacity('div_record', 100);
123 <action type='html' target='div_record' errorCode='' errorMessage='' >
125 <b>Record $rec not found!</b>
127 <action type='javascript' errorCode='' errorMessage='' >
129 var el = iwfGetById('div_record_nr');
130 if (el) el.innerHTML = '<strike> $rec </strike>';
138 } elsif ($q->path_info =~ m#template_list#) {
141 <action type='html' target='div_template_list' errorCode='' errorMessage='' >
142 <div>} . template_list_html($template_filename) . qq{</div>
149 } elsif ($q->path_info =~ m#template#) {
151 my $template_path = $out->{'include_path'} . '/' . $template_filename;
153 if ($q->param('save_template')) {
155 update_file($template_path, $q->param('tt_template'));
158 <action type='html' target='div_template_status' errorCode='' errorMessage='' >
159 <tt>$template_filename</tt> saved
163 iwfShow('div_template_status', 1);
165 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
174 my $tmpl = get_file_in_html($template_path);
177 <action type='html' target='div_template' errorCode='' errorMessage='' >
179 <form name="frmEditor" action="$self" method="post" iwfTarget="div_template_status" >
181 <textarea name="tt_template" cols="80" rows="10" style="display: block;">
186 <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
188 <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
190 <span id="div_template_status" style="color: #808080;">idle</span>
192 <input type="hidden" name="template" value="$template_filename" />
198 iwfOpacity('div_template', 100);
199 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
207 } elsif ($q->path_info =~ m#css#) {
209 my $css_path = $abs_path . '/web/' . $css_file;
212 if ($q->param('save_css')) {
213 update_file($css_path, $q->param('user_css'));
216 <action type='html' target='div_css_status' errorCode='' errorMessage='' >
217 <tt>$css_file</tt> saved
221 iwfShow('div_css_status', 1);
224 iwfLog('loading user.css?'+css_rnd);
225 iwfGetById('user_css_link').href = 'user.css?'+css_rnd;
226 iwfHideGentlyDelay('div_css_status', 2, 2000, 1);
235 my $user_css = get_file_in_html($css_path);
238 <action type='html' target='div_css' errorCode='' errorMessage='' >
240 <form name="frmCSSEditor" action="$self" method="post" iwfTarget="div_css_status" >
242 <textarea name="user_css" cols="80" rows="10" style="display: block; width: 100%;">
247 <input type="button" name="save_css" value="Save" onclick="javascript:iwfRequest(this);" />
248 <span id="div_css_status" style="color: #808080;">idle</span>
253 iwfLog('loaded CSS template');
263 my $template_list_html = template_list_html($template_filename);
265 print <<"_END_OF_HEAD_";
268 <title>WebPAC simple browse interface</title>
270 <link id="user_css_link" href="user.css" type="text/css" rel="stylesheet">
272 <script type='text/javascript' src='iwf/iwfcore.js'></script>
273 <script type='text/javascript' src='iwf/iwfgui.js'></script>
274 <script type='text/javascript' src='iwf/iwfxml.js'></script>
275 <script type='text/javascript' src='iwf/iwfajax.js'></script>
276 <script type='text/javascript' src='iwf/iwconfig.js'></script>
277 <script type='text/javascript'>
281 var template_filename = '$template_filename';
285 function update_status(text) {
286 var el = iwfGetById('div_record_nr');
287 if (el) el.innerHTML = text;
290 function load_rec(nr) {
292 iwfHide('a_left_arr', 1);
294 iwfShow('a_left_arr', 1);
296 update_status(nr+'...');
297 iwfRequest( url+'/xml/?template='+template_filename+'&rec='+nr, 'div_record' );
298 iwfOpacity('div_record', 30);
315 function reload_rec() {
320 function edit_template() {
321 iwfHideGently('div_css', 30, 1);
322 iwfShowGently('div_template', 30, 1);
326 function edit_css() {
327 iwfHideGently('div_template', 30, 1);
328 iwfShowGently('div_css', 30, 1);
332 function load_template(name) {
333 iwfLog('changing template to '+name);
334 iwfOpacity('div_template', 30);
335 template_filename = name;
336 // load template editor
337 iwfRequest( url+'/template/?template='+template_filename, 'div_template' );
340 // refresh template list
341 iwfRequest( url+'/template_list/?template='+template_filename, 'div_template_list' );
344 function init_page() {
345 iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
346 iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template'));
348 iwfX('div_css', iwfX('div_template'));
349 iwfY('div_css', iwfY('div_template'));
351 iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
353 // load template editor and record
354 load_template(template_filename);
357 iwfRequest( url+'/css/', 'div_css' );
363 <body onload="init_page();">
368 db_path = <tt>$db_path</tt><br/>
369 css = <tt>$css_file</tt>
371 <div style="background: #e0e0e0; padding: 0.5em; display: block;">
372 <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">⇦</a>
373 <span id="div_record_nr"> none </span>
375 <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a>
376 <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a>
377 <a href="#" onClick="iwfShowLog(); return false;">▤</a>
382 <div id="div_template_list" style="display: inline; border: 2px solid #ffcc88; float: right; z-index: 10;">
388 <div style="border: 2px solid #ffff80;">
391 <a id="a_template" href="#" onClick="return edit_template();">template</a>
392 <a id="a_css" href="#" onClick="return edit_css();">css</a>
395 <div id="div_template">
396 <span style="color: #808080;"> no template loaded yet. </span>
399 <div id="div_css" style="position: absolute; display: none;">
400 <span style="color: #808080;"> no CSS loaded yet. </span>
405 <div id="div_record" style="display: block;">
406 <span style="color: #808080;"> no record loaded yet. </span>