From 03f7403d2f9c7b0f3ef6606f8ea2491560d3e865 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 24 Mar 2008 09:06:15 +0000 Subject: [PATCH] Mit neuem Buch weitergemacht --- lib/FrBr/Books/Controller/Books.pm | 24 +++++- lib/FrBr/Books/Util/Author.pm | 127 +++++++++++++++++++++++++++++ root/src/books/book_form.tt2 | 26 +++++- root/src/books/form.css | 10 +++ 4 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 lib/FrBr/Books/Util/Author.pm create mode 100644 root/src/books/form.css diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index 7f952ac..f7a6405 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -9,6 +9,7 @@ use base 'Catalyst::Controller'; use FrBr::Common; use FrBr::Books::Util::Book; +use FrBr::Books::Util::Author; =head1 NAME @@ -132,12 +133,33 @@ sub form_new : Path('new') { }; $c->stash->{'template'} = 'books/new.tt2'; + push @{$c->stash->{'cssfiles'}}, 'books/form.css'; $c->stash->{'error_message'} = ''; $c->stash->{'book_edit'} = {}; $c->stash->{'book_edit'}{'title'} = 'Neues Buch'; - unless ( $c->request->params->{'do_save'} ) { + my $autor_list_complete = get_author_list($c); + + $c->stash->{'autor_list_book'} = []; + $c->stash->{'autor_list_no'} = [ map { $_->{'id'} } @$autor_list_complete ]; + + $c->stash->{'autor_list'} = {}; + for my $autor ( @$autor_list_complete ) { + $c->stash->{'autor_list'}{ $autor->{'id'} } = $autor->{'name'}; + } + + $c->log->debug( get_output_string( $K . "Autoren gesamt: ", $autor_list_complete ) ); + $autor_list_complete = undef; + $c->log->debug( get_output_string( $K . "Autoren-Hash: ", $c->stash->{'autor_list'} ) ); + $c->log->debug( get_output_string( $K . "Autoren des Buches: ", $c->stash->{'autor_list_book'} ) ); + $c->log->debug( get_output_string( $K . "Autoren, die fehlen: ", $c->stash->{'autor_list_no'} ) ); + + unless ( $c->request->params->{'book_form_sent'} ) { + return 1; + } + + if ( $c->request->params->{'wird_autor'} ) { return 1; } diff --git a/lib/FrBr/Books/Util/Author.pm b/lib/FrBr/Books/Util/Author.pm new file mode 100644 index 0000000..6f61291 --- /dev/null +++ b/lib/FrBr/Books/Util/Author.pm @@ -0,0 +1,127 @@ +package FrBr::Books::Util::Author; + +# $Id$ +# $URL$ + +use strict; +use warnings; + +use FrBr::Common; + +# Export-Deklarationen + +BEGIN { + + use Exporter(); + our ( $VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); + + # set the version for version checking + $VERSION = 0.1; + my ($rev) = '$Revision$' =~ /(\d+)/; + $VERSION = sprintf( $VERSION . ".%d", $rev ); + + @ISA = qw(Exporter); + @EXPORT = qw( + &get_author_list + ); + + #%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], + + # your exported package globals go here, + # as well as any optionally exported functions + #@EXPORT_OK = qw($Var1 %Hashit &func3); +} ## end BEGIN + +our @EXPORT_OK; + +=head1 NAME + +FrBr::Books::Util::Author - Modul fuer Funktionen rund um Autoren + +=head1 METHODS + +=cut + +#----------------------------------------------------------------------------------- + +=head2 get_author_list( $c, $params ) + +Sammelt alle Autoren zusammen. + +Folgende benannte Parameter koennen ueber $params uebergeben werden: + +Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Autoren, die den uebergebenen Suchkriterien entsprechen: + + $res = [ + { 'id' => 1, + 'name' => 'J.R.R. Tolkien', + 'descr' => 'Bla Blub', + }, + { 'id' => 2, + ... + }, + ... + ]; + +Die Liste ist nach den Autor-Namen alphabetisch sortiert. + +=cut + +sub get_author_list { + + my $c = shift; + my $K = __PACKAGE__ . "::get_author_list(): "; + + $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; + + my $params = {}; + if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) { + $params = $_[0]; + } + else { + %$params = @_; + } + $c->log->debug( get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2; + + my $list = []; + + my $search_params = undef; + + my $other_params = {}; + $other_params->{'order_by'} = [ 'autor_name' ]; + $other_params->{'select'} = [ + 'id', + 'autor_name', + 'autor_descr', + ]; + $other_params->{'as'} = [ + 'id', + 'autor_name', + 'autor_descr', + ]; + + for my $autor_rs ( $c->model('Schema::Autoren')->search( $search_params, $other_params )->all() ) { + my $autor = {}; + $autor->{'id'} = $autor_rs->id(); + $autor->{'name'} = $autor_rs->autor_name(); + $autor->{'descr'} = $autor_rs->autor_descr(); + push @$list, $autor; + } + + return $list; +} + +#----------------------------------------------------------------------------------- + +=head1 AUTHOR + +Frank Brehm + +=head1 LICENSE + +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; diff --git a/root/src/books/book_form.tt2 b/root/src/books/book_form.tt2 index 8707702..d4ea58d 100644 --- a/root/src/books/book_form.tt2 +++ b/root/src/books/book_form.tt2 @@ -7,12 +7,36 @@ -%]
+ [%- IF book_edit.id %][% END %] + + + @@ -43,7 +67,7 @@ - +
[% book_form_title %]
 
Autor (-en): + + + + + + + + + +
Verfügbare AutorenAutoren des Buchs


+

+

+ +
Buchtitel:
 
diff --git a/root/src/books/form.css b/root/src/books/form.css new file mode 100644 index 0000000..81191e8 --- /dev/null +++ b/root/src/books/form.css @@ -0,0 +1,10 @@ +[%# + # Template fuer Stylesheets Buchformulare + # + # $Id$ + # $URL$ + # +-%] +/* Stylesheets Formulare */ + + -- 2.39.5