From ac242cea90313a9ce5caebaa92bb279649b75563 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 11 Nov 2008 12:26:23 +0000 Subject: [PATCH] Neue Buchserie angefangen, mit Unterbringungsorten angefangen --- lib/FrBr/Books/Controller/Autor.pm | 22 +-- lib/FrBr/Books/Controller/Serie.pm | 248 +++++++++++++++++++++++++++++ lib/FrBr/Books/Db/Buecher.pm | 2 + lib/FrBr/Books/Db/Orte.pm | 32 ++++ lib/FrBr/Books/Util/Serie.pm | 47 +++++- root/src/books/book_form.tt2 | 7 +- root/src/index.tt2 | 8 + root/src/serie/form.css | 10 ++ root/src/serie/form.tt2 | 41 +++++ root/src/serie/index.tt2 | 47 ++++++ root/src/serie/new.tt2 | 16 ++ root/src/serie/save_success.tt2 | 17 ++ root/src/serie/styles.css | 10 ++ 13 files changed, 494 insertions(+), 13 deletions(-) create mode 100644 lib/FrBr/Books/Controller/Serie.pm create mode 100644 lib/FrBr/Books/Db/Orte.pm create mode 100644 root/src/serie/form.css create mode 100644 root/src/serie/form.tt2 create mode 100644 root/src/serie/index.tt2 create mode 100644 root/src/serie/new.tt2 create mode 100644 root/src/serie/save_success.tt2 create mode 100644 root/src/serie/styles.css diff --git a/lib/FrBr/Books/Controller/Autor.pm b/lib/FrBr/Books/Controller/Autor.pm index 56c6f07..19e4723 100644 --- a/lib/FrBr/Books/Controller/Autor.pm +++ b/lib/FrBr/Books/Controller/Autor.pm @@ -31,7 +31,7 @@ Catalyst Controller. sub auto : Private { my ( $self, $c ) = @_; - my $K = __PACKAGE__ . "::auto(): "; + my $K = ( caller(0) )[3] . "(): "; $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; @@ -70,7 +70,7 @@ sub index : Private { sub default : Private { my ( $self, $c ) = @_; - my $K = __PACKAGE__ . "::default(): "; + my $K = ( caller(0) )[3] . "(): "; $c->stash->{'template'} = 'not_implemented.tt2'; @@ -92,7 +92,7 @@ Erstellen eines neuen Autors. sub form_new : Path('new') { my ( $self, $c ) = @_; - my $K = __PACKAGE__ . "::form_new(): "; + my $K = ( caller(0) )[3] . "(): "; $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; @@ -115,8 +115,6 @@ sub form_new : Path('new') { $self->autor_session2stash($c); $c->stash->{'autor_edit'}{'name'} = "Neuer Autor" unless $c->stash->{'autor_edit'}{'name'}; - $c->stash->{'return_target_autor_save'} = $c->session->{'return_target_autor_save'} || $c->web_path('/autor'); - return 1 unless $c->request->params->{'autor_form_sent'} and $c->request->params->{'do_save'}; return $self->save_author($c); @@ -128,7 +126,7 @@ sub form_new : Path('new') { sub save_author : Private { my ( $self, $c ) = @_; - my $K = __PACKAGE__ . "::save_author(): "; + my $K = ( caller(0) )[3] . "(): "; return 1 unless $self->check_formparams($c); @@ -153,7 +151,7 @@ sub save_author : Private { sub check_formparams : Private { my ( $self, $c ) = @_; - my $K = __PACKAGE__ . "::check_formparams(): "; + my $K = ( caller(0) )[3] . "(): "; unless ( $c->stash->{'autor_edit'} ) { $c->stash->{'error_message'} = "Interner Fehler"; @@ -174,13 +172,15 @@ sub check_formparams : Private { sub autor_session2stash : Private { my ( $self, $c ) = @_; - my $K = __PACKAGE__ . "::autor_session2stash(): "; + my $K = ( caller(0) )[3] . "(): "; $c->stash->{'autor_edit'} = {} unless $c->stash->{'autor_edit'}; $c->stash->{'autor_edit'}{'id'} = $c->session->{'autor_data_edit'}{'id'} if $c->session->{'autor_data_edit'}{'id'}; $c->stash->{'autor_edit'}{'name'} = $c->session->{'autor_data_edit'}{'name'} if $c->session->{'autor_data_edit'}{'name'}; $c->stash->{'autor_edit'}{'desc'} = $c->session->{'autor_data_edit'}{'desc'} if $c->session->{'autor_data_edit'}{'desc'}; + $c->stash->{'return_target_autor_save'} = $c->session->{'return_target_autor_save'} || $c->web_path('/autor'); + return 1; } @@ -190,12 +190,12 @@ sub autor_session2stash : Private { sub autor_cgi2session : Private { my ( $self, $c ) = @_; - my $K = __PACKAGE__ . "::autor_cgi2session(): "; - - return 1 unless $c->request->params->{'autor_form_sent'}; + my $K = ( caller(0) )[3] . "(): "; $c->session->{'return_target_autor_save'} = $c->request->params->{'return_target_form'} if $c->request->params->{'return_target_form'}; + return 1 unless $c->request->params->{'autor_form_sent'}; + # Basis anlegen, wenn notwendig $c->session->{'autor_data_edit'} = {} unless $c->session->{'autor_data_edit'}; diff --git a/lib/FrBr/Books/Controller/Serie.pm b/lib/FrBr/Books/Controller/Serie.pm new file mode 100644 index 0000000..0acdfd9 --- /dev/null +++ b/lib/FrBr/Books/Controller/Serie.pm @@ -0,0 +1,248 @@ +package FrBr::Books::Controller::Serie; + +# $Id$ +# $URL$ + +use strict; +use warnings; +use base 'Catalyst::Controller'; + +use FrBr::Common; +use FrBr::Books::Util::Serie; + +=head1 NAME + +FrBr::Books::Controller::Serie - Catalyst Controller fuer alles rund um Buchserien + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + +#------------------------------------------------------- + +=head2 auto + +=cut + +sub auto : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; + + $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'}; + push @{ $c->stash->{'menu_path'} }, { + 'path' => $c->web_path("/serie"), + 'name' => "Serie" + }; + + $c->stash->{'cssfiles'} = [] unless $c->stash->{'cssfiles'}; + push @{$c->stash->{'cssfiles'}}, 'serie/styles.css'; + + 1; + +} ## end sub auto : + +#------------------------------------------------------- + +=head2 index + +=cut + +sub index : Private { + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->stash->{'template'} = 'serie/index.tt2'; +} + +#------------------------------------------------------- + +=head2 default + +=cut + +sub default : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->stash->{'template'} = 'not_implemented.tt2'; + + push @{ $c->stash->{'menu_path'} }, { + 'path' => $c->web_path("/serie/default"), + 'name' => "Nicht Implementiert" + }; + +} ## end sub default : + +#------------------------------------------------------- + +=head2 form_new( ) + +Erstellen einer neuen Buchserie. + +=cut + +sub form_new : Path('new') { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; + + $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'}; + push @{ $c->stash->{'menu_path'} }, { + 'path' => $c->web_path("/serie/new"), + 'name' => "Neu" + }; + + $c->stash->{'template'} = 'serie/new.tt2'; + push @{$c->stash->{'cssfiles'}}, 'serie/form.css'; + + $c->stash->{'error_message'} = ''; + +# $self->prepare_data_structures($c); + + $self->serie_cgi2session($c); + + $c->stash->{'serie_edit'} = {} unless $c->stash->{'serie_edit'}; + $self->serie_session2stash($c); + $c->stash->{'serie_edit'}{'name'} = "Neue Buchserie" unless $c->stash->{'serie_edit'}{'name'}; + $c->stash->{'serie_edit'}{'descr'} = "Beschreibung der Buchserie" unless defined $c->stash->{'serie_edit'}{'descr'}; + + return 1 unless $c->request->params->{'serie_form_sent'} and $c->request->params->{'do_save'}; + + return $self->do_save_serie($c); + +} + +#------------------------------------------------------- + +sub do_save_serie : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + return 1 unless $self->check_formparams($c); + + eval { + die "Speichern der Buchserie mißlungen." unless save_serie( $c, $c->stash->{'serie_edit'} ); + }; + if ( $@ ) { + $c->stash->{'error_message'} = $@; + return undef; + } + + $c->stash->{'template'} = 'serie/save_success.tt2'; + delete $c->session->{'serie_data_edit'} if exists $c->session->{'serie_data_edit'}; + delete $c->session->{'return_target_serie_save'} if exists $c->session->{'return_target_serie_save'}; + + return 1; + +} + +#------------------------------------------------------- + +sub check_formparams : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + unless ( $c->stash->{'serie_edit'} ) { + $c->stash->{'error_message'} = "Interner Fehler"; + return undef; + } + + unless ( $c->stash->{'serie_edit'}{'name'} ) { + $c->stash->{'error_message'} = "Kein Name der Buchserie angegeben."; + return undef; + } + + return 1; + +} + +#------------------------------------------------------- + +sub serie_cgi2session : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->session->{'return_target_serie_save'} = $c->request->params->{'return_target_form'} if $c->request->params->{'return_target_form'}; + + return 1 unless $c->request->params->{'serie_form_sent'}; + + # Basis anlegen, wenn notwendig + $c->session->{'serie_data_edit'} = {} unless $c->session->{'serie_data_edit'}; + + # Serien-Id eintragen, wenn notwendig + $c->session->{'serie_data_edit'}{'id'} = $c->request->params->{'serien_id'} if $c->request->params->{'serien_id'}; + + # Name der Serie + if ( defined $c->request->params->{'serien_name'} ) { + my $name = $c->request->params->{'serien_name'}; + $name =~ s/^\s+//; + $name =~ s/\s+$//; + $c->session->{'serie_data_edit'}{'name'} = $name; + } + + # Beschreibung der Serie + if ( defined $c->request->params->{'serien_descr'} ) { + my $descr = $c->request->params->{'serien_descr'}; + $descr =~ s/^\s+//; + $descr =~ s/\s+$//; + $c->session->{'serie_data_edit'}{'descr'} = $descr; + } + else { + $c->session->{'serie_data_edit'}{'descr'} = ''; + } + + return 1; + +} + +#------------------------------------------------------- + +sub serie_session2stash : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->log->debug( get_output_string( $K . "Buchserie in der Session:", $c->session->{'serie_data_edit'} ) ) if $c->stash->{'debug_level'} > 2; + + $c->stash->{'serie_edit'} = {} unless $c->stash->{'serie_edit'}; + $c->stash->{'serie_edit'}{'id'} = $c->session->{'serie_data_edit'}{'id'} if $c->session->{'serie_data_edit'}{'id'}; + $c->stash->{'serie_edit'}{'name'} = $c->session->{'serie_data_edit'}{'name'} if $c->session->{'serie_data_edit'}{'name'}; + $c->stash->{'serie_edit'}{'descr'} = $c->session->{'serie_data_edit'}{'descr'}; + + $c->stash->{'return_target_serie_save'} = $c->session->{'return_target_serie_save'} || $c->web_path('/kategorie'); + + return 1; + +} + +#------------------------------------------------------- + +=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; + +__END__ + +# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab : diff --git a/lib/FrBr/Books/Db/Buecher.pm b/lib/FrBr/Books/Db/Buecher.pm index 8840bfa..a7979de 100644 --- a/lib/FrBr/Books/Db/Buecher.pm +++ b/lib/FrBr/Books/Db/Buecher.pm @@ -17,6 +17,7 @@ __PACKAGE__->add_columns( "untertitel" => { data_type => "VARCHAR", default_value => undef, is_nullable => 1, size => 250, }, "bindungsart_id" => { data_type => "INT", default_value => undef, is_nullable => 1, size => 10 }, "verlags_id" => { data_type => "INT", default_value => undef, is_nullable => 0, size => 10 }, + "orts_id" => { data_type => "INT", default_value => undef, is_nullable => 1, size => 10 }, "isbn" => { data_type => "VARCHAR", default_value => undef, is_nullable => 1, size => 20, }, "buch_nr" => { data_type => "VARCHAR", default_value => undef, is_nullable => 1, size => 100, }, "ausgabejahr" => { data_type => "MEDIUMINT", default_value => undef, is_nullable => 1, size => 8, }, @@ -30,6 +31,7 @@ __PACKAGE__->set_primary_key("id"); __PACKAGE__->might_have( 'waehrung' => 'FrBr::Books::Db::Waehrungen', { 'foreign.id' => 'self.waehrungs_id' } ); __PACKAGE__->might_have( 'verlag' => 'FrBr::Books::Db::Verlage', { 'foreign.id' => 'self.verlags_id' } ); +__PACKAGE__->might_have( 'ort' => 'FrBr::Books::Db::Orte', { 'foreign.id' => 'self.orts_id' } ); __PACKAGE__->might_have( 'bindungsart' => 'FrBr::Books::Db::Bindungsarten', { 'foreign.id' => 'self.bindungsart_id' } ); # Created by DBIx::Class::Schema::Loader v0.04004 @ 2008-03-17 17:53:52 diff --git a/lib/FrBr/Books/Db/Orte.pm b/lib/FrBr/Books/Db/Orte.pm new file mode 100644 index 0000000..a34246b --- /dev/null +++ b/lib/FrBr/Books/Db/Orte.pm @@ -0,0 +1,32 @@ +package FrBr::Books::Db::Orte; + +# $Id$ +# $URL$ + +use strict; +use warnings; + +use base 'DBIx::Class'; + +__PACKAGE__->load_components("Core"); +__PACKAGE__->table("orte"); +__PACKAGE__->add_columns( + "id" => { data_type => "INT", default_value => undef, is_nullable => 0, size => 10 }, + "name" => { data_type => "VARCHAR", default_value => undef, is_nullable => 0, size => 100, }, + "descr" => { data_type => "TEXT", default_value => undef, is_nullable => 0, size => 65535, }, + "statisch" => { data_type => "ENUM", default_value => "n", is_nullable => 0, size => 1 }, +); +__PACKAGE__->set_primary_key("id"); +__PACKAGE__->add_unique_constraint("name", ["name"]); + + +# Created by DBIx::Class::Schema::Loader v0.04004 @ 2008-03-17 17:53:52 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QwPjYKNwUnR5b418xxulDg + + +# You can replace this text with custom content, and it will be preserved on regeneration +1; + +__END__ + +# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab : diff --git a/lib/FrBr/Books/Util/Serie.pm b/lib/FrBr/Books/Util/Serie.pm index b654b8f..f9e4523 100644 --- a/lib/FrBr/Books/Util/Serie.pm +++ b/lib/FrBr/Books/Util/Serie.pm @@ -23,6 +23,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &get_serienliste + &save_serie ); #%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], @@ -71,7 +72,7 @@ Die Liste ist nach den Serien-Namen alphabetisch sortiert. sub get_serienliste { my $c = shift; - my $K = __PACKAGE__ . "::get_serienliste(): "; + my $K = ( caller(0) )[3] . "(): "; $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; @@ -131,6 +132,50 @@ sub get_serienliste { #----------------------------------------------------------------------------------- +=head2 save_serie( $c, $serie ) + +=cut + +sub save_serie { + + my $c = shift; + my $serie = shift; + my $K = ( caller(0) )[3] . "(): "; + + $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; + + my $storage = $c->stash->{'storage'}; + + my $save_func = sub { + my ( $storage, $dbh, $serien_id, $serien_name, $serien_desc ) = @_; + my $sql = <debug() ) { + my $text = $sql; + $text =~ s/\s+$//; + $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $serien_id, $serien_name, $serien_desc, $serien_name, $serien_desc ) ) . "\n"; + warn $text; + } + + my $sth = $dbh->prepare($sql); + $sth->execute( $serien_id, $serien_name, $serien_desc, $serien_name, $serien_desc ); + }; + + $storage->dbh_do( $save_func, $serie->{'id'}, $serie->{'name'}, $serie->{'descr'} ); + + return $storage->last_insert_id(); + +} + +#----------------------------------------------------------------------------------- + =head1 AUTHOR Frank Brehm diff --git a/root/src/books/book_form.tt2 b/root/src/books/book_form.tt2 index 8073815..abeb566 100644 --- a/root/src/books/book_form.tt2 +++ b/root/src/books/book_form.tt2 @@ -27,6 +27,11 @@ function goto_new_category() { window.location.href = target; } +function goto_new_serie() { + var target = '[% Catalyst.web_path( '/serie/new', { 'return_target_form' => self_url } ) %]'; + window.location.href = target; +} + //]]>
@@ -112,7 +117,7 @@ function goto_new_category() { [% END %]

-

+

+[%- IF serie_edit.id %][% END %] + + + + + + + + + + + + + + + + + + +
[% serie_form_title %]
 
Buchserie:
 
Beschreibung:
 
+
+[%- IF error_message %] +
+Fehler: [% error_message %] +
+[% END -%] diff --git a/root/src/serie/index.tt2 b/root/src/serie/index.tt2 new file mode 100644 index 0000000..be4375f --- /dev/null +++ b/root/src/serie/index.tt2 @@ -0,0 +1,47 @@ +[%# + + index.tt2 - Index-Template (Menue) fuer Buchserien + + vim: noai : ts=4 fenc=utf-8 filetype=html expandtab : + + $Id$ + $URL$ + +-%] +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/root/src/serie/new.tt2 b/root/src/serie/new.tt2 new file mode 100644 index 0000000..14dfd2d --- /dev/null +++ b/root/src/serie/new.tt2 @@ -0,0 +1,16 @@ +[%# + + Template für neue Buchserie + + vim: noai : ts=4 fenc=utf-8 filetype=html expandtab : + + $Id$ + $URL$ + +-%] +[%- serie_form_title = 'Neue Buchserie' -%] +[% PROCESS serie/form.tt2 %] + + diff --git a/root/src/serie/save_success.tt2 b/root/src/serie/save_success.tt2 new file mode 100644 index 0000000..fb77d17 --- /dev/null +++ b/root/src/serie/save_success.tt2 @@ -0,0 +1,17 @@ +[%# + + save_success.tt2 - Template fuer erfolgreiches Speichern der Buchserie + + vim: noai : ts=4 fenc=utf-8 filetype=html expandtab : + + $Id$ + $URL$ + +-%] +
+ +Die Buchserie "[% serie_edit.name %] wurde erfolgreich gespeichert. + +

OK

+ +
diff --git a/root/src/serie/styles.css b/root/src/serie/styles.css new file mode 100644 index 0000000..e2133b4 --- /dev/null +++ b/root/src/serie/styles.css @@ -0,0 +1,10 @@ +/* [%# + # Template fuer Stylesheets Buchserien + # + # $Id$ + # $URL$ + # +-%] + Stylesheets Buchserien */ + + -- 2.39.5