From 70aa55286cee9606f9d11a214036251e6774409e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 11 Nov 2008 14:58:53 +0000 Subject: [PATCH] Neuen Aufbewahrungsort gespeichert --- lib/FrBr/Books/Controller/Ort.pm | 254 +++++++++++++++++++++++++++++ lib/FrBr/Books/Controller/Serie.pm | 2 +- lib/FrBr/Books/Util/Ort.pm | 47 ++++++ root/src/books/book_form.tt2 | 5 + root/src/index.tt2 | 8 + root/src/ort/form.css | 10 ++ root/src/ort/form.tt2 | 42 +++++ root/src/ort/index.tt2 | 47 ++++++ root/src/ort/new.tt2 | 16 ++ root/src/ort/save_success.tt2 | 17 ++ root/src/ort/styles.css | 10 ++ 11 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 lib/FrBr/Books/Controller/Ort.pm create mode 100644 root/src/ort/form.css create mode 100644 root/src/ort/form.tt2 create mode 100644 root/src/ort/index.tt2 create mode 100644 root/src/ort/new.tt2 create mode 100644 root/src/ort/save_success.tt2 create mode 100644 root/src/ort/styles.css diff --git a/lib/FrBr/Books/Controller/Ort.pm b/lib/FrBr/Books/Controller/Ort.pm new file mode 100644 index 0000000..e77245d --- /dev/null +++ b/lib/FrBr/Books/Controller/Ort.pm @@ -0,0 +1,254 @@ +package FrBr::Books::Controller::Ort; + +# $Id$ +# $URL$ + +use strict; +use warnings; +use base 'Catalyst::Controller'; + +use FrBr::Common; +use FrBr::Books::Util::Ort; + +=head1 NAME + +FrBr::Books::Controller::Ort - Catalyst Controller fuer alles rund um Aufbewahrungsorte + +=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("/ort"), + 'name' => "Aufbewahrungsort" + }; + + $c->stash->{'cssfiles'} = [] unless $c->stash->{'cssfiles'}; + push @{$c->stash->{'cssfiles'}}, 'ort/styles.css'; + + 1; + +} ## end sub auto : + +#------------------------------------------------------- + +=head2 index + +=cut + +sub index : Private { + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->stash->{'template'} = 'ort/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("/ort/default"), + 'name' => "Nicht Implementiert" + }; + +} ## end sub default : + +#------------------------------------------------------- + +=head2 form_new( ) + +Erstellen eines neuen Aufbewahrungsortes. + +=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("/ort/new"), + 'name' => "Neu" + }; + + $c->stash->{'template'} = 'ort/new.tt2'; + push @{$c->stash->{'cssfiles'}}, 'ort/form.css'; + + $c->stash->{'error_message'} = ''; + +# $self->prepare_data_structures($c); + + $self->ort_cgi2session($c); + + $c->stash->{'ort_edit'} = {} unless $c->stash->{'ort_edit'}; + $self->ort_session2stash($c); + $c->stash->{'ort_edit'}{'name'} = "Neuer Aufbewahrungsort" unless $c->stash->{'ort_edit'}{'name'}; + $c->stash->{'ort_edit'}{'descr'} = "Beschreibung des Aufbewahrungsortes" unless defined $c->stash->{'ort_edit'}{'descr'}; + + return 1 unless $c->request->params->{'ort_form_sent'} and $c->request->params->{'do_save'}; + + return $self->do_save_ort($c); + +} + +#------------------------------------------------------- + +sub do_save_ort : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + return 1 unless $self->check_formparams($c); + + eval { + die "Speichern des Aufbewahrungsortes mißlungen." unless save_ort( $c, $c->stash->{'ort_edit'} ); + }; + if ( $@ ) { + $c->stash->{'error_message'} = $@; + return undef; + } + + $c->stash->{'template'} = 'ort/save_success.tt2'; + delete $c->session->{'ort_data_edit'} if exists $c->session->{'ort_data_edit'}; + delete $c->session->{'return_target_ort_save'} if exists $c->session->{'return_target_ort_save'}; + + return 1; + +} + +#------------------------------------------------------- + +sub check_formparams : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + unless ( $c->stash->{'ort_edit'} ) { + $c->stash->{'error_message'} = "Interner Fehler"; + return undef; + } + + unless ( $c->stash->{'ort_edit'}{'name'} ) { + $c->stash->{'error_message'} = "Kein Name des Aufbewahrungsortes angegeben."; + return undef; + } + + $c->stash->{'ort_edit'}{'statisch'} = to_bool( $c->stash->{'ort_edit'}{'statisch'} ) ? 'y' : 'n'; + + return 1; + +} + +#------------------------------------------------------- + +sub ort_cgi2session : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->session->{'return_target_ort_save'} = $c->request->params->{'return_target_form'} if $c->request->params->{'return_target_form'}; + + return 1 unless $c->request->params->{'ort_form_sent'}; + + # Basis anlegen, wenn notwendig + $c->session->{'ort_data_edit'} = {} unless $c->session->{'ort_data_edit'}; + + # Orts-Id eintragen, wenn notwendig + $c->session->{'ort_data_edit'}{'id'} = $c->request->params->{'orts_id'} if $c->request->params->{'orts_id'}; + + # Name der Serie + if ( defined $c->request->params->{'orts_name'} ) { + my $name = $c->request->params->{'orts_name'}; + $name =~ s/^\s+//; + $name =~ s/\s+$//; + $c->session->{'ort_data_edit'}{'name'} = $name; + } + + # Beschreibung der Serie + if ( defined $c->request->params->{'orts_descr'} ) { + my $descr = $c->request->params->{'orts_descr'}; + $descr =~ s/^\s+//; + $descr =~ s/\s+$//; + $c->session->{'ort_data_edit'}{'descr'} = $descr; + } + else { + $c->session->{'ort_data_edit'}{'descr'} = ''; + } + + # ist es statischer (nicht änderbarer) Aufbewahrungsort ? + $c->session->{'ort_data_edit'}{'statisch'} = to_bool( $c->request->params->{'ort_statisch'} ) ? 'y' : 'n'; + + return 1; + +} + +#------------------------------------------------------- + +sub ort_session2stash : Private { + + my ( $self, $c ) = @_; + my $K = ( caller(0) )[3] . "(): "; + + $c->log->debug( get_output_string( $K . "Aufbewahrungsort in der Session:", $c->session->{'ort_data_edit'} ) ) if $c->stash->{'debug_level'} > 2; + + $c->stash->{'ort_edit'} = {} unless $c->stash->{'ort_edit'}; + $c->stash->{'ort_edit'}{'id'} = $c->session->{'ort_data_edit'}{'id'} if $c->session->{'ort_data_edit'}{'id'}; + $c->stash->{'ort_edit'}{'name'} = $c->session->{'ort_data_edit'}{'name'} if $c->session->{'ort_data_edit'}{'name'}; + $c->stash->{'ort_edit'}{'descr'} = $c->session->{'ort_data_edit'}{'descr'}; + $c->stash->{'ort_edit'}{'statisch'} = $c->session->{'ort_data_edit'}{'statisch'}; + + $c->stash->{'return_target_ort_save'} = $c->session->{'return_target_ort_save'} || $c->web_path('/ort'); + + 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/Controller/Serie.pm b/lib/FrBr/Books/Controller/Serie.pm index 0acdfd9..4d2859e 100644 --- a/lib/FrBr/Books/Controller/Serie.pm +++ b/lib/FrBr/Books/Controller/Serie.pm @@ -222,7 +222,7 @@ sub serie_session2stash : Private { $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'); + $c->stash->{'return_target_serie_save'} = $c->session->{'return_target_serie_save'} || $c->web_path('/serie'); return 1; diff --git a/lib/FrBr/Books/Util/Ort.pm b/lib/FrBr/Books/Util/Ort.pm index 502e371..3cbb9cc 100644 --- a/lib/FrBr/Books/Util/Ort.pm +++ b/lib/FrBr/Books/Util/Ort.pm @@ -23,6 +23,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &get_ortsliste + &save_ort ); #%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], @@ -117,6 +118,52 @@ sub get_ortsliste { #----------------------------------------------------------------------------------- +=head2 save_ort( $c, $ort ) + +=cut + +sub save_ort { + + my $c = shift; + my $ort = 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, $orts_id, $orts_name, $orts_desc, $statisch ) = @_; + my $sql = <debug() ) { + my $text = $sql; + $text =~ s/\s+$//; + $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $orts_id, $orts_name, $orts_desc, $statisch, $orts_name, $orts_desc, $statisch ) ) . "\n"; + warn $text; + } + + my $sth = $dbh->prepare($sql); + $sth->execute( $orts_id, $orts_name, $orts_desc, $statisch, $orts_name, $orts_desc, $statisch ); + }; + + my $static = to_bool( $ort->{'statisch'} ) ? 'y' : 'n'; + + $storage->dbh_do( $save_func, $ort->{'id'}, $ort->{'name'}, $ort->{'descr'}, $static ); + + 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 1d6e0dc..2019296 100644 --- a/root/src/books/book_form.tt2 +++ b/root/src/books/book_form.tt2 @@ -32,6 +32,11 @@ function goto_new_serie() { window.location.href = target; } +function goto_new_ort() { + var target = '[% Catalyst.web_path( '/ort/new', { 'return_target_form' => self_url } ) %]'; + window.location.href = target; +} + //]]>
diff --git a/root/src/index.tt2 b/root/src/index.tt2 index acee9fd..9bb2cb3 100644 --- a/root/src/index.tt2 +++ b/root/src/index.tt2 @@ -54,6 +54,14 @@   Buchserien + + +   + + +   + + Aufbewahrungsorte diff --git a/root/src/ort/form.css b/root/src/ort/form.css new file mode 100644 index 0000000..db1f3c0 --- /dev/null +++ b/root/src/ort/form.css @@ -0,0 +1,10 @@ +[%# + # Template fuer Stylesheets Aufbewahrungsorte + # + # $Id$ + # $URL$ + # +-%] +/* Stylesheets Aufbewahrungsorte */ + + diff --git a/root/src/ort/form.tt2 b/root/src/ort/form.tt2 new file mode 100644 index 0000000..6cd7384 --- /dev/null +++ b/root/src/ort/form.tt2 @@ -0,0 +1,42 @@ +[%# + + Template für Formular Aufbewahrungsorte + + vim: noai : ts=4 fenc=utf-8 filetype=html expandtab : + + $Id$ + $URL$ + +-%] + + + + + + +[%- IF ort_edit.id %][% END %] + + + + + + + + + + + + + + + + + + +
[% ort_form_title %]
 
Bezeichnung des Aufbewahrungsortes:
 
Beschreibung:
 
+
+[%- IF error_message %] +
+Fehler: [% error_message %] +
+[% END -%] diff --git a/root/src/ort/index.tt2 b/root/src/ort/index.tt2 new file mode 100644 index 0000000..8be4883 --- /dev/null +++ b/root/src/ort/index.tt2 @@ -0,0 +1,47 @@ +[%# + + index.tt2 - Index-Template (Menue) fuer Aufbewahrungsorte + + vim: noai : ts=4 fenc=utf-8 filetype=html expandtab : + + $Id$ + $URL$ + +-%] +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/root/src/ort/new.tt2 b/root/src/ort/new.tt2 new file mode 100644 index 0000000..be9f240 --- /dev/null +++ b/root/src/ort/new.tt2 @@ -0,0 +1,16 @@ +[%# + + Template für neuen Aufbewahrungsort + + vim: noai : ts=4 fenc=utf-8 filetype=html expandtab : + + $Id$ + $URL$ + +-%] +[%- serie_form_title = 'Neuer Aufbewahrungsort' -%] +[% PROCESS ort/form.tt2 %] + + diff --git a/root/src/ort/save_success.tt2 b/root/src/ort/save_success.tt2 new file mode 100644 index 0000000..ce40e1b --- /dev/null +++ b/root/src/ort/save_success.tt2 @@ -0,0 +1,17 @@ +[%# + + save_success.tt2 - Template fuer erfolgreiches Speichern des Aufbewahrungsortes + + vim: noai : ts=4 fenc=utf-8 filetype=html expandtab : + + $Id$ + $URL$ + +-%] +
+ +Der Aufbewahrungsort "[% ort_edit.name %] wurde erfolgreich gespeichert. + +

OK

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