use FrBr::Common;
use FrBr::Books::Util::Book;
+use FrBr::Books::Util::Author;
=head1 NAME
};
$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;
}
--- /dev/null
+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;
-%]
<!-- Book form -->
<form method="post" name="book_form" action="[% Catalyst.request.base %][% Catalyst.request.path %]">
+<input type="hidden" name="book_form_sent" value="sent" />
[%- IF book_edit.id %]<input type="hidden" name="book_id" value="[% book_edit.id | html %]" />[% END %]
<table class="ftable" cellspacing="0">
<tr>
<th colspan="2" class="title">[% book_form_title %]</th>
</tr><tr>
<td colspan="2"> </td>
+ </tr><tr>
+ <th>Autor (-en):</th>
+ <td>
+ <table class="two_lists" cellspacing="0">
+ <tr>
+ <th>Verfügbare Autoren</th>
+ <th></th>
+ <th>Autoren des Buchs</th>
+ </tr><tr>
+ <td><select name="autor_not" size="10" multiple>
+ <option value="">-- Autor oder Autoren wählen --</option>[% FOR autor_id IN autor_list_no %]
+ <option value="[% autor_id %]">[% autor_list.$autor_id %]</option>
+ [% END %]</select></td>
+ <td><input type="submit" name="wird_autor" value="⇒" class="shift_button" title="Wird Autor" /><br /><br />
+ <input type="submit" name="nach_oben" value="⇑" class="shift_button" title="Autor in der Reihenfolge nach oben" /><br /><br />
+ <input type="submit" name="nach_unten" value="⇓" class="shift_button" title="Autor in der Reihenfolge nach unten" /><br /><br />
+ <input type="submit" name="entf_autor" value="⇐" class="shift_button" title="Autor entfernen" />
+ </td>
+ <td><select name="autor_book" size="10" multiple>
+ <option value="">-- Autor oder Autoren entfernen --</option>[% FOR autor_id IN autor_list_book %]
+ <option value="[% autor_id %]">[% autor_list.$autor_id %]</option>
+ [% END %]</select></td>
+ </tr></table></td>
</tr><tr>
<th>Buchtitel:</th>
<td><input type="text" name="book_title" size="60" maxlength="250" value="[% book_edit.title | html %]" /></td>
</tr><tr>
<td colspan="2"> </td>
</tr><tr>
- <th colspan="2" class="button"><input type="submit" name="submit" value=" OK " /></th>
+ <th colspan="2" class="button"><input type="submit" name="do_save" value=" OK " /></th>
</tr>
</table>
</form>
--- /dev/null
+[%#
+ # Template fuer Stylesheets Buchformulare
+ #
+ # $Id$
+ # $URL$
+ #
+-%]
+/* Stylesheets Formulare */
+
+