[vhffs-dev] [1821] No more HTML::Template in moderation. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1821
Author: beuss
Date: 2011-05-26 22:42:44 +0200 (Thu, 26 May 2011)
Log Message:
-----------
No more HTML::Template in moderation.
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Object.pm
trunk/vhffs-panel/Makefile.am
trunk/vhffs-panel/admin/moderation/index.pl
trunk/vhffs-panel/templates/Makefile.am
Added Paths:
-----------
trunk/vhffs-panel/templates/admin/moderation/
trunk/vhffs-panel/templates/admin/moderation/index.tt
Removed Paths:
-------------
trunk/vhffs-panel/admin/moderation/submit.pl
trunk/vhffs-panel/templates/admin/misc/moderation.tmpl
trunk/vhffs-panel/templates/admin/misc/moderation_applied.tmpl
trunk/vhffs-panel/templates/admin/misc/moderation_part.tmpl
Modified: trunk/vhffs-api/src/Vhffs/Object.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Object.pm 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-api/src/Vhffs/Object.pm 2011-05-26 20:42:44 UTC (rev 1821)
@@ -424,7 +424,7 @@
my $mail;
- if(defined $comments) {
+ if(defined $comments and $comments =~ /\S/) {
$mail = sprintf(
gettext( "Hello %s %s,\n\nYour request for a %s (%s) on %s was accepted, however, moderators wanted to add some precision:\n%s.\nPlease wait while we are creating your object.\n\nCheers,\nThe moderator team\n\n---------\n%s\n%s\n" ) ,
$user->get_firstname,
Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-panel/Makefile.am 2011-05-26 20:42:44 UTC (rev 1821)
@@ -866,7 +866,6 @@
admin/broadcast/list.pl \
admin/broadcast/view.pl \
admin/broadcast/create.pl \
- admin/moderation/submit.pl \
admin/moderation/index.pl \
admin/stats.pl \
admin/su.pl \
Modified: trunk/vhffs-panel/admin/moderation/index.pl
===================================================================
--- trunk/vhffs-panel/admin/moderation/index.pl 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-panel/admin/moderation/index.pl 2011-05-26 20:42:44 UTC (rev 1821)
@@ -32,7 +32,6 @@
use utf8;
use POSIX qw(locale_h);
-use HTML::Template;
use locale;
use Locale::gettext;
use CGI;
@@ -41,85 +40,63 @@
use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Main;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Constants;
+use Vhffs::Panel::Modo;
use Vhffs::Object;
use Vhffs::ObjectFactory;
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
+my $panel = new Vhffs::Panel::Modo();
-my $vhffs = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
+my $vhffs = $panel->{vhffs};
my $cgi = $panel->{'cgi'};
-my $servername = $cgi->param("name");
-my $templatesdir = $vhffs->get_config->get_templatedir;
-my $template;
+my $accept = $cgi->param('accept');
+my $refuse = $cgi->param('refuse');
-#Use is not allowed to see this page, only MODERATOR and ADMIN
-unless( $user->is_moderator || $user->is_admin )
-{
- $template = new HTML::Template( filename => $templatesdir.'/panel/misc/simplemsg.tmpl' );
- $template->param( MESSAGE => gettext('You\'re not allowed to do this (ACL rights)') );
+if(defined $accept || defined $refuse) {
+ # Submitted
+ my $oid = $cgi->param('oid');
+ my $message = $cgi->param('message');
+ unless(defined $oid and defined $message) {
+ $panel->add_error( gettext('CGI Error!') );
+ } else {
+ my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $oid );
+ unless(defined $object) {
+ $panel->add_error( gettext('Object not found') );
+ } else {
+ $message = Encode::decode_utf8( $message );
+ if( defined $refuse and $message !~ /\S/) {
+ $panel->add_error( gettext('You have to enter a refuse reason') );
+ } else {
+ if(defined $refuse) {
+ if($object->moderate_refuse( $message ) >= 0) {
+ $panel->add_info( gettext('Object refused') );
+ } else {
+ $panel->add_error( gettext('Error while updating object') );
+ }
+ } else {
+ if($object->moderate_accept( $message ) >= 0) {
+ $panel->add_info( gettext('Object accepted') );
+ } else {
+ $panel->add_error( gettext('Error while updating object') );
+ }
+ }
+ }
+ }
+ }
}
-else
-{
- $panel->set_title( gettext('Moderation') );
- my $objects = Vhffs::Object::getall( $vhffs, undef, Vhffs::Constants::WAITING_FOR_VALIDATION );
- unless( defined $objects ) {
- $template = new HTML::Template( filename => $templatesdir.'/panel/misc/simplemsg.tmpl' );
- $template->param( MESSAGE => gettext('There is nothing to moderate') );
- }
- else {
+$panel->set_title( gettext('Moderation') );
- $template = new HTML::Template( filename => $templatesdir.'/panel/admin/misc/moderation.tmpl' );
- $template->param( HEADER_TYPE => gettext('Type') );
- $template->param( HEADER_NAME => gettext('Name') );
- $template->param( HEADER_USER => gettext('User') );
- $template->param( HEADER_GROUP => gettext('Group') );
- $template->param( HEADER_DESCRIPTION => gettext('Description') );
- $template->param( HEADER_ACCEPT => gettext('Accept') );
- $template->param( HEADER_REFUSE => gettext('Refuse') );
-
- my $output = '';
-
- foreach ( @{$objects} ) {
-
- my $subtemplate = new HTML::Template( filename => $templatesdir.'/panel/admin/misc/moderation_part.tmpl' );
-
- my $user = $_->get_user;
- my $group = $_->get_group;
-
- my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $_->{object_id} );
- $subtemplate->param( TYPE => Vhffs::Functions::type_string_from_type_id( $_->{type} ) );
- $subtemplate->param( NAME => $object->get_label );
-
- $subtemplate->param( OWNER => $user->get_username);
-
- if( $vhffs->get_config->get_users->{'use_notation'} eq 'yes' )
- {
- $subtemplate->param( NOTE => $user->get_note );
- }
-
- $subtemplate->param( GROUP => $group->get_groupname );
-
- $subtemplate->param( OID => $_->get_oid );
- $subtemplate->param( DESCRIPTION => $_->get_description );
- $subtemplate->param( ACCEPT => gettext('Accept') );
- $subtemplate->param( REFUSE => gettext('Refuse') );
- $output .= $subtemplate->output;
- }
-
- $template->param( MODERATION => $output );
- }
+# TODO This is pure crap but I'm currently working
+# on Template::Toolkit and sweared no to touch anything
+# else...
+my $objects = Vhffs::Object::getall( $vhffs, undef, Vhffs::Constants::WAITING_FOR_VALIDATION );
+my $vars = {
+ objects => [],
+ use_notation => ( $vhffs->get_config->get_users->{'use_notation'} eq 'yes' )
+};
+foreach my $o(@$objects) {
+ push @{$vars->{objects}}, Vhffs::ObjectFactory::fetch_object( $vhffs, $o->{object_id});
}
+$panel->render('admin/moderation/index.tt', $vars);
-$panel->build( $template );
-$panel->display;
Deleted: trunk/vhffs-panel/admin/moderation/submit.pl
===================================================================
--- trunk/vhffs-panel/admin/moderation/submit.pl 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-panel/admin/moderation/submit.pl 2011-05-26 20:42:44 UTC (rev 1821)
@@ -1,105 +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 Encode;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Object;
-use Vhffs::ObjectFactory;
-
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
-
-my $cgi = $panel->{'cgi'};
-my $vhffs = $panel->{'vhffs'};
-my $user = $panel->{'user'};
-my $templatedir = $panel->{'templatedir'};
-
-my $accept = $cgi->param('ACCEPT');
-my $reason = Encode::decode_utf8( $cgi->param('reason') );
-
-my $template = new HTML::Template( filename => $templatedir.'/panel/admin/misc/moderation_applied.tmpl' );
-
-#Use is not allowed to see this page, only MODERATOR and ADMIN
-unless( $user->is_moderator || $user->is_admin )
-{
- my $message = gettext('You\'re not allowed to do this (ACL rights)');
- $template->param( MESSAGE => $message );
-}
-else
-{
- my $oid = $cgi->param('OID');
- my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $oid );
-
- if( ( ! defined $oid ) || ( ! defined $object ) || ( ! defined $accept ) )
- {
- $template->param( MESSAGE => gettext("CGI Error !") );
- }
- else
- {
- my $ok;
-
- if( $accept == 1 )
- {
- $ok = $object->moderate_accept;
- }
- else
- {
- $ok = $object->moderate_refuse( $reason );
- }
-
- if( $ok < 0 )
- {
- $template->param( MESSAGE => gettext("Cannot apply modifications") );
- }
- else
- {
- $template->param( MESSAGE => gettext("Modifications applied successfully") );
- }
- }
-}
-
-$panel->set_refresh_url( '/admin/moderation.pl' );
-$panel->build( $template );
-$panel->display;
Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-panel/templates/Makefile.am 2011-05-26 20:42:44 UTC (rev 1821)
@@ -4,10 +4,6 @@
admin/main/general.tmpl \
admin/main/main.tmpl \
admin/misc/list.tmpl \
- admin/misc/mailings_part.tmpl \
- admin/misc/moderation_applied.tmpl \
- admin/misc/moderation_part.tmpl \
- admin/misc/moderation.tmpl \
admin/misc/stats.tmpl \
admin/misc/su.tmpl \
admin/object/edit.tmpl \
@@ -37,13 +33,14 @@
misc/simplemsg.tmpl \
acl/form.tt \
acl/view.tt \
- admin/group/list.tt \
- admin/index.tt \
admin/broadcast/create.tt \
admin/broadcast/list.tt \
admin/broadcast/view.tt \
+ admin/group/list.tt \
+ admin/index.tt \
admin/misc/list.tt \
admin/misc/search.tt \
+ admin/moderation/index.tt \
admin/object/edit.tt \
admin/user/list.tt \
anonymous/account_created.tt \
Deleted: trunk/vhffs-panel/templates/admin/misc/moderation.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/misc/moderation.tmpl 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-panel/templates/admin/misc/moderation.tmpl 2011-05-26 20:42:44 UTC (rev 1821)
@@ -1,26 +0,0 @@
-<table>
-<tr>
- <th>
- <TMPL_VAR ESCAPE=1 NAME="HEADER_TYPE">
- </th>
- <th>
- <TMPL_VAR ESCAPE=1 NAME="HEADER_NAME">
- </th>
- <th>
- <TMPL_VAR ESCAPE=1 NAME="HEADER_USER">
- </th>
- <th>
- <TMPL_VAR ESCAPE=1 NAME="HEADER_GROUP">
- </th>
- <th class="mainColumn">
- <TMPL_VAR ESCAPE=1 NAME="HEADER_DESCRIPTION">
- </th>
- <th>
- <TMPL_VAR ESCAPE=1 NAME="HEADER_ACCEPT">
- </th>
- <th>
- <TMPL_VAR ESCAPE=1 NAME="HEADER_REFUSE">
- </th>
-</tr>
-<TMPL_VAR ESCAPE=0 NAME="MODERATION">
-</table>
Deleted: trunk/vhffs-panel/templates/admin/misc/moderation_applied.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/misc/moderation_applied.tmpl 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-panel/templates/admin/misc/moderation_applied.tmpl 2011-05-26 20:42:44 UTC (rev 1821)
@@ -1,2 +0,0 @@
- <h1><TMPL_VAR ESCAPE=1 NAME="MESSAGE"></h1>
-
Deleted: trunk/vhffs-panel/templates/admin/misc/moderation_part.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/misc/moderation_part.tmpl 2011-05-26 12:21:32 UTC (rev 1820)
+++ trunk/vhffs-panel/templates/admin/misc/moderation_part.tmpl 2011-05-26 20:42:44 UTC (rev 1821)
@@ -1,40 +0,0 @@
-<tr>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="TYPE">
- </td>
- <td>
- <TMPL_VAR ESCAPE=1 NAME="NAME">
- </td>
- <td>
-
- <a href="/user/prefs.pl?name=<TMPL_VAR ESCAPE=1 NAME="OWNER">">
- <TMPL_VAR ESCAPE=1 NAME="OWNER">
- </a>
- (<TMPL_VAR ESCAPE=1 NAME="NOTE">)
-
- </td>
- <td>
- <a href="/group/view.pl?group=<TMPL_VAR ESCAPE=1 NAME="GROUP">">
- <TMPL_VAR ESCAPE=1 NAME="GROUP">
- </a>
- </td>
- <td class="mainColumn">
- <TMPL_VAR ESCAPE=1 NAME="DESCRIPTION">
- </td>
- <td>
- <form method="post" action="moderation/submit.pl" accept-charset="utf-8">
- <input type="hidden" name="OID" value="<TMPL_VAR ESCAPE=1 NAME="OID">" />
- <input type="hidden" name="ACCEPT" value="1" />
- <input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="ACCEPT">" />
- </form>
- </td>
- <td>
-
- <form method="post" action="moderation/submit.pl" accept-charset="utf-8">
- <textarea name="reason" cols="30" rows="4"></textarea>
- <input type="hidden" name="OID" value="<TMPL_VAR ESCAPE=1 NAME="OID">" />
- <input type="hidden" name="ACCEPT" value="0" />
- <input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="REFUSE">" />
- </form>
- </td>
-</tr>
Added: trunk/vhffs-panel/templates/admin/moderation/index.tt
===================================================================
--- trunk/vhffs-panel/templates/admin/moderation/index.tt (rev 0)
+++ trunk/vhffs-panel/templates/admin/moderation/index.tt 2011-05-26 20:42:44 UTC (rev 1821)
@@ -0,0 +1,37 @@
+[% IF objects.size() > 0 %]
+<table>
+ <thead>
+ <tr>
+ <th>[% 'Type' | i18n | html %]</th>
+ <th>[% 'Name' | i18n | html %]</th>
+ <th>[% 'Owner' | i18n | html %]</th>
+ <th>[% 'Group' | i18n | html %]</th>
+ <th class="mainColumn">[% 'Description' | i18n | html %]</th>
+ <th>[% 'Action' | i18n | html %]</th>
+ </tr>
+ </thead>
+ <tbody>
+[% FOREACH o IN objects %]
+ <tr>
+ <td>[% o.type | stringify_type | i18n | html %]</td>
+ <td>[% o.label | html %]</td>
+ <td><a href="/user/prefs.pl?name=[% o.get_user.get_username | html %]">[% o.get_user.get_username | html %]</a>
+ [% '(' _ o.get_user.get_note _ ')' IF use_notation %]</td>
+ <td><a href="/group/view.pl?group=[% o.get_group.get_groupname | html %]">[% o.get_group.get_groupname | html %]</a></td>
+ <td class="mainColumn">[% o.get_description | html_para %]</td>
+ <td>
+ <form action="/admin/moderation/index.pl" method="post" accept-charset="utf-8">
+ <p><textarea name="message" cols="30" rows="4"></textarea></p>
+ <p>
+ <input type="hidden" name="oid" value="[% o.get_oid %]"/>
+ <input type="submit" name="accept" value="[% 'Accept' | i18n | html %]"/>
+ <input type="submit" name="refuse" value="[% 'Refuse' | i18n | html %]"/></p>
+ </form>
+ </td>
+ </tr>
+[% END %]
+ </tbody>
+</table>
+[% ELSE %]
+<p>[% 'No object waiting for validation.' | i18n | html %]</p>
+[% END %]