r8984@llin: dpavlin | 2005-11-20 02:51:47 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Nov 2005 01:50:47 +0000 (01:50 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Nov 2005 01:50:47 +0000 (01:50 +0000)
 drop down to select template

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@72 07558da8-63fa-0310-ba24-9fe276d99e06

web/browse.cgi

index 3981a86..0ea35b9 100755 (executable)
@@ -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' );
 
@@ -82,7 +85,7 @@ if ($q->path_info =~ m#xml#) {
                print qq{<response>
 <action type='html' target='div_record' errorCode='' errorMessage='' >
                }, $iconv_utf8->convert( $out->apply(
-                       template => $template_file,
+                       template => $template_filename,
                        data => $ds,
                ) ), qq{
 
@@ -117,7 +120,7 @@ if ($q->path_info =~ m#xml#) {
 
 } 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 +128,7 @@ if ($q->path_info =~ m#xml#) {
 
                        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'>
 <!--
@@ -227,6 +230,22 @@ iwfLog('loaded CSS template');
                exit;
 
 } else {
+
+       my $template_form = qq{
+               <form action="$self" method="get" style="display: inline;">
+               <select name="template">
+       };
+       foreach my $t (@templates) {
+               my $s = '';
+               $s = ' selected' if ($t eq $template_filename);
+               $template_form .= qq{<option$s>$t</option>};
+       }
+       $template_form .= qq{
+               </select>
+               <input type="submit" name="ch_template" value="Switch"/>
+               </form>
+       };
+
        print <<"_END_OF_HEAD_";
 <html>
 <head>
@@ -243,6 +262,7 @@ iwfLog('loaded CSS template');
 
 var rec = $rec ;
 var url = '$self';
+var template_filename = '$template_filename';
 
 var css_rnd = 0;
 
@@ -258,7 +278,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);
 }
 
@@ -305,7 +325,7 @@ function init_page() {
        load_rec(rec);
 
        // load template editor
-       iwfRequest( url+'/template/', 'div_template' );
+       iwfRequest( url+'/template/?template='+template_filename, 'div_template' );
        // load css editor
        iwfRequest( url+'/css/', 'div_css' );
 }
@@ -319,7 +339,7 @@ function init_page() {
 </div>
 
 db_path = <tt>$db_path</tt><br/>
-template = <tt>$template_file</tt><br/>
+template = $template_form<br/>
 css = <tt>$css_file</tt>
 
 <div style="background: #e0e0e0; padding: 0.5em; display: block;">