[vhffs-dev] [1780] No more HTML::Template in cron/prefs

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


Revision: 1780
Author:   beuss
Date:     2011-05-19 22:35:35 +0200 (Thu, 19 May 2011)
Log Message:
-----------
No more HTML::Template in cron/prefs

Modified Paths:
--------------
    trunk/vhffs-panel/cron/prefs.pl
    trunk/vhffs-panel/templates/Makefile.am
    trunk/vhffs-panel/templates/cron/create.tt

Added Paths:
-----------
    trunk/vhffs-panel/templates/cron/prefs.tt

Removed Paths:
-------------
    trunk/vhffs-panel/cron/delete.pl
    trunk/vhffs-panel/templates/cron/prefs.tmpl

Deleted: trunk/vhffs-panel/cron/delete.pl
===================================================================
--- trunk/vhffs-panel/cron/delete.pl	2011-05-19 20:35:27 UTC (rev 1779)
+++ trunk/vhffs-panel/cron/delete.pl	2011-05-19 20:35:35 UTC (rev 1780)
@@ -1,103 +0,0 @@
-#!%PERL% -w 
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-
-use utf8;
-use POSIX qw(locale_h);
-use HTML::Template;
-use locale;
-use Locale::gettext;
-use CGI;
-use CGI::Session;
-use strict;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Main;
-use Vhffs::Group;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Panel::Group;
-use Vhffs::Services::Cron;
-
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
-
-my $vhffs = $panel->{'vhffs'};
-my $user = $panel->{'user'};
-my $cgi = $panel->{'cgi'};
-my $templatedir = $panel->{'templatedir'};
-
-my $message;
-my $owner = $cgi->param('PROJECT_OWNER');
-my $cronpath = $cgi->param('CRONPATH');
-my $sure = $cgi->param('DELETE');
-
-my $cron = Vhffs::Services::Cron::get_by_cronpath( $vhffs, $cronpath );
-
-unless( defined $cron )
-{
-	$message = gettext("This cron job doesn't exist in VHFFS database");
-}
-elsif( ! defined $sure )
-{
-	$message = gettext( "CGI Error !" );
-}
-elsif( !$user->can_delete( $cron ) )
-{
-	$message = gettext( 'You\'re not allowed to do this, object is not in active state or you don\'t have enough ACL rights' );
-}
-elsif( $sure == 0 )
-{
-	$message = gettext( "This cron job will NOT be deleted" );
-}
-else
-{
-	$cron->set_status( Vhffs::Constants::TO_DELETE );
-	if( $cron->commit < 0 )
-	{
-		$message = gettext('Cannot apply changes');
-	}
-	else
-	{
-		$message = gettext('This cron job will be deleted');
-	}
-}
-
-
-my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
-$template->param( MESSAGE => $message );
-
-$panel->set_refresh_url( "/cron/prefs.pl?name=$cronpath" );
-$panel->build( $template );
-$panel->display;

Modified: trunk/vhffs-panel/cron/prefs.pl
===================================================================
--- trunk/vhffs-panel/cron/prefs.pl	2011-05-19 20:35:27 UTC (rev 1779)
+++ trunk/vhffs-panel/cron/prefs.pl	2011-05-19 20:35:35 UTC (rev 1780)
@@ -32,7 +32,6 @@
 
 use utf8;
 use POSIX qw(locale_h);
-use HTML::Template;
 use locale;
 use Locale::gettext;
 use CGI;
@@ -40,13 +39,7 @@
 use strict;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Group;
-use Vhffs::Main;
 use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Panel::Object;
-use Vhffs::Panel::Template;
 use Vhffs::Services::Cron;
 
 my $panel = new Vhffs::Panel::Main();
@@ -64,102 +57,26 @@
 my $template;
 
 
-unless( defined $cronpath )
-{
-	$template = new HTML::Template( filename => $templatedir.'/panel/misc/simplemsg.tmpl' );
-	$template->param( MESSAGE => gettext( 'CGI Error !' ) );
+unless( defined $cronpath ) {
+    $panel->render('misc/message.tt', { message => gettext( 'CGI Error !' ) } );
 }
-elsif( ! defined $cron )
-{
-	$template = new HTML::Template( filename => $templatedir.'/panel/misc/simplemsg.tmpl' );
-	$template->param( MESSAGE => gettext('Cannot get informations on this object') );
-}
-elsif( !$user->can_view( $cron ) )
-{
-	$template = new HTML::Template( filename => $templatedir.'/panel/misc/simplemsg.tmpl' );
-	$template->param( MESSAGE => gettext( 'You\'re not allowed to do this, object is not in active state or you don\'t have enough ACL rights' ) );
-}
-else
-{
+elsif( ! defined $cron ) {
+    $panel->render('misc/message.tt', { message => gettext('Cannot get informations on this object') } );
+} elsif( !$user->can_view( $cron ) ) {
+    $panel->render('misc/message.tt', { message => gettext( 'You\'re not allowed to do this, object is not in active state or you don\'t have enough ACL rights' ) } );
+} else {
 	if( defined $cgi->param('save_prefs_submit') ) {
 		save_prefs();
 	}
 
-	$template = new Vhffs::Panel::Template( filename => $templatedir."/panel/cron/prefs.tmpl" );
+    my $vars = {
+        cron => $cron
+    };
 
 	$panel->set_title( gettext("Cron job Administration") );
-
-	$template->param( TEXT_CRONPATH => gettext("Path") );
-	$template->param( VALUE_CRONPATH => $cron->get_cronpath );
-
-	$template->param( TEXT_INTERVAL => gettext("Interval between runs") );
-	$template->param( VALUE_INTERVAL => $cron->get_interval/60 );
-	$template->param( TEXT_MINUTES => gettext("minutes") );
-
-	$template->param( TEXT_REPORTMAIL => gettext("Mail reports to") );
-	$template->param( VALUE_REPORTMAIL => $cron->get_reportmail );
-
-	use DateTime;
-	use DateTime::Locale;
-	my $loc = DateTime::Locale->load($user->get_lang);
-	my $dt;
-	my $datestr;
-
-	if( defined $cron->get_lastrundate )  {
-		$dt = DateTime->from_epoch( epoch => $cron->get_lastrundate, locale => $user->get_lang);
-		$datestr = $dt->strftime($loc->medium_date_format()).' '.$dt->strftime($loc->long_time_format());
-	} else {
-		$datestr = gettext('Never');
-	}
-	$template->param( TEXT_LASTRUNDATE => gettext("Last run date was") );
-	$template->param( VALUE_LASTRUNDATE => $datestr );
-
-	my $rt = $cron->get_lastrunreturncode;
-	$rt = gettext('Never') unless defined $rt;
-	$template->param( TEXT_LASTRUNRETURNCODE => gettext("Last run return code was") );
-	$template->param( VALUE_LASTRUNRETURNCODE => $rt );
-
-	if( defined $cron->get_nextrundate )  {
-		$dt = DateTime->from_epoch( epoch => $cron->get_nextrundate, locale => $user->get_lang);
-		$datestr = $dt->strftime($loc->medium_date_format()).' '.$dt->strftime($loc->long_time_format());
-	} else {
-		$datestr = gettext('As soon as possible');
-	}
-	$template->param( TEXT_NEXTRUNDATE => gettext("Next run is scheduled at") );
-	$template->param( VALUE_NEXTRUNDATE => $datestr );
-
-	$template->param( TEXT_RUNNING => gettext("State") );
-	my $state = $cron->get_running;
-	my $statestr = '';
-	if( $state == 0 ) {
-		$statestr = gettext('Sleeping');
-	} elsif( $state == 1 ) {
-		$statestr = gettext('Running');
-	} else {
-		$statestr = gettext('Collided, something went wrong, recovering');
-	}
-	$template->param( VALUE_RUNNING => $statestr );
-
-	$template->param( VALUE_OID => $cron->get_oid );
-	$template->param( TEXT_ACL_ADMIN => gettext("Admin Rights on this object (ACL)") );
-	$template->param( EXPLAIN_ADMIN_ACL => gettext("You can Manage rights on this service for each user in the VHFFS database. Please read help before manage it.") );
-	$template->param( ADMIN_ACL => gettext("Ok, go to ACL admin") );
-
-	$template->param( TEXT_SEND => gettext("Modify") );
-	$template->param( TEXT_DELETE_CRON => gettext("Delete this cron job") );
-	$template->param( TEXT_BEFORE_DELETE => gettext("This action is non-reversible. This Cron job will be DESTROYED.") );
-	$template->param( ASK_DELETE_CRON => gettext("Are you SURE you want DELETE this Cron job ?") );
-	$template->param( YES => gettext("Yes I'm sure of what I do") );
-	$template->param( NO => gettext("No, I'm not sure, I prefer to keep this project.") );
-	$template->param( TEXT_DELETE => gettext("Delete") );
-
-	my $adminpart = Vhffs::Panel::Object::admin_part( $panel, $cron );
-	$template->param( ADMIN_PART => $adminpart->output ) if( defined $adminpart );
+    $panel->render('cron/prefs.tt', $vars);
 }
 
-$panel->build( $template );
-$panel->display;
-
 sub save_prefs {
 	my $ok = 1;
 

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2011-05-19 20:35:27 UTC (rev 1779)
+++ trunk/vhffs-panel/templates/Makefile.am	2011-05-19 20:35:35 UTC (rev 1780)
@@ -72,7 +72,6 @@
 	misc/simplemsg.tmpl \
 	bazaar/create.tmpl \
 	bazaar/prefs.tmpl \
-	cron/prefs.tmpl \
 	acl/form.tt \
 	acl/view.tt \
 	admin/object/edit.tt \
@@ -82,6 +81,7 @@
 	anonymous/lost-password-ack.tt \
 	anonymous/subscribe.tt \
 	cron/create.tt \
+	cron/prefs.tt \
 	cvs/create.tt \
 	database/prefs.tt \
 	dns/create.tt \

Modified: trunk/vhffs-panel/templates/cron/create.tt
===================================================================
--- trunk/vhffs-panel/templates/cron/create.tt	2011-05-19 20:35:27 UTC (rev 1779)
+++ trunk/vhffs-panel/templates/cron/create.tt	2011-05-19 20:35:35 UTC (rev 1780)
@@ -11,7 +11,7 @@
 	<p>
 		<label for="cron_interval">[% 'Interval:' | i18n | html %]</label>
 		<input type="text" name="interval" id="interval" value="[% interval | html %]"/>
-		[% 'In minutes, at which interval this cron should be started, the minimum interval is set to %d minutes' | i18n | pretty_print(default_interval) %]
+		[% 'In minutes, at which interval this cron should be started, the minimum interval is set to %d minutes' | i18n | pretty_print(default_interval) | html %]
 	</p>
 	<p>
 		<label for="cron_reportmail">[% 'Mail to:' | i18n | html %]</label>

Deleted: trunk/vhffs-panel/templates/cron/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/cron/prefs.tmpl	2011-05-19 20:35:27 UTC (rev 1779)
+++ trunk/vhffs-panel/templates/cron/prefs.tmpl	2011-05-19 20:35:35 UTC (rev 1780)
@@ -1,101 +0,0 @@
-<fieldset>
-<legend><TMPL_I18N KEY="Options"></legend>
-<form method="post" action="/cron/prefs.pl" accept-charset="utf-8">
-	<p>
-		<label for="name">
-			<TMPL_VAR ESCAPE=1 NAME="TEXT_CRONPATH"> :
-		</label>
-		<TMPL_VAR ESCAPE=1 NAME="VALUE_CRONPATH">
-		<input type="hidden" name="name" id="name" value="<TMPL_VAR ESCAPE=1 NAME="VALUE_CRONPATH">"/>
-		<br/>
-	</p>
-	<p>
-		<label for="interval">
-			<TMPL_VAR ESCAPE=1 NAME="TEXT_INTERVAL"> :
-		</label>
-		<input type="text" name="interval" id="interval" value="<TMPL_VAR ESCAPE=1 NAME="VALUE_INTERVAL">"/>
-		<TMPL_VAR ESCAPE=1 NAME="TEXT_MINUTES">
-	</p>
-	<p>
-		<label for="reportmail">
-			<TMPL_VAR ESCAPE=1 NAME="TEXT_REPORTMAIL"> :
-		</label>
-		<input type="text" name="reportmail" id="reportmail" value="<TMPL_VAR ESCAPE=1 NAME="VALUE_REPORTMAIL">"/>
-	</p>
-	<p>
-		<label for="lastrundate">
-			<TMPL_VAR ESCAPE=1 NAME="TEXT_LASTRUNDATE"> :
-		</label>
-		<TMPL_VAR ESCAPE=1 NAME="VALUE_LASTRUNDATE">
-		<br/>
-	</p>
-	<p>
-		<label for="lastrunreturncode">
-			<TMPL_VAR ESCAPE=1 NAME="TEXT_LASTRUNRETURNCODE"> :
-		</label>
-		<TMPL_VAR ESCAPE=1 NAME="VALUE_LASTRUNRETURNCODE">
-		<br/>
-	</p>
-	<p>
-		<label for="nextrundate">
-			<TMPL_VAR ESCAPE=1 NAME="TEXT_NEXTRUNDATE"> :
-		</label>
-		<TMPL_VAR ESCAPE=1 NAME="VALUE_NEXTRUNDATE">
-		<br/>
-	</p>
-	<p>
-		<label for="running">
-			<TMPL_VAR ESCAPE=1 NAME="TEXT_RUNNING"> :
-		</label>
-		<TMPL_VAR ESCAPE=1 NAME="VALUE_RUNNING">
-		<br/>
-	</p>
-	<p class="button">
-		<input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="TEXT_SEND">" name="save_prefs_submit"/>
-	</p>
-</form>
-</fieldset>
-
-<h2><TMPL_VAR ESCAPE=1 NAME="TEXT_ACL_ADMIN"></h2>
-		
-<form method="post" action="../acl/view.pl" accept-charset="utf-8">
-	<p><TMPL_VAR ESCAPE=1 NAME="EXPLAIN_ADMIN_ACL"></p>
-
-	<input type="hidden" name="target_oid" value="<TMPL_VAR ESCAPE=1 NAME="VALUE_OID">" />
-	<p class="button" id="buttonAclAdmin">
-		<input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="ADMIN_ACL">" />
-	</p>
-</form>
-
-
-<h2><TMPL_VAR ESCAPE=1 NAME="TEXT_DELETE_CRON"></h2>
-
-<form method="post" action="delete.pl" accept-charset="utf-8">
-	<fieldset class="delete">
-		<legend>
-			<TMPL_VAR ESCAPE=1 NAME="ASK_DELETE_CRON">:
-		</legend>
-
-		<p class="warning"><TMPL_VAR ESCAPE=1 NAME="TEXT_BEFORE_DELETE"></p>
-		<p>
-			<input type="radio" name="DELETE" id="DELETE_NO"  value="0" checked="checked" />
-			<label for="DELETE_NO">
-				<TMPL_VAR ESCAPE=1 NAME="NO">
-			</label>
-		</p>
-		<p>
-			<input type="radio" name="DELETE" id="DELETE_YES" value="1" />
-			<label for="DELETE_YES">
-				<TMPL_VAR ESCAPE=1 NAME="YES">
-			</label>
-		</p>
-	</fieldset>
-	
-	<p class="button" id="buttonDelete">
-		<input type="hidden" name="CRONPATH" value="<TMPL_VAR ESCAPE=1 NAME="VALUE_CRONPATH">" />
-		<input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="TEXT_DELETE">" />
-	</p>
-				
-</form>
-
-<TMPL_VAR ESCAPE=0 NAME="ADMIN_PART">

Added: trunk/vhffs-panel/templates/cron/prefs.tt
===================================================================
--- trunk/vhffs-panel/templates/cron/prefs.tt	                        (rev 0)
+++ trunk/vhffs-panel/templates/cron/prefs.tt	2011-05-19 20:35:35 UTC (rev 1780)
@@ -0,0 +1,67 @@
+[% USE date %]
+<fieldset>
+<legend>[% 'Options' | i18n | html %]</legend>
+<form method="post" action="/cron/prefs.pl" accept-charset="utf-8">
+	<p>
+		<label for="name">[% 'Path:' | i18n | html %]</label>
+        [% cron.cronpath | html %]
+		<input type="hidden" name="name" id="name" value="[% cron.get_cronpath | html %]"/>
+		<br/>
+	</p>
+	<p>
+		<label for="interval">[% 'Interval:' | i18n | html %]</label>
+		<input type="text" name="interval" id="interval" value="[% cron.get_interval / 60 %]"/>
+        [% 'minutes' | i18n | html %]
+	</p>
+	<p>
+		<label for="reportmail">[% 'Send reports to:' | i18n | html %]</label>
+		<input type="text" name="reportmail" id="reportmail" value="[% cron.get_reportmail | html %]"/>
+	</p>
+	<p>
+		<label>[% 'Last run:' | i18n | html %]</label>
+[% IF cron.get_lastrundate().defined() %]
+        [% date.format(cron.get_lastrundate, '%x %X') | html %]
+[% ELSE %]
+        [% 'Never run' | i18n | html %]
+[% END %]
+	</p>
+	<p>
+		<label>[% 'Last return code:' | i18n | html %]</label>
+[% IF cron.get_lastrunreturncode().defined() %]
+        [% cron.get_lastrunreturncode %]
+[% ELSE %]
+        [% 'Never run' | i18n | html %]
+[% END %]
+	</p>
+	<p>
+		<label for="nextrundate">[% 'Next run scheduled at:' | i18n | html %]</label>
+		[% date.format(cron.get_nextrundate, '%x %X') | html %]
+	</p>
+	<p>
+		<label for="running">[% 'Status:' | i18n | html %]</label>
+[% IF cron.get_running == 0 %]
+        [% 'Stand-by' | i18n | html %]
+[% ELSIF cron.get_running == 1 %]
+        [% 'Running' | i18n | html %]
+[% ELSE %]
+        [% 'Collided, something went wrong, recovering' | i18n | html %]
+[% END %]
+	</p>
+	<p class="button">
+		<input type="submit" value="[% 'Update' | i18n | html %]" name="save_prefs_submit"/>
+	</p>
+</form>
+</fieldset>
+
+[% INCLUDE 'acl/form.tt' 
+    object = cron %]
+
+[% INCLUDE 'object/delete.tt'
+    type = 'cron'
+    oid = cron.get_oid %]
+
+[% IF current_user.is_admin %]
+    [% INCLUDE 'admin/object/edit.tt' 
+        object = cron %]
+[% END %]
+


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