-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dvd.pm
56 lines (47 loc) · 1.55 KB
/
Dvd.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use strict;
use warnings;
package DvdDatabase::Controller::Dvd;
use base 'WebNano::Controller';
use DvdDatabase::Controller::Dvd::Form;
use DvdDatabase::Controller::Dvd::Record;
sub index_action {
my( $self ) = @_;
my $rs = $self->application->schema->resultset( 'Dvd' );
return $self->render( 'list.tt', { items => [ $rs->search ] } );
}
sub create_action {
my ( $self ) = @_;
my $req = $self->request;
my $form = DvdDatabase::Controller::Dvd::Form->new(
params => $req->parameters->as_hashref,
schema => $self->application->schema,
);
if( $req->method eq 'POST' && $form->process() ){
my $record = $form->item;
my $res = $req->new_response();
$res->redirect( $self->self_url . 'record/' . $record->id . '/view' );
return $res;
}
$form->field( 'submit' )->value( 'Create' );
return $self->render( 'edit.tt', { form => $form->render } );
}
sub record_action {
my( $self, $id, $action ) = @_;
my $rs = $self->application->schema->resultset( 'Dvd' );
my $record = $rs->find( $id );
if( ! $record ) {
my $res = $self->request->new_response(404);
$res->content_type('text/plain');
$res->body( 'No record with id: ' . $id );
return $res;
}
return DvdDatabase::Controller::Dvd::Record->handle(
path => $action,
application => $self->application,
env => $self->env,
self_url => $self->self_url . "record/$id/",
self_path => $self->self_path . '/Record',
record => $record,
);
}
1;