]> Frank Brehm's Git Trees - books.git/commitdiff
Mit Autorenformular angefangen
authorFrank Brehm <frank@brehm-online.com>
Thu, 27 Mar 2008 18:19:35 +0000 (18:19 +0000)
committerFrank Brehm <frank@brehm-online.com>
Thu, 27 Mar 2008 18:19:35 +0000 (18:19 +0000)
lib/FrBr/Books.pm
lib/FrBr/Books/Controller/Autor.pm [new file with mode: 0644]
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Util/Author.pm
root/src/autor/autor_form.tt2 [new file with mode: 0644]
root/src/autor/form.css [new file with mode: 0644]
root/src/autor/index.tt2 [new file with mode: 0644]
root/src/autor/new.tt2 [new file with mode: 0644]
root/src/autor/styles.css [new file with mode: 0644]
t/controller_Autor.t [new file with mode: 0644]

index 01f3184729e30b541a26ff53051d0f672daf0f8d..4192593bc726e8b66ec3a4ffce006635a08eb7a6 100644 (file)
@@ -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 (file)
index 0000000..947432c
--- /dev/null
@@ -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;
index 346973548f7f068b668210ae600bbf66c270c9bd..7c01385c5d258d2652e446d1b6f33704608fa11c 100644 (file)
@@ -54,7 +54,6 @@ sub auto : Private {
 
 #-------------------------------------------------------
 
-
 =head2 index 
 
 =cut
index 6f61291fb089c699091102f2cb6ac7c7096e13cb..d9624bcbfed8d829c143a05460056cca54fbe529 100644 (file)
@@ -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 = <<ENDE;
+INSERT INTO `autoren` (
+    `id`, `autor_name`, `autor_descr` )
+  VALUES (
+    ?, ?, ? )
+  ON DUPLICATE KEY UPDATE
+    `autor_name` = ?, `autor_descr` = ?
+ENDE
+
+        if ( $storage->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 (file)
index 0000000..709c233
--- /dev/null
@@ -0,0 +1,36 @@
+[%#
+     Template fuer Autorenangaben
+
+     $Id$
+     $URL$
+
+-%]
+
+<!-- Autoren-Formular -->
+
+<form method="post" name="autor_form" action="[% self_url %]">
+<input type="hidden" name="autor_form_sent" value="sent" />
+[%- IF autor_edit.id %]<input type="hidden" name="autor_id" value="[% autor_edit.id | html %]" />[% END %]
+  <table class="ftable" cellspacing="0">
+    <tr>
+      <th colspan="2" class="title">[% autor_form_title %]</th>
+    </tr><tr>
+      <td colspan="2">&nbsp;</td>
+    </tr><tr>
+      <th>Name des Autors:</th>
+      <td><input type="text" name="autor_name" size="50" maxlength="250" value="[% autor_edit.name | html %]" /></td>
+    </tr><tr>
+      <th>Zusätzliche Angaben:</th>
+      <td><textarea name="autor_desc" cols="50" rows="5">[% autor_edit.desc | 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/autor/form.css b/root/src/autor/form.css
new file mode 100644 (file)
index 0000000..79ffe51
--- /dev/null
@@ -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 (file)
index 0000000..31d1330
--- /dev/null
@@ -0,0 +1,45 @@
+[%#
+
+    index.tt2 - Index-Template (Menue) fuer Autoren-Dinge
+
+   #$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('/autor/list') %]">Liste der Buchautoren</a></td>
+  </tr>
+  <tr>
+    <td colspan="2" class="empty">
+      &nbsp;</td>
+  </tr>
+  <tr>
+    <td class="button">
+      &nbsp;</td>
+    <td class="item">
+      <a href="[% path('/autor/new') %]">Neuer Autor</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/autor/new.tt2 b/root/src/autor/new.tt2
new file mode 100644 (file)
index 0000000..bb27468
--- /dev/null
@@ -0,0 +1,13 @@
+[%#
+     Template fuer neuen Autor
+
+     $Id$
+     $URL$
+
+-%]
+[%- autor_form_title = 'Neuer Autor' -%]
+[% PROCESS autor/autor_form.tt2 %]
+
+<div class="back">
+<h2><a href="[% path('/autor') %]">[% 'Zurück' %]</a></h2>
+</div>
diff --git a/root/src/autor/styles.css b/root/src/autor/styles.css
new file mode 100644 (file)
index 0000000..98edb6e
--- /dev/null
@@ -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 (file)
index 0000000..1224a59
--- /dev/null
@@ -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' );
+
+