[vhffs-dev] [1822] No more HTML::Template in object/list.

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


Revision: 1822
Author:   beuss
Date:     2011-05-26 22:42:53 +0200 (Thu, 26 May 2011)
Log Message:
-----------
No more HTML::Template in object/list.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Object.pm
    trunk/vhffs-panel/admin/object/list.pl
    trunk/vhffs-panel/templates/Makefile.am

Added Paths:
-----------
    trunk/vhffs-panel/templates/admin/object/list.tt

Removed Paths:
-------------
    trunk/vhffs-panel/templates/admin/object/part.tmpl

Modified: trunk/vhffs-api/src/Vhffs/Panel/Object.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Object.pm	2011-05-26 20:42:44 UTC (rev 1821)
+++ trunk/vhffs-api/src/Vhffs/Panel/Object.pm	2011-05-26 20:42:53 UTC (rev 1822)
@@ -49,27 +49,22 @@
 sub search
 {
     my ($main, $name) = @_;
-    my $sql;
+
     my @params;
-    my $objs = [];
+    my $sql = 'SELECT o.object_id AS oid, u.username as owner_user, g.groupname as owner_group, o.type, o.state '.
+        'FROM vhffs_object o '.
+        'INNER JOIN vhffs_users u ON (u.uid = o.owner_uid) '.
+        'INNER JOIN vhffs_groups g ON (g.gid = o.owner_gid) ';
 
     if( defined $name ) {
-        $sql = 'SELECT o.object_id AS oid, u.username, g.groupname, o.type, o.state FROM vhffs_object o INNER JOIN vhffs_users u ON o.owner_uid = u.uid INNER JOIN vhffs_groups g ON o.owner_gid = g.gid WHERE ( o.description ILIKE ? ) OR ( o.object_id = ? ) OR ( o.owner_uid = ? ) OR ( o.owner_gid = ? ) OR ( state = ? ) OR ( u.username LIKE ? ) OR ( g.groupname LIKE ? ) OR ( o.type = ? ) ORDER BY o.object_id';
+        $sql .= ' WHERE ( o.description ILIKE ? ) OR ( o.object_id = ? ) OR ( o.owner_uid = ? ) OR ( o.owner_gid = ? ) OR ( state = ? ) OR ( u.username LIKE ? ) OR ( g.groupname LIKE ? ) OR ( o.type = ? ) ';
         push(@params, '%'.$name.'%', $name, $name, $name, $name, '%'.lc($name).'%', '%'.lc($name).'%', $name );
-    } else {
-        $sql = 'SELECT o.object_id AS oid, u.username, g.groupname, o.type, o.state FROM vhffs_object o INNER JOIN vhffs_users u ON o.owner_uid = u.uid INNER JOIN vhffs_groups g ON o.owner_gid = g.gid ORDER BY o.object_id';
     }
-    my $dbh = $main->get_db_object();
-    my $sth = $dbh->prepare($sql) or return undef;
 
-    return undef unless($sth->execute(@params));
+    $sql .= 'ORDER BY o.object_id';
 
-    while(my $o = $sth->fetchrow_hashref('NAME_lc')) {
-        $o->{state} = Vhffs::Functions::status_string_from_status_id($o->{state});
-        $o->{type} = Vhffs::Functions::type_string_from_type_id($o->{type});
-        push(@$objs, $o);
-    }
-    return $objs;
+    my $dbh = $main->get_db_object();
+    return $dbh->selectall_arrayref($sql, { Slice => {} }, @params);
 }
 
 

Modified: trunk/vhffs-panel/admin/object/list.pl
===================================================================
--- trunk/vhffs-panel/admin/object/list.pl	2011-05-26 20:42:44 UTC (rev 1821)
+++ trunk/vhffs-panel/admin/object/list.pl	2011-05-26 20:42:53 UTC (rev 1822)
@@ -41,66 +41,15 @@
 
 
 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::Admin;
 use Vhffs::Panel::Object;
-use Vhffs::Stats;
-use Vhffs::Constants;
 
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
+my $panel = new Vhffs::Panel::Admin();
 
-my $vhffs = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-my $cgi = $panel->{'cgi'};
-my $name = $cgi->param("NAME");
-my $template;
-my $templatesdir = $vhffs->get_config->get_templatedir;
+my $vhffs = $panel->{vhffs};
+my $cgi = $panel->{cgi};
 
-
-if( $user->is_admin != 1 )
-{
-	$template = new HTML::Template( filename => $templatesdir."/panel/misc/simplemsg.tmpl" );
-	my $message = gettext( "You are not allowed to see it");
-	$template->param( MESSAGE => $message );
-}
-else
-{
-	$template = new HTML::Template( filename => $templatesdir."/panel/admin/misc/list.tmpl" );
-
-	if( defined( $name ) )
-	{
-		$template->param( TITLE => gettext("Search result "));
-	}
-	else
-	{
-		$template->param( TITLE => gettext("All objects List") );
-	}
-
-    $template->param( TEXT_TITLE1 => gettext('Object ID') );
-    $template->param( TEXT_TITLE2 => gettext('Owner user') );
-    $template->param( TEXT_TITLE3 => gettext('Owner group') );
-    $template->param( TEXT_TITLE4 => gettext('State') );
-    $template->param( TEXT_TITLE5 => gettext('History') );
-
-	my $objs = Vhffs::Panel::Object::search( $vhffs , $name );
-
-	if( defined $objs ) {
-        my $subtemplate = new HTML::Template( filename => $templatesdir."/panel/admin/object/part.tmpl", global_vars => 1 );
-        $subtemplate->param( SEND => gettext('Edit this object'));
-        $subtemplate->param( HISTORY => gettext('History'));
-		$subtemplate->param(OBJECTS => $objs);
-		$template->param( LIST => $subtemplate->output );
-	}
-	
-
-}
-
-$panel->build( $template );
-$panel->display;
+my $name = $cgi->param("NAME");
+my $vars = {};
+$vars->{objects} = Vhffs::Panel::Object::search( $vhffs , $name );
+$panel->render('admin/object/list.tt', $vars);

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2011-05-26 20:42:44 UTC (rev 1821)
+++ trunk/vhffs-panel/templates/Makefile.am	2011-05-26 20:42:53 UTC (rev 1822)
@@ -42,6 +42,7 @@
 	admin/misc/search.tt \
 	admin/moderation/index.tt \
 	admin/object/edit.tt \
+	admin/object/list.tt \
 	admin/user/list.tt \
 	anonymous/account_created.tt \
 	anonymous/login.tt \

Added: trunk/vhffs-panel/templates/admin/object/list.tt
===================================================================
--- trunk/vhffs-panel/templates/admin/object/list.tt	                        (rev 0)
+++ trunk/vhffs-panel/templates/admin/object/list.tt	2011-05-26 20:42:53 UTC (rev 1822)
@@ -0,0 +1,28 @@
+<h1>[% 'Objects list' | i18n | html %]</h1>
+
+[% IF objects.size > 0 %]
+<table>
+    <thead>
+		<tr>
+			<th>[% 'Object ID' | i18n | html %]</th>
+			<th>[% 'Owner user' | i18n | html %]</th>
+			<th>[% 'Owner group' | i18n | html %]</th>
+			<th>[% 'State' | i18n | html %]</th>
+            <th>[% 'Preferences' | i18n | html %]</th>
+		</tr>
+    </thead>
+    <tbody>
+[% FOREACH o IN objects %]
+        <tr>
+            <td>[% o.oid %] ([% o.type | stringify_type %])</td>
+            <td>[% o.owner_user | html %]</td>
+            <td>[% o.owner_group | html %]</td>
+            <td>[% o.state | stringify_status | html %]</td>
+            <td><a href="/admin/object/edit.pl?OID=[% o.oid %]">[% 'Edit' | i18n | html %]</a></td>
+        </tr>
+[% END %]
+    </tbody>
+</table>
+[% ELSE %]
+<p>[% 'No object found' | i18n | html %]
+[% END %]

Deleted: trunk/vhffs-panel/templates/admin/object/part.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/object/part.tmpl	2011-05-26 20:42:44 UTC (rev 1821)
+++ trunk/vhffs-panel/templates/admin/object/part.tmpl	2011-05-26 20:42:53 UTC (rev 1822)
@@ -1,25 +0,0 @@
-<TMPL_LOOP NAME="OBJECTS">
-<tr>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="OID"> (<TMPL_VAR ESCAPE=1 NAME="TYPE">)
-	</td>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="USERNAME"> 
-	</td>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="GROUPNAME"> 
-	</td>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="STATE"> 
-	</td>
-	<td>
-		<a href="../../history.pl?OID=<TMPL_VAR ESCAPE=1 NAME="OID">"><TMPL_VAR ESCAPE=1 NAME="HISTORY"></a> 
-	</td>
-	<td>
-		<form method="post" action="edit.pl" accept-charset="utf-8">
-			<input type="hidden" name="OID" value="<TMPL_VAR ESCAPE=1 NAME="OID">" />
-			<input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="SEND">" />
-		</form>
-	</td>
-</tr>
-</TMPL_LOOP>


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