]> Frank Brehm's Git Trees - books.git/commitdiff
Mit neuem Buch weitergemacht
authorFrank Brehm <frank@brehm-online.com>
Mon, 24 Mar 2008 09:06:15 +0000 (09:06 +0000)
committerFrank Brehm <frank@brehm-online.com>
Mon, 24 Mar 2008 09:06:15 +0000 (09:06 +0000)
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Util/Author.pm [new file with mode: 0644]
root/src/books/book_form.tt2
root/src/books/form.css [new file with mode: 0644]

index 7f952ac2b079c0c320be75ede650c7c9da845b82..f7a6405b4505717e8213dc8628549afc9d37ae5b 100644 (file)
@@ -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 (file)
index 0000000..6f61291
--- /dev/null
@@ -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;
index 870770208cd836de7e5ece5bab409074066b02da..d4ea58d92aee34505bc192536446e41864a9f3c4 100644 (file)
@@ -7,12 +7,36 @@
 -%]
 <!-- 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">&nbsp;</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="&rArr;" class="shift_button" title="Wird Autor" /><br /><br />
+                <input type="submit" name="nach_oben"  value="&uArr;" class="shift_button" title="Autor in der Reihenfolge nach oben" /><br /><br />
+                <input type="submit" name="nach_unten" value="&dArr;" class="shift_button" title="Autor in der Reihenfolge nach unten" /><br /><br />
+                <input type="submit" name="entf_autor" value="&lArr;" 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>
@@ -43,7 +67,7 @@
     </tr><tr>
       <td colspan="2">&nbsp;</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>
diff --git a/root/src/books/form.css b/root/src/books/form.css
new file mode 100644 (file)
index 0000000..81191e8
--- /dev/null
@@ -0,0 +1,10 @@
+[%#
+   # Template fuer Stylesheets Buchformulare
+   #
+   # $Id$
+   # $URL$
+   #
+-%]
+/*  Stylesheets Formulare */
+
+