# Soll die Log-Ausgabe farbig erfolgen ?
colored_log: 0
#
+# Standard-Listenlaenge
+default_list_length: 10
+#
# Sitzungsparameter
session:
expires: 7200
sub auto : Private {
my ( $self, $c ) = @_;
- my $K = __PACKAGE__ . "::auto(): ";
+ my $K = ( caller(0) )[3] . "(): ";
my $self_url = $c->request->base . $c->request->path;
$self_url =~ s#^https?://[^/]+/#/#;
$c->log->debug( $K . "Aktuelle Script-URL: '" . $c->stash->{'self_url'} . "'." ) if $c->stash->{'debug_level'} >= 2;
+ # Listenlaenge festlegen
+ $c->stash->{'list_length'} = $c->session->{'list_length'} || $c->config->{'default_list_length'} || 10;
+
+
1;
} ## end sub auto :
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
+=head1 INTERNA
+
+=head2 Sitzungs-Variablen:
+
+=over 4
+
+=item I<last_run>: Zeitstempel des letzten Durchlaufs
+
+=item I<last_path>: URL des letzten Requests
+
+=item I<cur_path>: URL des aktuellen Requests
+
+=item I<request>: Hash-Ref mit ein paar Angaben zum aktuellen Request:
+
+ 'request' => {
+ 'client' => '192.166.201.59',
+ 'host' => 'sarah',
+ 'uagent' => 'Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.4) Gecko/2008111819 Gentoo Firefox/3.0.4',
+ 'uri' => bless( do{\(my $o = 'http://sarah.brehm-online.com:3000/books/list')}, 'URI::http' )
+ },
+
+=item I<list_length>: die aktuelle Listenlaenge
+
+=back
+
=cut
1;
$self->add_booklist_menu($c);
- my $buchliste = get_booklist( $c );
+ my $page = $c->session->{'book_list_page'} || 1;
+ my $list_length = $c->stash->{'list_length'} || 10;
+
+ if ( $c->request->params->{'page'} and to_int( $c->request->params->{'page'} ) ) {
+ $page = to_int( $c->request->params->{'page'} );
+ $c->session->{'book_list_page'} = $page;
+ }
+
+ my ( $buchliste, $anzahl ) = get_booklist( $c, { 'page' => $page } );
+ my $max_page = 1;
+ if ( $anzahl ) {
+ $max_page = int( $anzahl / $list_length ) + 1;
+ if ( ( $page - 1 ) * $list_length > $anzahl ) {
+ $page = $max_page;
+ $c->session->{'book_list_page'} = $page;
+ }
+ }
+ else {
+ $page = 1;
+ $c->session->{'book_list_page'} = 1;
+ }
+
+ $c->stash->{'book_liste_page'} = {};
+ $c->stash->{'book_liste_page'}{'cur'} = $page;
+ $c->stash->{'book_liste_page'}{'first'} = 1;
+ $c->stash->{'book_liste_page'}{'last'} = $max_page;
+ $c->stash->{'book_liste_page'}{'prev'} = ( $page > 1 ) ? ( $page - 1 ) : 1;
+ $c->stash->{'book_liste_page'}{'next'} = ( ( $page + 1 ) > $max_page ) ? $max_page : ( $page + 1 );
+ $c->stash->{'book_liste_page'}{'books'} = $anzahl;
+ $c->stash->{'book_liste_page'}{'book_from'} = $anzahl ? ( ( $page - 1 ) * $list_length ) + 1 : 0;
+ $c->stash->{'book_liste_page'}{'book_to'} = ( $page * $list_length ) > $anzahl ? $anzahl : ( $page * $list_length );
+ $c->log->debug( get_output_string( $K, "Seitennavigation: ", $c->stash->{'book_liste_page'} ) ) if $c->stash->{'debug_level'} >= 2;
+
$c->log->debug( get_output_string( $K, "Erhaltene Buchliste: ", $buchliste ) ) if $c->stash->{'debug_level'} >= 2;
$c->stash->{'books'} = $buchliste;
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
+=head1 INTERNA
+
+=head2 Sitzungs-Variablen:
+
+=over 4
+
+=item I<book_data_edit>: die aktuellen daten des zu bearbeitenden Buches, bevor sie gespeichert werden
+
+=item I<delete_book_id>: die Id des zu loeschenden Buches
+
+=item I<list_length>: die aktuelle Listenlaenge
+
+=item I<return_target_autor_save>: URI fuer den Zurueck-Knopf auf der C<Erfolgreich gespeichert>-Seite
+
+=item I<return_target_del>: URI fuer den Zurueck-Knopf im Loeschen-Formular
+
+=item I<return_target_edit>: URI fuer den Zurueck-Knopf im Bearbeiten-Formular
+
+=item I<return_target_new>: URI fuer den Zurueck-Knopf im Neuen-Buch-Formular
+
+=item I<return_target_view>: URI fuer den Zurueck-Knopf im Betrachten-Formular
+
+=item I<from_book_list>: boolscher Flag, ob man aus der Buecherliste ins Formular kam oder aus dem Menue
+
+=back
+
=cut
#-------------------------------------------------------
my $list = [];
my $buchmap = {},
+ my $anzahl_buecher = 0;
+
+ # Suchparameter zusammensammeln
+ my $b_search_params = {};
- my $b_search_params = undef;
if ( $params->{'buch_id'} ) {
- $b_search_params = { 'me.id' => $params->{'buch_id'} };
+ $b_search_params->{'me.id'} = $params->{'buch_id'};
}
+ # Suchparameter auf undef setzen, falls es keine gibt.
+ $b_search_params = undef unless scalar keys %$b_search_params;
+
my $other_params = {};
$other_params->{'order_by'} = [ 'title' ];
$other_params->{'join'} = [ 'waehrung', 'verlag', 'ort', 'bindungsart' ];
+
+ $anzahl_buecher = $c->model('Schema::Buecher')->count( $b_search_params, $other_params );
+ $c->log->debug( get_output_string( $K, "Anzahl gefundene Buecher: ", $anzahl_buecher ) ) if $c->stash->{'debug_level'} >= 2;
+
+ $other_params->{'rows'} = $c->stash->{'list_length'} || 10;
+ $other_params->{'page'} = $params->{'page'} || $c->stash->{'page'} || 1;
+
$other_params->{'select'} = [
'me.id',
'me.title',
$i++;
}
- return $list unless scalar( @$list );
+ return ( wantarray ? ( $list, 0 ) : $list ) unless scalar( @$list );
# Autoren zusammensammeln
my $a_search_params = {};
push @{$buch->{'serien_ids'}}, $sid;
}
- return $list;
+ return ( wantarray ? ( $list, $anzahl_buecher ) : $list );
}
#-----------------------------------------------------------------------------------
[% META title = 'Bücherliste' -%]
+[% BLOCK navrow %]
+ <tr>
+ <td class="nav" colspan="8"><table cellspacing="0" class="nav" width="100%">
+ <tr>
+ <td width="33%" style="text-align: left;"><b>[% IF book_liste_page.cur != 1 %]<a href="[% self_url %]?page=1" title="Erste Seite"><<</a>[% ELSE %]<<[% END %] [% IF book_liste_page.cur != book_liste_page.prev %]<a href="[% self_url %]?page=[% book_liste_page.prev %]" title="Vorherige Seite"><</a>[% ELSE %]<[% END %]</b></td>
+ <td width="33%" style="text-align: center;">Buch [% book_liste_page.book_from %] bis [% book_liste_page.book_to %] von [% book_liste_page.books %]</td>
+ <td width="33%" style="text-align: right;"><b>[% IF book_liste_page.cur != book_liste_page.next %]<a href="[% self_url %]?page=[% book_liste_page.next %]" title="Nächste Seite">></a>[% ELSE %]>[% END %] [% IF book_liste_page.cur != book_liste_page.last %]<a href="[% self_url %]?page=[% book_liste_page.last %]" title="Letzte Seite">>></a>[% ELSE %]>>[% END %]</b></td>
+ </tr>
+ </table></td>
+ </tr>
+[% END -%]
+
<div class="center">
<table class="wrapper" cellspacing="0">
<th></th>
<th></th>
<th></th>
- </tr>
+ </tr>[% PROCESS navrow %]
[% rowstyle = 'even' %][%- FOREACH book IN books -%][% buch_id = book.id %]
<tr>
<td class="[% rowstyle %]">[% tt_authors = [ ]; tt_authors.push(autor) FOREACH autor = book.autoren %][% tt_authors.join(', ') %]</td>
<td class="[% rowstyle %] button"><a href="[% path('/books/delete') %]?delete_book_id=[% book.id %]">Löschen</a></td>
</tr>
[% IF rowstyle == 'even' %][% rowstyle = 'odd'%][% ELSE %][% rowstyle = 'even' %][% END %][% END -%]
-</table></td></tr></table>
+[% PROCESS navrow %]</table></td></tr></table>
</div>