]> Frank Brehm's Git Trees - books.git/commitdiff
Neuen Aufbewahrungsort gespeichert
authorFrank Brehm <frank@brehm-online.com>
Tue, 11 Nov 2008 14:58:53 +0000 (14:58 +0000)
committerFrank Brehm <frank@brehm-online.com>
Tue, 11 Nov 2008 14:58:53 +0000 (14:58 +0000)
lib/FrBr/Books/Controller/Ort.pm [new file with mode: 0644]
lib/FrBr/Books/Controller/Serie.pm
lib/FrBr/Books/Util/Ort.pm
root/src/books/book_form.tt2
root/src/index.tt2
root/src/ort/form.css [new file with mode: 0644]
root/src/ort/form.tt2 [new file with mode: 0644]
root/src/ort/index.tt2 [new file with mode: 0644]
root/src/ort/new.tt2 [new file with mode: 0644]
root/src/ort/save_success.tt2 [new file with mode: 0644]
root/src/ort/styles.css [new file with mode: 0644]

diff --git a/lib/FrBr/Books/Controller/Ort.pm b/lib/FrBr/Books/Controller/Ort.pm
new file mode 100644 (file)
index 0000000..e77245d
--- /dev/null
@@ -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 : 
index 0acdfd941d50ed040cdec7cb15d1bcb1270ba841..4d2859e3786e49855412bed1788c643d3ccc5da3 100644 (file)
@@ -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;
 
index 502e37173900865450e1db44526dd6c7f789945b..3cbb9ccc21b3c829a859574fa73360756cbb8792 100644 (file)
@@ -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 = <<ENDE;
+INSERT INTO `orte` (
+    `id`, `name`, `descr`, `statisch` )
+  VALUES (
+    ?, ?, ?, ? )
+  ON DUPLICATE KEY UPDATE
+    `id` = LAST_INSERT_ID(`id`), `name` = ?, `descr` = ?, `statisch` = ?
+ENDE
+
+        if ( $storage->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
index 1d6e0dcf712aae6f71178e36c3c40a00019ebab4..20192963c0c7c32b44eb9f89ed38e90d269c7f7f 100644 (file)
@@ -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;
+}
+
 //]]></script>
 
 <form method="post" name="book_form" action="[% self_url %]">
index acee9fd5046cf07368282576967ce51cdc169959..9bb2cb33ee8c04a0a97f3f35314001c85aa3b101 100644 (file)
       &nbsp;</td>
     <td class="item">
       <a href="[% path('/serie') %]">Buchserien</a></td>
+  </tr><tr>
+    <td colspan="2" class="empty">
+      &nbsp;</td>
+  </tr><tr>
+    <td class="button">
+      &nbsp;</td>
+    <td class="item">
+      <a href="[% path('/ort') %]">Aufbewahrungsorte</a></td>
   </tr>
 </table>
 </div>
diff --git a/root/src/ort/form.css b/root/src/ort/form.css
new file mode 100644 (file)
index 0000000..db1f3c0
--- /dev/null
@@ -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 (file)
index 0000000..6cd7384
--- /dev/null
@@ -0,0 +1,42 @@
+[%#
+
+    Template für Formular Aufbewahrungsorte
+
+    vim: noai : ts=4 fenc=utf-8 filetype=html expandtab :
+
+    $Id$
+    $URL$
+
+-%]
+
+<!-- Aufbewahrungsort-Formular -->
+
+<form method="post" name="ort_form" action="[% self_url %]">
+<input type="hidden" name="ort_form_sent" value="sent" />
+<input type="hidden" name="ort_statisch" value="[% IF ort_edit.statisch %][% ort_edit.statisch | html %][% ELSE %]n[% END %]" />
+[%- IF ort_edit.id %]<input type="hidden" name="orts_id" value="[% ort_edit.id | html %]" />[% END %]
+  <table class="ftable" cellspacing="0">
+    <tr>
+      <th colspan="2" class="title">[% ort_form_title %]</th>
+    </tr><tr>
+      <td colspan="2">&nbsp;</td>
+    </tr><tr>
+      <th>Bezeichnung des Aufbewahrungsortes:</th>
+      <td><input type="text" name="orts_name" size="50" maxlength="100" value="[% ort_edit.name | html %]" /></td>
+    </tr><tr>
+      <td colspan="2">&nbsp;</td>
+    </tr><tr>
+      <th>Beschreibung:</th>
+      <td><textarea name="orts_descr" cols="50" rows="10">[% ort_edit.descr | html %]</textarea></td>
+    </tr><tr>
+      <td colspan="2">&nbsp;</td>
+    </tr><tr>
+      <th colspan="2" class="button"><input type="submit" name="do_save" value="  OK  " /></th>
+    </tr>
+  </table>
+</form>
+[%- IF error_message %]
+<div class="error">
+<span class="bold">Fehler:</span>&nbsp;[% error_message %]
+</div>
+[% END -%]
diff --git a/root/src/ort/index.tt2 b/root/src/ort/index.tt2
new file mode 100644 (file)
index 0000000..8be4883
--- /dev/null
@@ -0,0 +1,47 @@
+[%#
+
+    index.tt2 - Index-Template (Menue) fuer Aufbewahrungsorte
+
+    vim: noai : ts=4 fenc=utf-8 filetype=html expandtab :
+
+    $Id$
+    $URL$
+
+-%]
+<div style="text-align: center">
+<table class="menu" cellspacing="0">
+  <tr>
+    <th colspan="2">Menü</th>
+  </tr>
+  <tr>
+    <td colspan="2" class="empty">
+      &nbsp;</td>
+  </tr>
+  <tr>
+    <td class="button">
+      &nbsp;</td>
+    <td class="item">
+      <a href="[% path('/ort/list') %]">Liste der Aufbewahrungsorte</a></td>
+  </tr>
+  <tr>
+    <td colspan="2" class="empty">
+      &nbsp;</td>
+  </tr>
+  <tr>
+    <td class="button">
+      &nbsp;</td>
+    <td class="item">
+      <a href="[% path('/ort/new') %]">Neuer Aufbewahrungsort</a></td>
+  </tr>
+  <tr>
+    <td colspan="2" class="empty">
+      &nbsp;</td>
+  </tr>
+  <tr>
+    <td class="button">
+      &nbsp;</td>
+    <td class="item">
+      <a href="[% path('/') %]">Zurück zum Hauptmenü</a></td>
+  </tr>
+</table>
+</div>
diff --git a/root/src/ort/new.tt2 b/root/src/ort/new.tt2
new file mode 100644 (file)
index 0000000..be9f240
--- /dev/null
@@ -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 %]
+
+<div class="back">
+<h2><a href="[% return_target_ort_save %]">[% 'Zurück' %]</a></h2>
+</div>
diff --git a/root/src/ort/save_success.tt2 b/root/src/ort/save_success.tt2
new file mode 100644 (file)
index 0000000..ce40e1b
--- /dev/null
@@ -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$
+
+-%]
+<div style="text-align: center">
+
+Der Aufbewahrungsort <b>&quot;[% ort_edit.name %]</b> wurde erfolgreich gespeichert.
+
+<h2><a href="[% return_target_ort_save %]">OK</a></h2>
+
+</div>
diff --git a/root/src/ort/styles.css b/root/src/ort/styles.css
new file mode 100644 (file)
index 0000000..e2133b4
--- /dev/null
@@ -0,0 +1,10 @@
+/* [%#
+   # Template fuer Stylesheets Buchserien
+   #
+   # $Id$
+   # $URL$
+   #
+-%]
+ Stylesheets Buchserien */
+
+