[vhffs-dev] [1203] This should fix #239.

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


Revision: 1203
Author:   beuss
Date:     2008-05-23 19:26:28 +0200 (Fri, 23 May 2008)

Log Message:
-----------
This should fix #239.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Main.pm
    trunk/vhffs-api/src/Vhffs/Tag/Request.pm
    trunk/vhffs-panel/Makefile.am
    trunk/vhffs-panel/admin/tag/category/create.pl
    trunk/vhffs-panel/admin/tag/request/list.pl
    trunk/vhffs-panel/templates/Makefile.am
    trunk/vhffs-panel/templates/admin/tag/request/list.tmpl

Added Paths:
-----------
    trunk/vhffs-panel/admin/tag/request/details.pl
    trunk/vhffs-panel/templates/admin/tag/request/details.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Main.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2008-05-23 16:29:12 UTC (rev 1202)
+++ trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2008-05-23 17:26:28 UTC (rev 1203)
@@ -649,6 +649,7 @@
 	my $templatedir = $panel->{templatedir};
 
 	$panel->add_info( Encode::decode_utf8( $cgi->param('msg') ) ) if( defined $cgi->param('msg') );
+	$panel->add_error( Encode::decode_utf8( $cgi->param('error') ) ) if( defined $cgi->param('error') );
 
 	my $paneltemplate = new HTML::Template( filename => $templatedir.'/panel/main/panel.tmpl' );
 	$paneltemplate->param( THEME => $theme );

Modified: trunk/vhffs-api/src/Vhffs/Tag/Request.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Tag/Request.pm	2008-05-23 16:29:12 UTC (rev 1202)
+++ trunk/vhffs-api/src/Vhffs/Tag/Request.pm	2008-05-23 17:26:28 UTC (rev 1203)
@@ -128,4 +128,12 @@
 	return $self->{tagged};
 }
 
+sub delete {
+	my ($self) = @_;
+
+	my $sql = q{DELETE FROM vhffs_tag_request WHERE tag_request_id = ?};
+	my $dbh = $self->{main}->get_db_object();
+	return $dbh->do($sql, undef, $self->{request_id});
+}
+
 1;

Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am	2008-05-23 16:29:12 UTC (rev 1202)
+++ trunk/vhffs-panel/Makefile.am	2008-05-23 17:26:28 UTC (rev 1203)
@@ -64,6 +64,7 @@
 	admin/tag/category/create.pl \
 	admin/tag/category/edit.pl \
 	admin/tag/category/list.pl \
+	admin/tag/request/details.pl \
 	admin/tag/request/list.pl \
 	admin/git/index.pl \
 	admin/git/list.pl \

Modified: trunk/vhffs-panel/admin/tag/category/create.pl
===================================================================
--- trunk/vhffs-panel/admin/tag/category/create.pl	2008-05-23 16:29:12 UTC (rev 1202)
+++ trunk/vhffs-panel/admin/tag/category/create.pl	2008-05-23 17:26:28 UTC (rev 1203)
@@ -90,6 +90,11 @@
 		return 0;
 	}
 	
+	if($label =~ /^\s*$/ || $description =~ /^\s*$/) {
+		$panel->add_error( gettext('You have to enter a label and a description for the category') );
+		return 0;
+	}
+	
 	if(!defined Vhffs::Tag::Category::create($vhffs, $label, $description, $visibility, $panel->{user})) {
 		$panel->add_error( gettext('Unable to create category') );
 		return 0;

Added: trunk/vhffs-panel/admin/tag/request/details.pl
===================================================================
--- trunk/vhffs-panel/admin/tag/request/details.pl	                        (rev 0)
+++ trunk/vhffs-panel/admin/tag/request/details.pl	2008-05-23 17:26:28 UTC (rev 1203)
@@ -0,0 +1,207 @@
+#!%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.
+
+# details.pl - Displays details about a tag request and
+#              allows moderator to accept or reject it. 
+
+use utf8;
+use POSIX qw(locale_h);
+use DateTime;
+use DateTime::Locale;
+use locale;
+use Locale::gettext;
+use CGI;
+use CGI::Session;
+use Encode;
+use strict;
+
+use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Main;
+use Vhffs::ObjectFactory;
+use Vhffs::Panel::Main;
+use Vhffs::Panel::Template;
+use Vhffs::Tag;
+use Vhffs::Tag::Category;
+use Vhffs::Tag::Request;
+   
+my $panel = new Vhffs::Panel::Main();
+exit 0 unless $panel;
+my $session = $panel->get_session;
+exit 0 unless $session;
+my $templatedir = $panel->{'templatedir'};
+my $cgi = $panel->{cgi};
+my $vhffs = $panel->{vhffs};
+
+$panel->check_modo;
+
+my $request_id;
+
+unless(defined ($request_id = $cgi->param('request_id'))) {
+	my $url = '/admin/tag/request/list.pl?error='.gettext('CGI Error');
+	$panel->redirect($url);
+}
+
+my $request;
+
+unless(defined ($request = Vhffs::Tag::Request::get_by_request_id($vhffs, $request_id))) {
+	my $url = '/admin/tag/request/list.pl?error='.gettext('Tag request not found');
+	$panel->redirect($url);
+}
+
+my $template = new Vhffs::Panel::Template( filename => $templatedir.'/panel/admin/tag/request/details.tmpl', die_on_bad_params => 0 );
+
+if(defined $cgi->param('accept_request_submit')) {
+	if(accept_request()) {
+		my $url = '/admin/tag/request/list.pl?msg='.gettext('Tag request accepted');
+		$panel->redirect($url);
+	} else {
+		$template->param('CATEGORY' => $cgi->param('category_label'));
+		$template->param('CATEGORY_DESCRIPTION' => $cgi->param('category_description'));
+		$template->param('TAG' => $cgi->param('tag_label'));
+		$template->param('TAG_DESCRIPTION' => $cgi->param('tag_description'));
+	}
+} else {
+	$template->param('CATEGORY' => $request->{category_label});
+	$template->param('TAG' => $request->{tag_label});
+}
+
+my $user = $panel->{user};
+$panel->set_title( gettext('Tag request details') );
+my $loc = DateTime::Locale->load($user->get_lang);
+
+my $dt = DateTime->from_epoch( epoch => $request->{created}, locale => $user->get_lang);
+
+$template->param('REQUEST_ID' => $request->{request_id});
+$template->param('REQUESTER' => $request->get_requester->get_username);
+$template->param('TAGGED' => $request->get_tagged->get_label);
+$template->param('CREATED' =>  $dt->strftime($loc->medium_date_format().' '.$loc->long_time_format()));
+$template->param('CATEGORIES' => Vhffs::Tag::Category::get_all($vhffs));
+
+my $category_id = $cgi->param('category');
+
+if(defined $category_id) {
+	$template->param('TAGS' => Vhffs::Tag::get_by_category_id($vhffs, $category_id));
+	$template->param('SELECTED_CATEGORY_ID' => $category_id);
+} else {
+	# Avoid warning in tmpl_expr
+	$template->param('SELECTED_CATEGORY_ID' => -1);
+}
+
+
+$panel->build($template);
+$panel->display;
+
+
+sub accept_request {
+	my $category_id = $cgi->param('category');
+	my $category_label = $cgi->param('category_label');
+	my $tag_id = $cgi->param('tag');
+	my $tag_label = $cgi->param('tag_label');
+	my $category_description = $cgi->param('category_description');
+	my $tag_description = $cgi->param('tag_description');
+	
+	unless(defined $category_id && defined $category_label && defined $category_description
+			&& defined $tag_id && defined $tag_label && defined $tag_description) {
+		$panel->add_error(gettext('CGI Error'));
+		return 0;
+	}
+	
+	my $category;
+	my $tag;
+	
+	if($category_id < 0) {
+		if($tag_id > 0) {
+			$panel->add_error( gettext('If you want to create a new category, you have to create a new tag too') );
+			return 0;
+		}
+		
+		if($category_label =~ /^\s*$/ || $category_description =~ /^\s*$/) {
+			$panel->add_error( gettext('You have to enter a label and a description for the category') );
+			return 0;
+		}
+		
+		if($tag_label =~ /^\s*$/ || $tag_description =~ /^\s*$/) {
+			$panel->add_error( gettext('You have to enter a label and a description for the tag') );
+			return 0;
+		}
+		
+		unless(defined ($category = Vhffs::Tag::Category::create($vhffs, $category_label, $category_description, Vhffs::Constants::TAG_VISIBILITY_PUBLIC, $panel->{user}) ) ) {
+			$panel->add_error( gettext('Unable to create category') );
+			return 0;
+		}
+		
+		unless(defined ($tag = Vhffs::Tag::create($vhffs, $tag_label, $tag_description, $panel->{user}, $category) ) ) {
+			$panel->add_error( gettext('Unable to create tag') );
+			$category->delete();
+			return 0;
+		}
+	} else {
+		$category = Vhffs::Tag::Category::get_by_category_id($vhffs, $category_id);
+		unless(defined $category) {
+			$panel->add_error( gettext('Category not found') );
+			return 0;
+		}
+		
+		if($tag_id > 0) {
+			$tag = Vhffs::Tag::get_by_tag_id($vhffs, $tag_id);
+			unless( defined($tag) ) {
+				$panel->add_error( gettext('Tag not found') );
+				return 0;
+			}
+		} else {
+			if($tag_label =~ /^\s*$/ || $tag_description =~ /^\s*$/) {
+				$panel->add_error( gettext('You have to enter a label and a description for the tag') );
+				return 0;
+			}
+			
+			$tag = Vhffs::Tag::create($vhffs, $tag_label, $tag_description, $panel->{user}, $category);
+			
+			unless(defined $tag) {
+				$panel->add_error( gettext('Unable to create tag') );
+				return 0;
+			}
+		}
+	}
+	
+	# Adds the tag to the object for which it has
+	# been requested.
+	
+	my $object = $request->get_tagged();
+	if(defined $object) {
+		$user = $request->get_requester();
+		$user = $panel->{user} unless(defined $user);
+		$object->add_tag($tag, $user);
+	}
+	
+	$request->delete();
+	
+	return 1;
+}

Modified: trunk/vhffs-panel/admin/tag/request/list.pl
===================================================================
--- trunk/vhffs-panel/admin/tag/request/list.pl	2008-05-23 16:29:12 UTC (rev 1202)
+++ trunk/vhffs-panel/admin/tag/request/list.pl	2008-05-23 17:26:28 UTC (rev 1203)
@@ -36,7 +36,6 @@
 use DateTime::Locale;
 use locale;
 use Locale::gettext;
-use CGI::Carp;
 use CGI;
 use CGI::Session;
 use Encode;

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2008-05-23 16:29:12 UTC (rev 1202)
+++ trunk/vhffs-panel/templates/Makefile.am	2008-05-23 17:26:28 UTC (rev 1203)
@@ -44,6 +44,7 @@
 	admin/tag/category/create.tmpl \
 	admin/tag/category/edit.tmpl \ 
 	admin/tag/category/list.tmpl \
+	admin/tag/request/details.tmpl \
 	admin/tag/request/list.tmpl \
 	admin/git/part.tmpl \
 	admin/git/search.tmpl \

Added: trunk/vhffs-panel/templates/admin/tag/request/details.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/tag/request/details.tmpl	                        (rev 0)
+++ trunk/vhffs-panel/templates/admin/tag/request/details.tmpl	2008-05-23 17:26:28 UTC (rev 1203)
@@ -0,0 +1,45 @@
+<p><label><TMPL_I18N KEY="Category"></label><TMPL_VAR ESCAPE=1 NAME="CATEGORY"></p>
+<p><label><TMPL_I18N KEY="Tag"></label><TMPL_VAR ESCAPE=1 NAME="TAG"></p>
+<p><label><TMPL_I18N KEY="Requester"></label><TMPL_VAR ESCAPE=1 NAME="REQUESTER"></p>
+<p><label><TMPL_I18N KEY="Tagged object"></label><TMPL_VAR ESCAPE=1 NAME="TAGGED"></p>
+<p><label><TMPL_I18N KEY="Date"></label><TMPL_VAR NAME="CREATED"></p>
+<p class="info"><TMPL_I18N KEY="You can either accept the request (and possibly change the name of the tag/category) or reattach it to an existing category and/or tag. If you choose to create a category, you've to create the tag too."></p>
+<fieldset>
+<legend><TMPL_I18N KEY="Manage request"></legend>
+<form name="manageTagRequestForm" id="manageTagRequestForm" action="#" method="post">
+<div style="width:50%;float:left">
+<h3>Category</h3>
+<p><select name="category" id="tagRequestCategorySelect">
+<option value="-1">--- <TMPL_I18N KEY="Create category"></option>
+<TMPL_LOOP NAME="CATEGORIES">
+<option value="<TMPL_VAR NAME="category_id">"<TMPL_IF EXPR="SELECTED_CATEGORY_ID == category_id"> selected="selected"</TMPL_IF>><TMPL_VAR NAME="label"></option>
+</TMPL_LOOP>
+</select></p>
+<p><input type="text" name="category_label" value="<TMPL_VAR NAME="CATEGORY">"/></p>
+<p><textarea name="category_description" style="width:90%"><TMPL_VAR NAME="CATEGORY_DESCRIPTION"></textarea></p>
+</div>
+<div style="width:50%; float:right">
+<h3>Tag</h3>
+<select name="tag">
+<option value="-1">--- <TMPL_I18N KEY="Create tag"></option>
+<TMPL_LOOP NAME="TAGS">
+<option value="<TMPL_VAR NAME="tag_id">"><TMPL_VAR NAME="label"></option>
+</TMPL_LOOP>
+</select>
+<p><input type="text" name="tag_label" value="<TMPL_VAR NAME="TAG">"/></p>
+<p><textarea name="tag_description" style="width:90%"><TMPL_VAR NAME="TAG_DESCRIPTION"></textarea></p>
+</div>
+<div style="clear:both"></div>
+<p class="button">
+	<input type="submit" name="accept_request_submit" value="<TMPL_I18N KEY="Accept">"/>&nbsp;
+	<input type="submit" name="discard_request_submit" value="<TMPL_I18N KEY="Refuse">"/>
+</p>
+<input type="hidden" name="request_id" value="<TMPL_VAR NAME="REQUEST_ID">"/>
+</form>
+</fieldset>
+<script type="text/javascript">
+Event.observe($('tagRequestCategorySelect'), 'change', function(e) {
+	$('manageTagRequestForm').submit();
+});
+</script>
+

Modified: trunk/vhffs-panel/templates/admin/tag/request/list.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/tag/request/list.tmpl	2008-05-23 16:29:12 UTC (rev 1202)
+++ trunk/vhffs-panel/templates/admin/tag/request/list.tmpl	2008-05-23 17:26:28 UTC (rev 1203)
@@ -13,7 +13,8 @@
 <tbody>
 <TMPL_LOOP NAME="REQUESTS">
 <tr>
-	<td><TMPL_VAR NAME="category_label"></td>
+	<td><a href="/admin/tag/request/details.pl?request_id=<TMPL_VAR NAME="request_id">">
+		<TMPL_VAR NAME="category_label"></a></td>
 	<td><TMPL_VAR NAME="tag_label"></td>
 	<td><TMPL_VAR NAME="user"></td>
 	<td><TMPL_VAR NAME="object"></td>


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