[vhffs-dev] [1077] Done some cleanup in templates.

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


Revision: 1077
Author:   beuss
Date:     2007-11-12 19:13:49 +0000 (Mon, 12 Nov 2007)

Log Message:
-----------
Done some cleanup in templates. Pagination has been factorized so we can use it elsewhere...

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Commons.pm
    trunk/vhffs-api/src/Vhffs/Panel/User.pm
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-public/templates/Makefile.am
    trunk/vhffs-public/templates/groupslist.tmpl
    trunk/vhffs-public/templates/user.tmpl
    trunk/vhffs-public/templates/userslist.tmpl
    trunk/vhffs-public/user.pl
    trunk/vhffs-public/usersearch.pl
    trunk/vhffs-themes/vhffs/main.css

Added Paths:
-----------
    trunk/vhffs-public/templates/misc/groupinfo.tmpl
    trunk/vhffs-public/templates/misc/pagination.tmpl
    trunk/vhffs-public/templates/misc/userinfo.tmpl

Removed Paths:
-------------
    trunk/vhffs-public/templates/misc/lastusers-part.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Commons.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-11-12 19:13:49 UTC (rev 1077)
@@ -39,6 +39,8 @@
 use locale;
 use Locale::gettext;
 
+use Vhffs::Constants;
+
 sub display_login($$)
 {
     my ($vhffs, $panel) = @_;
@@ -88,4 +90,39 @@
     $panel->display;
 }
 
+sub paginate($$$$$) {
+    my ($template, $current_page, $total_count, $items_per_page, $url_params) = @_;
+    die('Attempted to paginate without pagination template') unless($template->query(name => 'PAGINATION'));
+    $template->param(PAGINATION => 1);
+    my $max_pages = int( ($total_count + ($items_per_page - 1)) / $items_per_page );
+    if($max_pages > 1) {
+        my @params;
+        foreach my $key (keys %$url_params) {
+            my $value = $url_params->{$key};
+            push @params, $key.'='.$value unless($value =~ /^\s*$/);
+        }
+        $template->param( SEARCH_CRITERIA => join('&', @params) );
+        $template->param( CURRENT_PAGE => $current_page );
+        my $pages = [];
+        if($current_page > 1) {
+            for(($current_page - $items_per_page < 1 ? 1 : $current_page - $items_per_page)..($current_page - 1)) {
+                push @$pages, { PAGE => $_ };
+            }
+        }
+        $template->param( PREVIOUS_PAGES => \@$pages );
+        $pages = [];
+
+        if($current_page < $max_pages) {
+            for(($current_page + 1)..($current_page + $items_per_page > $max_pages ? $max_pages : $current_page + $items_per_page)) {
+                push @$pages, { PAGE => $_ };
+            }
+        }
+        $template->param( NEXT_PAGES => $pages );
+
+        $template->param( PAGES =>  );
+        $template->param( PREVIOUS_PAGE => ($current_page - 1 < 1 ? 0 : $current_page - 1 ) );
+        $template->param( NEXT_PAGE => ($current_page + 1 > $max_pages ? 0 : $current_page + 1 ) );
+    }
+}
+
 1;

Modified: trunk/vhffs-api/src/Vhffs/Panel/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/User.pm	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-api/src/Vhffs/Panel/User.pm	2007-11-12 19:13:49 UTC (rev 1077)
@@ -159,7 +159,17 @@
     push @params, $count, $start;
 
     my $dbh = $main->get_db_object;
-    $result->{users} = $dbh->selectall_arrayref($select_clause.$restriction.$order, { Slice => {} }, Vhffs::Constants::ACTIVATED, @params);
+    my $sth = $dbh->prepare($select_clause.$restriction.$order);
+    my @users;
+    $sth->execute( Vhffs::Constants::ACTIVATED, @params );
+    my $sql = 'SELECT g.groupname FROM vhffs_groups g INNER JOIN vhffs_user_group ug ON ug.gid = g.gid WHERE ug.uid = ? AND g.groupname != ?';
+    my $ssth = $dbh->prepare($sql);
+    while(my $row = $sth->fetchrow_hashref) {
+       $ssth->execute($row->{uid}, $row->{username});
+       $row->{groups} = $ssth->fetchall_arrayref({});
+       push @users, $row;
+    }
+    $result->{users} = \@users;
     $select_clause = 'SELECT COUNT(*)';
     pop @params; pop @params;
     ($result->{total_count}) = @{$dbh->selectrow_arrayref($select_clause.$restriction, undef, Vhffs::Constants::ACTIVATED, @params)};

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2007-11-12 19:13:49 UTC (rev 1077)
@@ -99,12 +99,12 @@
     $self->{homedir} = $homedir;
     $self->{shell} = $shell;
     $self->{admin} = $admin;
-    $self->{firstname} = Encode::decode_utf8( $firstname );
-    $self->{lastname} = Encode::decode_utf8( $lastname );
-    $self->{address} = Encode::decode_utf8( $address );
-    $self->{zipcode} = Encode::decode_utf8( $zipcode );
-    $self->{city} = Encode::decode_utf8( $city );
-    $self->{country} = Encode::decode_utf8( $country );
+    $self->{firstname} = $firstname;
+    $self->{lastname} = $lastname;
+    $self->{address} = $address;
+    $self->{zipcode} = $zipcode;
+    $self->{city} = $city;
+    $self->{country} = $country;
     $self->{mail} = $mail;
     $self->{gpg_key} = $gpg_key;
     $self->{note} = $note;

Modified: trunk/vhffs-public/templates/Makefile.am
===================================================================
--- trunk/vhffs-public/templates/Makefile.am	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-public/templates/Makefile.am	2007-11-12 19:13:49 UTC (rev 1077)
@@ -6,9 +6,10 @@
 	groupslist.tmpl \
 	index.tmpl \
 	misc/cvs-part.tmpl \
-	misc/lastgroups-part.tmpl \
-	misc/lastusers-part.tmpl \
+	misc/groupinfo.tmpl \
 	misc/list-part.tmpl \
+	misc/pagination.tmpl \
+	misc/userinfo.tmpl \
 	misc/svn-part.tmpl \
 	misc/git-part.tmpl \
 	misc/web-part.tmpl \

Modified: trunk/vhffs-public/templates/groupslist.tmpl
===================================================================
--- trunk/vhffs-public/templates/groupslist.tmpl	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-public/templates/groupslist.tmpl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -13,5 +13,7 @@
 <p style="text-align:center;font-weight:bold;"><TMPL_VAR ESCAPE=1 NAME="MESSAGE"></p>
 </TMPL_IF>
 </TMPL_IF>
-<TMPL_INCLUDE NAME="misc/lastgroups-part.tmpl">
+<TMPL_LOOP NAME="GROUPS">
+<TMPL_INCLUDE NAME="misc/groupinfo.tmpl">
+</TMPL_LOOP>
 </div>

Added: trunk/vhffs-public/templates/misc/groupinfo.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/groupinfo.tmpl	                        (rev 0)
+++ trunk/vhffs-public/templates/misc/groupinfo.tmpl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -0,0 +1,6 @@
+<h2><a href="group.pl?name=<TMPL_VAR ESCAPE=1 NAME="GROUPNAME">"><TMPL_VAR ESCAPE=1 NAME="REALNAME"></a></h2>
+<ul>
+<li><TMPL_I18N KEY="Groupname">: <TMPL_VAR ESCAPE=1 NAME="GROUPNAME"></li>
+<li><TMPL_I18N KEY="Users">: <TMPL_INCLUDE NAME="../user_part.tmpl"></li>
+<li><TMPL_I18N KEY="Description">: <TMPL_VAR ESCAPE=1 NAME="DESCRIPTION"></li>
+</ul>

Deleted: trunk/vhffs-public/templates/misc/lastusers-part.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/lastusers-part.tmpl	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-public/templates/misc/lastusers-part.tmpl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -1,25 +0,0 @@
-<div class="public_user">
-<h2><TMPL_VAR ESCAPE=1 NAME="TEXT_TITLE"></h2>
-<TMPL_IF NAME="USE_AVATAR">
-<img src="/getavatar.pl?oid=<TMPL_VAR ESCAPE=1 NAME="VALUE_OID">" alt="<TMPL_VAR ESCAPE=1 NAME="VALUE_USERNAME"> avatar" class="avatar"/>
-</TMPL_IF>
-<ul>
-<li>
-<TMPL_VAR ESCAPE=1 NAME="TEXT_USERNAME">
-<TMPL_VAR ESCAPE=1 NAME="VALUE_USERNAME">
-</li>
-<li>
-<TMPL_VAR ESCAPE=1 NAME="TEXT_FIRSTNAME">
-<TMPL_VAR ESCAPE=1 NAME="VALUE_FIRSTNAME">
-</li>
-<li>
-<TMPL_VAR ESCAPE=1 NAME="TEXT_LASTNAME">
-<TMPL_VAR ESCAPE=1 NAME="VALUE_LASTNAME">
-</li>
-<li>
-<TMPL_VAR ESCAPE=1 NAME="TEXT_GROUPS">
-<TMPL_VAR ESCAPE=1 NAME="VALUE_GROUPS">
-</li>
-</ul>
-<div class="clear"></div>
-</div>

Added: trunk/vhffs-public/templates/misc/pagination.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/pagination.tmpl	                        (rev 0)
+++ trunk/vhffs-public/templates/misc/pagination.tmpl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -0,0 +1,22 @@
+<TMPL_IF NAME="PAGINATION">
+<div class="pagination">
+    <TMPL_IF NAME="PREVIOUS_PAGE">
+        <a href="?page=<TMPL_VAR NAME="PREVIOUS_PAGE"><TMPL_IF NAME="SEARCH_CRITERIA">&amp;<TMPL_VAR NAME="SEARCH_CRITERIA"></TMPL_IF>">&lt;&lt;</a>
+        <TMPL_LOOP NAME="PREVIOUS_PAGES">
+            <a href="?page=<TMPL_VAR NAME="PAGE"><TMPL_IF NAME="SEARCH_CRITERIA">&amp;<TMPL_VAR NAME="SEARCH_CRITERIA"></TMPL_IF>"><TMPL_VAR NAME="PAGE"></a>
+        </TMPL_LOOP>
+    <TMPL_ELSE>
+        &lt;&lt;
+    </TMPL_IF>
+    <TMPL_VAR NAME="CURRENT_PAGE">
+    <TMPL_IF NAME="NEXT_PAGE">
+        <TMPL_LOOP NAME="NEXT_PAGES">
+            <a href="?page=<TMPL_VAR NAME="PAGE"><TMPL_IF NAME="SEARCH_CRITERIA">&amp;<TMPL_VAR NAME="SEARCH_CRITERIA"></TMPL_IF>"><TMPL_VAR NAME="PAGE"></a>
+        </TMPL_LOOP>
+        <a href="?page=<TMPL_VAR NAME="NEXT_PAGE"><TMPL_IF NAME="SEARCH_CRITERIA">&amp;<TMPL_VAR NAME="SEARCH_CRITERIA"></TMPL_IF>">&gt;&gt;</a>
+    <TMPL_ELSE>
+        &gt;&gt;
+    </TMPL_IF>
+</div>
+</TMPL_IF>
+

Added: trunk/vhffs-public/templates/misc/userinfo.tmpl
===================================================================
--- trunk/vhffs-public/templates/misc/userinfo.tmpl	                        (rev 0)
+++ trunk/vhffs-public/templates/misc/userinfo.tmpl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -0,0 +1,19 @@
+<TMPL_IF NAME="USE_AVATAR">
+<img src="/getavatar.pl?oid=<TMPL_VAR ESCAPE=1 NAME="OBJECT_ID">" alt="<TMPL_VAR ESCAPE=1 NAME="USERNAME"> avatar" class="avatar"/>
+</TMPL_IF>
+<ul>
+<li>
+<TMPL_I18N KEY="Username">: <TMPL_VAR ESCAPE=1 NAME="USERNAME">
+</li>
+<li>
+<TMPL_I18N KEY="Firstname">: <TMPL_VAR ESCAPE=1 NAME="FIRSTNAME">
+</li>
+<li>
+<TMPL_I18N KEY="Lastname">: <TMPL_VAR ESCAPE=1 NAME="LASTNAME">
+</li>
+<li>
+<TMPL_INCLUDE NAME="../group_part.tmpl">
+</li>
+</ul>
+<div class="clear"></div>
+

Modified: trunk/vhffs-public/templates/user.tmpl
===================================================================
--- trunk/vhffs-public/templates/user.tmpl	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-public/templates/user.tmpl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -1,15 +1,6 @@
 <TMPL_INCLUDE NAME="banner.tmpl">
 
 <div id="public">
-<h1><TMPL_VAR ESCAPE=1 NAME="VALUE_USERNAME"></h1>
-<TMPL_IF NAME="USE_AVATAR">
-<img src="/getavatar.pl?oid=<TMPL_VAR ESCAPE=1 NAME="VALUE_OID">" alt="<TMPL_VAR ESCAPE=1 NAME="VALUE_USERNAME">" class="avatar"/>
-</TMPL_IF>
-<TMPL_VAR ESCAPE=0 NAME="IMG_AVATAR">
-<ul>
-    <li><TMPL_I18N KEY="Username">: <TMPL_VAR ESCAPE=1 NAME="VALUE_USERNAME"></li>
-    <li><TMPL_I18N KEY="Firstname">: <TMPL_VAR ESCAPE=1 NAME="VALUE_FIRSTNAME"></li>
-    <li><TMPL_I18N KEY="Lastname">: <TMPL_VAR ESCAPE=1 NAME="VALUE_LASTNAME"></li>
-    <li><TMPL_INCLUDE NAME="group_part.tmpl"></li>
-</ul>
+<h1><TMPL_VAR NAME="USERNAME"></h1>
+<TMPL_INCLUDE NAME="misc/userinfo.tmpl">
 </div>

Modified: trunk/vhffs-public/templates/userslist.tmpl
===================================================================
--- trunk/vhffs-public/templates/userslist.tmpl	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-public/templates/userslist.tmpl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -3,36 +3,8 @@
 <div id="public">
 
 <h1><TMPL_VAR ESCAPE=1 NAME="TEXT_TITLE"></h1>
-<TMPL_IF NAME="PAGES">
-    <TMPL_IF NAME="PREVIOUS_PAGE">
-        <a href="?page=<TMPL_VAR NAME="PREVIOUS_PAGE"><TMPL_IF NAME="SEARCH_CRITERIA">&amp;<TMPL_VAR NAME="SEARCH_CRITERIA"></TMPL_IF>">&lt;&lt;</a>
-    </TMPL_IF>
-    <TMPL_LOOP NAME="PAGES">
-        <a href="?page=<TMPL_VAR NAME="PAGE"><TMPL_IF NAME="SEARCH_CRITERIA">&amp;<TMPL_VAR NAME="SEARCH_CRITERIA"></TMPL_IF>"><TMPL_VAR NAME="PAGE"></a>
-    </TMPL_LOOP>
-    <TMPL_IF NAME="NEXT_PAGE">
-        <a href="?page=<TMPL_VAR NAME="NEXT_PAGE"><TMPL_IF NAME="SEARCH_CRITERIA">&amp;<TMPL_VAR NAME="SEARCH_CRITERIA"></TMPL_IF>">&gt;&gt;</a>
-    </TMPL_IF>
-</TMPL_IF>
+<TMPL_INCLUDE NAME="misc/pagination.tmpl">
 <TMPL_LOOP NAME="USERS">
-<h2><TMPL_VAR ESCAPE=1 NAME="USERNAME"></h2>
-<TMPL_IF NAME="USE_AVATAR">
-<img src="/getavatar.pl?oid=<TMPL_VAR ESCAPE=1 NAME="OBJECT_ID">" alt="<TMPL_VAR ESCAPE=1 NAME="USERNAME"> avatar" class="avatar"/>
-</TMPL_IF>
-<ul>
-<li>
-<TMPL_I18N KEY="Username">: <TMPL_VAR ESCAPE=1 NAME="USERNAME">
-</li>
-<li>
-<TMPL_I18N KEY="Firstname">: <TMPL_VAR ESCAPE=1 NAME="FIRSTNAME">
-</li>
-<li>
-<TMPL_I18N KEY="Lastname">: <TMPL_VAR ESCAPE=1 NAME="LASTNAME">
-</li>
-<li>
-<TMPL_INCLUDE NAME="group_part.tmpl">
-</li>
-</ul>
-<div class="clear"></div>
+<TMPL_INCLUDE NAME="misc/userinfo.tmpl">
 </TMPL_LOOP>
 </div>

Modified: trunk/vhffs-public/user.pl
===================================================================
--- trunk/vhffs-public/user.pl	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-public/user.pl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -65,10 +65,10 @@
     $template->param( MESSAGE => $message );
 } else {
     $template = new Vhffs::Panel::Template( filename => $templatedir.'/public/user.tmpl', loop_context_vars => 1, die_on_bad_params => 0);
-    $template->param( VALUE_OID => $user->get_oid );
-    $template->param( VALUE_USERNAME => $user->get_username );
-    $template->param( VALUE_FIRSTNAME => $user->get_firstname );
-    $template->param( VALUE_LASTNAME => $user->get_lastname );
+    $template->param( OBJECT_ID => $user->get_oid );
+    $template->param( USERNAME => $user->get_username );
+    $template->param( FIRSTNAME => $user->get_firstname );
+    $template->param( LASTNAME => $user->get_lastname );
     $template->param( GROUPS => Vhffs::Panel::User::get_groups($user) );
     $template->param( USE_AVATAR => $panel->use_users_avatars );
 }

Modified: trunk/vhffs-public/usersearch.pl
===================================================================
--- trunk/vhffs-public/usersearch.pl	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-public/usersearch.pl	2007-11-12 19:13:49 UTC (rev 1077)
@@ -38,6 +38,7 @@
 use CGI;
 
 use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Panel::Commons;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Template;
 
@@ -51,9 +52,9 @@
 $panel->check_public();
 
 my $template = new Vhffs::Panel::Template( filename => $templatedir.'/public/userslist.tmpl', die_on_bad_params => 0 );
-my $username = $cgi->param('username');
-my $firstname = $cgi->param('firstname');
-my $lastname = $cgi->param('lastname');
+my $username = $cgi->param('username') || '';
+my $firstname = $cgi->param('firstname') || '';
+my $lastname = $cgi->param('lastname') || '';
 my $page = $cgi->param('page');
 my $per_page_count = 5;
 $page = 1 unless(defined $page);
@@ -72,18 +73,9 @@
 if($result->{total_count} == 0) {
     $template->param( TEXT_TITLE => gettext('No user found') );
 } else {
-    my $max_pages = int( ($result->{total_count} + ($per_page_count - 1)) / $per_page_count );
-    if($max_pages > 1) {
-        my @params;
-        push @params, 'username='.$username unless($username =~ /^\s*$/);
-        push @params, 'firstname='.$firstname unless($firstname =~ /^\s*$/);
-        push @params, 'lastname='.$lastname unless($lastname =~ /^\s*$/);
-        $template->param( SEARCH_CRITERIA => join('&amp;', @params) );
-        $template->param( CURRENT_PAGE => $page );
-        $template->param( PAGES => paginate($page, $max_pages ) );
-        $template->param( PREVIOUS_PAGE => ($page - 1 < 1 ? 0 : $page - 1 ) );
-        $template->param( NEXT_PAGE => ($page + 1 > $max_pages ? 0 : $page + 1 ) );
-    }
+    Vhffs::Panel::Commons::paginate($template, $page, $result->{total_count}, $per_page_count,
+        { username => $username, firstname => $firstname, lastname => $lastname});
+    $template->param( USE_AVATAR => $panel->use_users_avatars );
     $template->param( TEXT_TITLE => sprintf( gettext('%d user(s) found'), $result->{total_count} ) );
     $template->param( USERS => $result->{users} );
 }
@@ -91,13 +83,3 @@
 $panel->light( $template );
 $panel->display;
 
-sub paginate {
-    my ($page, $max_pages) = @_;
-    my $pages = ();
-    for(($page - 5 < 1 ? 1 : $page - 5)..($page + 5 > $max_pages ? $max_pages : $page + 5) ) {
-        push @$pages, { PAGE => $_ };
-    }
-    return $pages;
-}
-
-

Modified: trunk/vhffs-themes/vhffs/main.css
===================================================================
--- trunk/vhffs-themes/vhffs/main.css	2007-11-12 19:12:58 UTC (rev 1076)
+++ trunk/vhffs-themes/vhffs/main.css	2007-11-12 19:13:49 UTC (rev 1077)
@@ -55,6 +55,7 @@
 #public img.avatar {
     float: left;
     margin-right:2em;
+    margin-bottom:1em;
     border: 1px solid black;
 }
 
@@ -799,3 +800,8 @@
 th.historyDate {
     width:6em;
 }
+
+div.pagination {
+    text-align:center;
+}
+


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