$abs_path =~ s#/[^/]*$#/../#;
my $db_path = $abs_path . '/db/';
-my $template_file = 'html_ffzg.tt';
+my $template_path = "$abs_path/conf/output/tt";
+opendir(my $dir, $template_path) || die "can't open template path $template_path: $!";
+my @templates = grep { /\.tt$/i } readdir($dir);
my $css_file = 'user.css';
my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
);
my $out = new WebPAC::Output::TT(
- include_path => "$abs_path/conf/output/tt",
+ include_path => $template_path,
filters => { foo => sub { shift } },
);
my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
my $rec = $q->param('rec') || 1;
+my $template_filename = $q->param('template') || $templates[0];
print $q->header( -charset => 'utf-8' );
return $iconv_loc->convert(chr(hex($t)));
}
$content =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
+ $content =~ s/^[\n\r]+//s;
$content =~ s/[\n\r]+$//s;
write_file($path . '.new', $content) || die "can't save ${path}.new $!";
return $content;
}
+sub template_list_html($) {
+ my $current = shift || die;
+
+ my $html = qq{ Template\n<ul> };
+
+ foreach my $t (sort @templates) {
+ if ($t eq $current) {
+ $html .= qq{ <li><b>$t</b></li> };
+ } else {
+ $html .= qq{ <li><a href="#" onClick="load_template('$t'); return false;">$t</a></li> };
+ }
+ }
+
+ $html .= qq{ </ul> };
+ return $html;
+}
+
##----
if ($q->path_info =~ m#xml#) {
- my @ds = $db->load_ds($rec);
+ my $ds = $db->load_ds($rec);
- if (@ds && $#ds > 0) {
+ if ($ds) {
print qq{<response>
<action type='html' target='div_record' errorCode='' errorMessage='' >
}, $iconv_utf8->convert( $out->apply(
- template => $template_file,
- data => \@ds,
+ template => $template_filename,
+ data => $ds,
) ), qq{
</action>
exit;
}
+} elsif ($q->path_info =~ m#template_list#) {
+
+ print qq{<response>
+<action type='html' target='div_template_list' errorCode='' errorMessage='' >
+<div>} . template_list_html($template_filename) . qq{</div>
+</action>
+</response>
+ };
+
+ exit;
+
} elsif ($q->path_info =~ m#template#) {
- my $template_path = $out->{'include_path'} . '/' . $template_file;
+ my $template_path = $out->{'include_path'} . '/' . $template_filename;
if ($q->param('save_template')) {
print qq{<response>
<action type='html' target='div_template_status' errorCode='' errorMessage='' >
-<tt>$template_file</tt> saved
+<tt>$template_filename</tt> saved
</action>
<action type='js'>
<!--
-->
<span id="div_template_status" style="color: #808080;">idle</span>
-<input type='hidden' value='hidden post value' name='hidValue' />
+<input type="hidden" name="template" value="$template_filename" />
</form>
</action>
<action type='js'>
<!--
+iwfOpacity('div_template', 100);
iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
-->
</action>
exit;
} else {
+
+ my $template_list_html = template_list_html($template_filename);
+
print <<"_END_OF_HEAD_";
<html>
<head>
var rec = $rec ;
var url = '$self';
+var template_filename = '$template_filename';
var css_rnd = 0;
iwfShow('a_left_arr', 1);
}
update_status(nr+'...');
- iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
+ iwfRequest( url+'/xml/?template='+template_filename+'&rec='+nr, 'div_record' );
iwfOpacity('div_record', 30);
}
return false;
}
+function load_template(name) {
+ iwfLog('changing template to '+name);
+ iwfOpacity('div_template', 30);
+ template_filename = name;
+ // load template editor
+ iwfRequest( url+'/template/?template='+template_filename, 'div_template' );
+ load_rec(rec);
+
+ // refresh template list
+ iwfRequest( url+'/template_list/?template='+template_filename, 'div_template_list' );
+}
+
function init_page() {
iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template'));
iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
- load_rec(rec);
+ // load template editor and record
+ load_template(template_filename);
- // load template editor
- iwfRequest( url+'/template/', 'div_template' );
// load css editor
iwfRequest( url+'/css/', 'div_css' );
}
</div>
db_path = <tt>$db_path</tt><br/>
-template = <tt>$template_file</tt><br/>
css = <tt>$css_file</tt>
<div style="background: #e0e0e0; padding: 0.5em; display: block;">
</div>
+
+<div id="div_template_list" style="display: inline; border: 2px solid #ffcc88; float: right; z-index: 10;">
+$template_list_html
+</div>
+
<div>
-<div style="display: block;">
+<div style="border: 2px solid #ffff80;">
+
Editor
<a id="a_template" href="#" onClick="return edit_template();">template</a>
<a id="a_css" href="#" onClick="return edit_css();">css</a>
+
<div id="div_template">
<span style="color: #808080;"> no template loaded yet. </span>
</div>