From f7c5a192d38e41ae20ad97eaf17948c76c95e9fd Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 10 Dec 2008 13:10:27 +0000 Subject: [PATCH] =?utf8?q?Buch=20Neu,=20=C3=84ndern=20und=20L=C3=B6schen?= =?utf8?q?=20fertig?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/FrBr/Books/Controller/Books.pm | 90 ++++++++++++++++++++++ lib/FrBr/Books/Util/Book.pm | 45 +++++++++++ root/lib/site/styles.css | 4 + root/src/books/delete.tt2 | 117 +++++++++++++++++++++++++++++ root/src/books/delete_success.tt2 | 58 ++++++++++++++ root/src/books/form.tt2 | 4 +- root/src/books/styles.css | 12 +++ root/src/books/view.tt2 | 8 +- 8 files changed, 332 insertions(+), 6 deletions(-) create mode 100644 root/src/books/delete.tt2 create mode 100644 root/src/books/delete_success.tt2 diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index 464d956..50eee4c 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -250,6 +250,71 @@ sub form_view : Path('view') { #------------------------------------------------------- +=head2 delete_buch( ) + +Löscht ein vorhandenes Buch. + +=cut + +sub delete_buch : Path('delete') { + + 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'}; + $self->add_booklist_menu($c) if $c->session->{'from_book_list'}; + push @{ $c->stash->{'menu_path'} }, { + 'path' => $c->web_path("/books/delete"), + 'name' => "Löschen" + }; + + $c->stash->{'error_message'} = ''; + + my $buch_id = to_int( $c->request->params->{'delete_book_id'} || $c->session->{'delete_book_id'} || 0 ); + unless ( $buch_id ) { + $c->stash->{'template'} = 'error.tt2'; + $c->stash->{'error'} = 'Keine oder ungültige Buch-Id übergeben.'; + return 1; + } + $c->session->{'delete_book_id'} = $buch_id; + + my $buchliste = get_booklist( $c, 'buch_id' => $buch_id ); + $c->log->debug( get_output_string( $K, "Erhaltene Buchliste: ", $buchliste ) ) if $c->stash->{'debug_level'} >= 2; + + unless ( $buchliste and scalar( @$buchliste ) ) { + $c->stash->{'template'} = 'error.tt2'; + $c->stash->{'error'} = 'Zur übergebenen Buch-Id wurde kein Buch gefunden.'; + return 1; + } + + $c->stash->{'return_target'} = $c->session->{'return_target_del'} or $c->web_path("/books/list"); + + $c->stash->{'book'} = $buchliste->[0]; + $buchliste = undef; + + $c->stash->{'template'} = 'books/delete.tt2'; + push @{$c->stash->{'cssfiles'}}, 'books/view.css'; + + if ( $c->request->params->{'really_delete_book'} and $c->request->params->{'really_delete_book'} eq 'yes' and $c->request->params->{'do_delete'} ) { + eval { + delete_book( $c, $buch_id ); + }; + if ( $@ ) { + $c->stash->{'error_message'} = $@; + $c->log->warn( "Fehler beim Löschen des Buches: " . $@ ); + return undef; + } + $c->stash->{'template'} = 'books/delete_success.tt2'; + delete $c->session->{'delete_book_id'} if exists $c->session->{'delete_book_id'}; + delete $c->session->{'book_data_edit'} if exists $c->session->{'book_data_edit'}; + } + +} + +#------------------------------------------------------- + =head2 form_edit( ) Aendern eines vorhandenen Buches. @@ -312,6 +377,7 @@ sub form_edit : Path('edit') { delete $buch->{'serien_ids'} if exists $buch->{'serien_ids'}; $buch->{'original_title'} = $buch->{'title_original'}; + $buch->{'book_nr'} = $buch->{'buch_nr'}; $c->log->debug( get_output_string( $K, "Buch nach Bereinigung: ", $buch ) ) if $c->stash->{'debug_level'} >= 2; @@ -450,6 +516,30 @@ sub check_formparams : Private { $book->{'seiten'} = $seiten; } + # Bindungsart-Id trimmen + if ( defined $book->{'bindungsart_id'} ) { + my ( $id ) = $book->{'bindungsart_id'} =~ /(\d+)/; + $book->{'bindungsart_id'} = $id; + } + + # Orts-Id trimmen + if ( defined $book->{'orts_id'} ) { + my ( $id ) = $book->{'orts_id'} =~ /(\d+)/; + $book->{'orts_id'} = $id; + } + + # Verlags-Id trimmen + if ( defined $book->{'verlags_id'} ) { + my ( $id ) = $book->{'verlags_id'} =~ /(\d+)/; + $book->{'verlags_id'} = $id; + } + + # Waehrungs-Id trimmen + if ( defined $book->{'waehrungs_id'} ) { + my ( $id ) = $book->{'waehrungs_id'} =~ /(\d+)/; + $book->{'waehrungs_id'} = $id; + } + # Preis trimmen if ( defined $book->{'preis'} ) { $book->{'preis'} =~ s/^\s+//; diff --git a/lib/FrBr/Books/Util/Book.pm b/lib/FrBr/Books/Util/Book.pm index ecabb90..13e250d 100644 --- a/lib/FrBr/Books/Util/Book.pm +++ b/lib/FrBr/Books/Util/Book.pm @@ -24,6 +24,7 @@ BEGIN { @EXPORT = qw( &get_booklist &save_book + &delete_book ); #%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], @@ -332,6 +333,50 @@ sub get_booklist { #----------------------------------------------------------------------------------- +=head2 delete_book( $c, $book_id ) + +Loescht das Buch mit der uebergebenen Buch-Id + +=cut + +sub delete_book { + + my $c = shift; + my $book_id = shift; + my $K = ( caller(0) )[3] . "(): "; + + $c->log->debug( $K . "aufgerufen fuer Buch-Id " . ( defined $book_id ? $book_id : '' ) . "." ) if $c->stash->{'debug_level'} > 2; + + return undef unless $book_id and to_int($book_id); + $book_id = to_int($book_id); + + my $schema = $c->model('Schema')->{'schema'}; + #$c->log->debug( get_output_string( $K . "Schema: ", $schema ) ) if $c->stash->{'debug_level'} > 4; + my $search_params = { + 'buch_id' => $book_id, + }; + + my $coderef = sub { + $c->model('Schema::Autor2buch')->search( $search_params )->delete(); + $c->model('Schema::Buch2kategorie')->search( $search_params )->delete(); + $c->model('Schema::Buch2serie')->search( $search_params )->delete(); + $c->model('Schema::Buecher')->search( { 'id' => $book_id } )->delete(); + }; + + my $rs; + eval { + $rs = $schema->txn_do($coderef); + }; + + if ($@) { # Transaction failed + die "Rollback nicht erfolgreich!" if ($@ =~ /Rollback failed/i ); # Rollback failed + die $@; + } + +} + +#----------------------------------------------------------------------------------- + =head2 save_book( $c, $book ) $book = { diff --git a/root/lib/site/styles.css b/root/lib/site/styles.css index 4773c67..8a74849 100644 --- a/root/lib/site/styles.css +++ b/root/lib/site/styles.css @@ -166,6 +166,10 @@ DIV#copyright { color: [% site.col.error %]; } +DIV.error { + white-space: pre; +} + TABLE.menu { font-size: 14pt; margin-left: auto; diff --git a/root/src/books/delete.tt2 b/root/src/books/delete.tt2 new file mode 100644 index 0000000..a894b24 --- /dev/null +++ b/root/src/books/delete.tt2 @@ -0,0 +1,117 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Möchten Sie das Buch '[%- book.title | html -%]' wirklich löschen?
Autor (-en):[% IF book.autoren.size > 1 %]
    [% FOR autor IN book.autoren %]
  • [% autor %]
  • [% END %]
[% ELSE %][% book.autoren.0 %][% END %]
Buchtitel:[% book.title | html %]
Untertitel:[% book.untertitel | html %]
Original-Titel:[% book.title_original | html %]
Verlag:[% book.verlagsname_long | html %]
Aufbewahrungsort:[% book.ortsname | html %]
Bindungsart:[% book.bindungsart | html %]
Kategorie(n):[% IF book.kategorien.size > 1 %]
    [% FOR kat IN book.kategorien %]
  • [% kat %]
  • [% END %]
[% ELSE %][% book.kategorien.0 %][% END %]
Buchserien:[% IF book.serien.size > 1 %]
    [% FOR serie IN book.serien %]
  • [% serie %]
  • [% END %]
[% ELSE %][% book.serien.0 %][% END %]
ISBN:[% book.isbn | html %]
Buch-Nummer (verlagseigen):[% book.buch_nr | html %]
Ausgabejahr:[% book.ausgabejahr | html %]
Druckjahr:[% book.druckjahr | html %]
Seiten:[% book.seiten | html %]
Preis:[% book.preis | format('%.2f') | replace('\.', ',') %] [% book.waehrungs_kuerzel | html %]
+ +[%- IF error_message %] +
+Fehler: [% error_message %] +
+[% END -%] + + + diff --git a/root/src/books/delete_success.tt2 b/root/src/books/delete_success.tt2 new file mode 100644 index 0000000..8c79a6e --- /dev/null +++ b/root/src/books/delete_success.tt2 @@ -0,0 +1,58 @@ + + +
+ +Das Buch "[% book.title | html %]" +von [% tt_authors = [ ]; tt_authors.push(autor) FOREACH autor = book.autoren %][% tt_authors.join(', ') | html %] wurde erfolgreich gelöscht. + +
+ + + diff --git a/root/src/books/form.tt2 b/root/src/books/form.tt2 index 45440fc..0a2bfc1 100644 --- a/root/src/books/form.tt2 +++ b/root/src/books/form.tt2 @@ -46,7 +46,7 @@ function goto_new_ort() { [% book_form_title %] -   + Autor (-en): @@ -165,7 +165,7 @@ function goto_new_ort() { [% END %]   -   + diff --git a/root/src/books/styles.css b/root/src/books/styles.css index d012b32..41f400f 100644 --- a/root/src/books/styles.css +++ b/root/src/books/styles.css @@ -75,6 +75,10 @@ TABLE.ftable TD { background-color: [% site.col.list_row_bold %]; } +TABLE.ftable TD.empty { + height: 0.5em; +} + TABLE.ftable TH.button { font-weight: bolder; text-align: center; @@ -83,6 +87,14 @@ TABLE.ftable TH.button { padding-right: 1em; } +TABLE.ftable TH.button INPUT { + font-weight: bolder; + text-align: center; + font-size: 1em; + padding-left: 1em; + padding-right: 1em; +} + TABLE.buchliste { text-align: left; border-width: 2px; diff --git a/root/src/books/view.tt2 b/root/src/books/view.tt2 index 9d90eee..04e37fc 100644 --- a/root/src/books/view.tt2 +++ b/root/src/books/view.tt2 @@ -1,4 +1,4 @@ -[%# + +Buchanzeige --> - + @@ -82,7 +82,7 @@ - + -- 2.39.5
Buchangaben '[%- book.title | html -%]'
 
Autor (-en): [% IF book.autoren.size > 1 %]
    [% FOR autor IN book.autoren %]
  • [% autor %]
  • [% END %]
[% ELSE %][% book.autoren.0 %][% END %]
[% book.isbn | html %]
Buch-Nummer (verlagseigen):[% book.book_nr | html %][% book.buch_nr | html %]
Ausgabejahr: [% book.ausgabejahr | html %]