From: Frank Brehm Date: Thu, 27 Mar 2008 18:19:35 +0000 (+0000) Subject: Mit Autorenformular angefangen X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=4e110a1b50dae39478561c5df4f5ca1eead25d46;p=books.git Mit Autorenformular angefangen --- diff --git a/lib/FrBr/Books.pm b/lib/FrBr/Books.pm index 01f3184..4192593 100644 --- a/lib/FrBr/Books.pm +++ b/lib/FrBr/Books.pm @@ -62,6 +62,7 @@ __PACKAGE__->config( 'dbic_class' => 'Schema::Session', 'expires' => 3600, 'private_data' => [ + 'autor_data_edit', 'book_data_edit', ], }, diff --git a/lib/FrBr/Books/Controller/Autor.pm b/lib/FrBr/Books/Controller/Autor.pm new file mode 100644 index 0000000..947432c --- /dev/null +++ b/lib/FrBr/Books/Controller/Autor.pm @@ -0,0 +1,217 @@ +package FrBr::Books::Controller::Autor; + +# $Id$ +# $URL$ + +use strict; +use warnings; +use base 'Catalyst::Controller'; + +use FrBr::Common; +use FrBr::Books::Util::Author; + +=head1 NAME + +FrBr::Books::Controller::Autor - Catalyst Controller fuer alle Autorensachen + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + +#------------------------------------------------------- + +=head2 auto + +=cut + +sub auto : Private { + + my ( $self, $c ) = @_; + my $K = __PACKAGE__ . "::auto(): "; + + $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("/autor"), + 'name' => "Autoren" + }; + + $c->stash->{'cssfiles'} = [] unless $c->stash->{'cssfiles'}; + push @{$c->stash->{'cssfiles'}}, 'autor/styles.css'; + + 1; + +} ## end sub auto : + +#------------------------------------------------------- + +=head2 index + +=cut + +sub index : Private { + my ( $self, $c ) = @_; + + $c->stash->{'template'} = 'autor/index.tt2'; + +} + +#------------------------------------------------------- + +=head2 default + +=cut + +sub default : Private { + + my ( $self, $c ) = @_; + my $K = __PACKAGE__ . "::default(): "; + + $c->stash->{'template'} = 'not_implemented.tt2'; + + push @{ $c->stash->{'menu_path'} }, { + 'path' => $c->web_path("/autor/default"), + 'name' => "Nicht Implementiert" + }; + +} ## end sub default : + +#------------------------------------------------------- + +=head2 form_new( ) + +Erstellen eines neuen Autors. + +=cut + +sub form_new : Path('new') { + + my ( $self, $c ) = @_; + my $K = __PACKAGE__ . "::form_new(): "; + + $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("/autor/new"), + 'name' => "Neu" + }; + + $c->stash->{'template'} = 'autor/new.tt2'; + push @{$c->stash->{'cssfiles'}}, 'autor/form.css'; + + $c->stash->{'error_message'} = ''; + +# $self->prepare_data_structures($c); + + $self->autor_cgi2session($c); + + $c->stash->{'autor_edit'} = {} unless $c->stash->{'autor_edit'}; + $self->autor_session2stash($c); + $c->stash->{'autor_edit'}{'name'} = "Neuer Autor" unless $c->stash->{'autor_edit'}{'name'}; + + return 1 unless $c->request->params->{'autor_form_sent'} and $c->request->params->{'do_save'}; + return 1 unless $self->check_formparams($c); + + return 1; + +} + +#------------------------------------------------------- + +sub save_author : Private { + + my ( $self, $c ) = @_; + my $K = __PACKAGE__ . "::save_author(): "; + + + +} + +#------------------------------------------------------- + +sub check_formparams : Private { + + my ( $self, $c ) = @_; + my $K = __PACKAGE__ . "::check_formparams(): "; + + unless ( $c->stash->{'autor_edit'} ) { + $c->stash->{'error_message'} = "Interner Fehler"; + return undef; + } + + unless ( $c->stash->{'autor_edit'} ) { + $c->stash->{'error_message'} = "Kein Name des Autors angegeben."; + return undef; + } + + return 1; + +} + +#------------------------------------------------------- + +sub autor_session2stash : Private { + + my ( $self, $c ) = @_; + my $K = __PACKAGE__ . "::autor_session2stash(): "; + + $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'}; + + return 1; + +} + +#------------------------------------------------------- + +sub autor_cgi2session : Private { + + my ( $self, $c ) = @_; + my $K = __PACKAGE__ . "::autor_cgi2session(): "; + + return 1 unless $c->request->params->{'autor_form_sent'}; + + # Basis anlegen, wenn notwendig + $c->session->{'autor_data_edit'} = {} unless $c->session->{'autor_data_edit'}; + + # Autor-Id eintragen, wenn notwendig + $c->session->{'autor_data_edit'}{'id'} = $c->request->params->{'autor_id'} if $c->request->params->{'autor_id'}; + + # Name des Autors + if ( defined $c->request->params->{'autor_name'} ) { + my $name = $c->request->params->{'autor_name'}; + $name =~ s/^\s+//; + $name =~ s/\s+$//; + $c->session->{'autor_data_edit'}{'name'} = $name; + } + + # Untertitel + $c->session->{'autor_data_edit'}{'desc'} = $c->request->params->{'autor_desc'} if defined $c->request->params->{'autor_desc'}; + + 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; diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index 3469735..7c01385 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -54,7 +54,6 @@ sub auto : Private { #------------------------------------------------------- - =head2 index =cut diff --git a/lib/FrBr/Books/Util/Author.pm b/lib/FrBr/Books/Util/Author.pm index 6f61291..d9624bc 100644 --- a/lib/FrBr/Books/Util/Author.pm +++ b/lib/FrBr/Books/Util/Author.pm @@ -23,6 +23,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &get_author_list + &save_autor ); #%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], @@ -113,6 +114,50 @@ sub get_author_list { #----------------------------------------------------------------------------------- +=head2 save_autor( $c, $autor ) + +=cut + +sub save_autor { + + my $c = shift; + my $autor = shift; + my $K = __PACKAGE__ . "::save_autor(): "; + + $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2; + + my $storage = $c->stash->{'storage'}; + + my $save_func = sub { + my ( $storage, $dbh, $autor_id, $name, $desc ) = @_; + my $sql = <debug() ) { + my $text = $sql; + $text =~ s/\s+$//; + $text .= ": " . join( ", ", map { $dbh->quote($_) } ( $uid, $ptype_id, $value, $value ) ) . "\n"; + warn $text; + } + + my $sth = $dbh->prepare($sql); + $sth->execute( $autor_id, $name, $desc, $name, $desc ); + }; + + $storage->dbh_do( $save_func, $autor->{'id'}, $autor->{'name'}, $autor->{'desc'} ); + + return $storage->last_insert_id(); + +} + +#----------------------------------------------------------------------------------- + =head1 AUTHOR Frank Brehm diff --git a/root/src/autor/autor_form.tt2 b/root/src/autor/autor_form.tt2 new file mode 100644 index 0000000..709c233 --- /dev/null +++ b/root/src/autor/autor_form.tt2 @@ -0,0 +1,36 @@ +[%# + Template fuer Autorenangaben + + $Id$ + $URL$ + +-%] + + + +
+ +[%- IF autor_edit.id %][% END %] + + + + + + + + + + + + + + + + +
[% autor_form_title %]
 
Name des Autors:
Zusätzliche Angaben:
 
+
+[%- IF error_message %] +
+Fehler: [% error_message %] +
+[% END -%] diff --git a/root/src/autor/form.css b/root/src/autor/form.css new file mode 100644 index 0000000..79ffe51 --- /dev/null +++ b/root/src/autor/form.css @@ -0,0 +1,10 @@ +[%# + # Template fuer Stylesheets Autorenformulare + # + # $Id$ + # $URL$ + # +-%] +/* Stylesheets Autoren-Formulare */ + + diff --git a/root/src/autor/index.tt2 b/root/src/autor/index.tt2 new file mode 100644 index 0000000..31d1330 --- /dev/null +++ b/root/src/autor/index.tt2 @@ -0,0 +1,45 @@ +[%# + + index.tt2 - Index-Template (Menue) fuer Autoren-Dinge + + #$Id$ + #$URL$ + +-%] +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/root/src/autor/new.tt2 b/root/src/autor/new.tt2 new file mode 100644 index 0000000..bb27468 --- /dev/null +++ b/root/src/autor/new.tt2 @@ -0,0 +1,13 @@ +[%# + Template fuer neuen Autor + + $Id$ + $URL$ + +-%] +[%- autor_form_title = 'Neuer Autor' -%] +[% PROCESS autor/autor_form.tt2 %] + + diff --git a/root/src/autor/styles.css b/root/src/autor/styles.css new file mode 100644 index 0000000..98edb6e --- /dev/null +++ b/root/src/autor/styles.css @@ -0,0 +1,10 @@ +[%# + # Template fuer Stylesheets Autoren + # + # $Id$ + # $URL$ + # +-%] +/* Stylesheets Autoren */ + + diff --git a/t/controller_Autor.t b/t/controller_Autor.t new file mode 100644 index 0000000..1224a59 --- /dev/null +++ b/t/controller_Autor.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More tests => 3; + +BEGIN { use_ok 'Catalyst::Test', 'FrBr::Books' } +BEGIN { use_ok 'FrBr::Books::Controller::Autor' } + +ok( request('/autor')->is_success, 'Request should succeed' ); + +