[vhffs-dev] [1688] Object history now use Template::Toolkit

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1688
Author:   beuss
Date:     2011-05-01 17:15:19 +0200 (Sun, 01 May 2011)
Log Message:
-----------
Object history now use Template::Toolkit

Modified Paths:
--------------
    trunk/vhffs-panel/history.pl
    trunk/vhffs-panel/templates/Makefile.am

Added Paths:
-----------
    trunk/vhffs-panel/templates/misc/history.tt

Removed Paths:
-------------
    trunk/vhffs-panel/templates/misc/history.tmpl

Modified: trunk/vhffs-panel/history.pl
===================================================================
--- trunk/vhffs-panel/history.pl	2011-05-01 15:15:12 UTC (rev 1687)
+++ trunk/vhffs-panel/history.pl	2011-05-01 15:15:19 UTC (rev 1688)
@@ -32,7 +32,6 @@
 
 use utf8;
 use POSIX qw(locale_h);
-use HTML::Template;
 use locale;
 use Locale::gettext;
 use CGI;
@@ -56,70 +55,35 @@
 exit 0 unless $session;
 
 my $vhffs = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
 my $user = $panel->{'user'};
 my $cgi = $panel->{'cgi'};
 my $oid = $cgi->param("OID");
 
 $oid = $cgi->param("oid") if( ! defined $oid );
 
-my $template;
-
 my $object;
-my $ok = 1;
-my $title;
 
-my $message;
-
 $object = Vhffs::Object::get_by_oid( $vhffs , $oid );
 
-
-my $templatesdir = $vhffs->get_config->get_templatedir;
-
-
 if( ! defined $oid ) {
-	$template = new HTML::Template( filename => $templatesdir."/panel/misc/simplemsg.tmpl" );
-	$message = gettext( "CGI Error !");
-	$template->param( MESSAGE => $message );
+    $panel->render('misc/message.tt', { message => gettext( "CGI Error !") });
 } elsif( !defined $object ) {
-
-	$template = new HTML::Template( filename => $templatesdir."/panel/misc/simplemsg.tmpl" );
-	$message = gettext("Cannot get information on this object");
-	$template->param( MESSAGE => $message );
-
+    $panel->render('misc/message.tt', { message => gettext( "Cannot get information on this object") });
 } elsif( !$user->can_view($object) ) {
-	$template = new HTML::Template( filename => $templatesdir."/panel/misc/simplemsg.tmpl" );
-	$message = gettext("You're not allowed to view this object's ACL");
-	$template->param( MESSAGE => $message );
+    $panel->render('misc/message.tt', { message => gettext("You're not allowed to view this object's ACL") });
 } else {
-	$template = new HTML::Template( filename => $templatesdir."/panel/misc/history.tmpl" );
     $panel->set_title( gettext("History") );
 
-	my $subtemplate;
 	my $history = $object->get_history;
-	my $string;
-	my $date;
 
-    unless(@{$history}) {
-        $template->param( HISTORY_PART => gettext('No event about this object') );
-    } else {
-        my $output = '';
-        my $history_tmpl = new HTML::Template( filename => $templatesdir.'/panel/misc/history_part.tmpl' );
-        use DateTime;
-        use DateTime::Locale;
-        my $loc = DateTime::Locale->load($user->get_lang);
-        foreach (@{$history}) {
-            my $dt = DateTime->from_epoch( epoch => $_->{date}, locale => $user->get_lang);
-            $history_tmpl->param( DATE => $dt->strftime($loc->medium_date_format().' '.$loc->long_time_format()));
-            $history_tmpl->param( EVENT => $_->{message} );
-            $history_tmpl->param( MODERATOR => $user->is_admin || $user->is_moderator );
-            $history_tmpl->param( SOURCE => $_->{source} );
-            $output .= $history_tmpl->output;
-        }
-        $template->param( HISTORY_PART => $output );
-    }
+    use DateTime;
+    use DateTime::Locale;
+    my $loc = DateTime::Locale->load($user->get_lang);
 
+    foreach(@$history) {
+        my $dt = DateTime->from_epoch( epoch => $_->{date}, locale => $user->get_lang);
+        $_->{date} = $dt->format_cldr($loc->date_format_medium().' '.$loc->time_format_long());
+    }
+    $panel->render('misc/history.tt', { history => $history });
 }
 
-$panel->build( $template );
-$panel->display;

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2011-05-01 15:15:12 UTC (rev 1687)
+++ trunk/vhffs-panel/templates/Makefile.am	2011-05-01 15:15:19 UTC (rev 1688)
@@ -100,7 +100,6 @@
 	misc/errors.tmpl \
 	misc/group_service.tmpl \
 	misc/history_part.tmpl \
-	misc/history.tmpl \
 	misc/infos.tmpl \
 	misc/service_index.tmpl \
 	misc/simplemsg.tmpl \
@@ -149,6 +148,7 @@
 	misc/closed.tt \
 	misc/errors.tt \
 	misc/header.tt \
+	misc/history.tt \
 	misc/infos.tt \
 	misc/languages.tt \
 	misc/message.tt \

Deleted: trunk/vhffs-panel/templates/misc/history.tmpl
===================================================================
--- trunk/vhffs-panel/templates/misc/history.tmpl	2011-05-01 15:15:12 UTC (rev 1687)
+++ trunk/vhffs-panel/templates/misc/history.tmpl	2011-05-01 15:15:19 UTC (rev 1688)
@@ -1,3 +0,0 @@
-<table>
-	<TMPL_VAR ESCAPE=0 NAME="HISTORY_PART">
-</table>

Added: trunk/vhffs-panel/templates/misc/history.tt
===================================================================
--- trunk/vhffs-panel/templates/misc/history.tt	                        (rev 0)
+++ trunk/vhffs-panel/templates/misc/history.tt	2011-05-01 15:15:19 UTC (rev 1688)
@@ -0,0 +1,19 @@
+[% IF history.size() %]
+[% USE date %]
+<table>
+    <tr>
+        <th>[% 'Date' | i18n | html %]</th>
+        <th>[% 'Event' | i18n | html %]</th>
+        [% IF current_user.is_moderator() || current_user.is_admin() %]<th>[% 'Source' | i18n | html %]</td>[% END %]
+    </tr>
+[% FOREACH h IN history %]
+    <tr>
+        <td>[% h.date %]</td>
+        <td>[% h.message %]</td>
+        <td>[% h.source || 'N/A' %]</td>
+    </tr>
+[% END %]
+</table>
+[% ELSE %]
+<p class="info">[% 'No history information about this object.' | i18n | html %]</p>
+[% END %]


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/