r8863@llin: dpavlin | 2005-11-14 16:59:48 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 14 Nov 2005 16:16:57 +0000 (16:16 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 14 Nov 2005 16:16:57 +0000 (16:16 +0000)
 edit template in browser

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

web/browse.cgi

index 54b3283..bf5cd61 100755 (executable)
@@ -1,9 +1,13 @@
 #!/usr/bin/perl -w
 
+use strict;
+
 use Cwd qw/abs_path/;
 use CGI::Carp qw(fatalsToBrowser);
 use CGI::Simple;
 use File::Slurp;
+use Data::Dumper;
+use Text::Iconv;
 
 use lib '../lib';
 
@@ -16,6 +20,9 @@ $abs_path =~ s#/[^/]*$#/../#;
 my $db_path = $abs_path . '/db/';
 my $template = 'html_ffzg.tt';
 
+my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
+my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
+
 my $db = new WebPAC::DB(
        path => $db_path,
        read_only => 1,
@@ -32,7 +39,7 @@ my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
 
 my $rec = $q->param('rec') || 1;
 
-print $q->header;
+print $q->header( -charset    => 'utf-8' );
 
 if ($q->path_info =~ m#xml#) {
 
@@ -79,18 +86,58 @@ if ($q->path_info =~ m#xml#) {
 
 } elsif ($q->path_info =~ m#template#) {
 
-               my $tmpl = read_file($out->{'include_path'} . '/' . $template);
-               $tmpl = $q->escapeHTML($tmpl);
+               my @actions;
+
+               if ($q->param('save_template')) {
+
+                       my $tmpl = $q->param('tt_template') || die "no template?";
+                       my $tmpl_file = $out->{'include_path'} . '/' . $template;
+                       write_file($tmpl_file . '.new', $iconv_loc->convert($tmpl)) || die "can't save $tmpl_file: $!";
+                       rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!";
+
+                       print qq{<response>
+<action type='html' target='div_status' errorCode='' errorMessage='' >
+$template saved
+</action>
+<action type='js'>
+<!--
+reload_rec();
+-->
+</action>
+</response>
+                       };
+                       exit;
+
+               }
+
+               my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
+               $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
 
                print qq{<response>
 <action type='html' target='div_template' errorCode='' errorMessage='' >
-<textarea name="tt_template" cols="80" rows="10">
+<pre>}, Dumper($q->Vars), qq{</pre>
+
+<form name="frmEditor" action="$self" method="post"
+iwfTarget="div_status"
+>
+
+<textarea name="tt_template" cols="80" rows="10" style="display: block;">
 $tmpl
 </textarea>
-<br/><input type="button" name="save" value="Save">
+
+<br/>
+<input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
+<input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" />
+<span id="div_status" style="color: #808080;">idle</span>
+
+<input type='hidden' value='hidden post value' name='hidValue' />
+
+</form>
 </action>
 </response>
-};
+               };
+
+               exit;
 
 } else {
        print qq{
@@ -145,6 +192,7 @@ function init_page() {
 <body onload="init_page();">
 
 db_path = <tt>$db_path</tt><br/>
+template = <tt>$template</tt><br/>
 
 <div id="iwfLog" style="display: none;">
 </div>
@@ -156,6 +204,7 @@ db_path = <tt>$db_path</tt><br/>
        <a href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>&nbsp;
        <a href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>&nbsp;
        <a href="#" onClick="iwfRefreshLog(); return false;">&#9636;</a>&nbsp;
+
 </div>
 
 <div id="div_template">