X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=web%2Fbrowse.cgi;h=bc9340f82e557fb04f361af72753dbf27e2a75dc;hb=1ccfac96de91ec6b87bf4cd74667d4b8159f5125;hp=916d946ac31fe5fee3a00648f045e762198e2e13;hpb=d4fc673006523d2a972a74943f880fcd47c658dd;p=webpac2
diff --git a/web/browse.cgi b/web/browse.cgi
index 916d946..bc9340f 100755
--- a/web/browse.cgi
+++ b/web/browse.cgi
@@ -18,7 +18,9 @@ my $abs_path = abs_path($0);
$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');
@@ -31,7 +33,7 @@ my $db = new WebPAC::DB(
);
my $out = new WebPAC::Output::TT(
- include_path => "$abs_path/conf/output/tt",
+ include_path => $template_path,
filters => { foo => sub { shift } },
);
@@ -39,6 +41,7 @@ my $q = new CGI::Simple;
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' );
@@ -72,18 +75,35 @@ sub get_file_in_html($) {
return $content;
}
+sub template_list_html($) {
+ my $current = shift || die;
+
+ my $html = qq{ Template\n
};
+
+ foreach my $t (sort @templates) {
+ if ($t eq $current) {
+ $html .= qq{ - $t
};
+ } else {
+ $html .= qq{ - $t
};
+ }
+ }
+
+ $html .= qq{
};
+ 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{
}, $iconv_utf8->convert( $out->apply(
- template => $template_file,
- data => \@ds,
+ template => $template_filename,
+ data => $ds,
) ), qq{
@@ -115,9 +135,20 @@ if ($q->path_info =~ m#xml#) {
exit;
}
+} elsif ($q->path_info =~ m#template_list#) {
+
+ print qq{
+
+} . template_list_html($template_filename) . qq{
+
+
+ };
+
+ 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')) {
@@ -125,7 +156,7 @@ if ($q->path_info =~ m#xml#) {
print qq{
-$template_file saved
+$template_filename saved
idle
-
+
@@ -227,6 +259,9 @@ iwfLog('loaded CSS template');
exit;
} else {
+
+ my $template_list_html = template_list_html($template_filename);
+
print <<"_END_OF_HEAD_";
@@ -243,6 +278,7 @@ iwfLog('loaded CSS template');
var rec = $rec ;
var url = '$self';
+var template_filename = '$template_filename';
var css_rnd = 0;
@@ -258,7 +294,7 @@ function load_rec(nr) {
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);
}
@@ -293,6 +329,18 @@ function edit_css() {
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'));
@@ -302,10 +350,9 @@ function init_page() {
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' );
}
@@ -319,7 +366,6 @@ function init_page() {
db_path = $db_path
-template = $template_file
css = $css_file
@@ -332,13 +378,20 @@ css = $css_file
+
+
+$template_list_html
+
+