root/lang/perl/Chaostr/trunk/lib/Chaostr/Web/Controller/Texts.pm

Revision 31513, 2.1 kB (checked in by vkgtaro, 3 months ago)

removed attribute. added config.

Line 
1package Chaostr::Web::Controller::Texts;
2
3use strict;
4use warnings;
5use base 'Chaostr::Base::Controller::Resources';
6
7=head1 NAME
8
9Chaostr::Web::Controller::Texts - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19sub list {
20    my ( $self, $c, $text_id ) = @_;
21
22    $c->stash->{texts} = $c->model('DBIC::Texts')->search();
23}
24
25sub create {
26    my ( $self, $c ) = @_;
27}
28
29sub do_create {
30    my ( $self, $c ) = @_;
31
32    $c->form({
33        required => [qw/text/],
34        optional => [qw/title/],
35    })->valid;
36
37    if ( $c->form->has_error ) {
38        $c->stash->{template} = 'texts/create.tt';
39        $c->forward('TT');
40        $c->fillform;
41        return;
42    }
43    my $results = $c->form;
44    $c->log->debug($results->valid->{text});
45
46    my $timeline = $c->model('DBIC::Timeline')->create( { type => 'texts', created_by => $c->user->id } );
47    my $text = $timeline->create_from_fv($c->form);
48
49    $c->res->redirect( $c->uri_for('/texts', $text->id) );
50}
51
52sub member {
53    my ( $self, $c, $text_id ) = @_;
54
55    $c->stash->{text} = $c->model('DBIC::Text')->find($text_id);
56}
57
58sub show {
59    my ( $self, $c, $text_id ) = @_;
60}
61
62sub update {
63    my ( $self, $c, $text_id ) = @_;
64
65    $c->forward('TT');
66    $c->fillform($c->stash->{text}->as_fdat);
67}
68
69sub do_update {
70    my ( $self, $c, $text_id ) = @_;
71
72    my $results = $c->form({
73        required => [qw/text/],
74        optional => [qw/title/],
75    });
76
77    if ( $c->form->has_error ) {
78        $c->stash->{template} = 'texts/update.tt';
79        $c->forward('TT');
80        $c->fillform;
81        return;
82    }
83
84    $c->stash->{text}->update_from_fv($results);
85
86    $c->res->redirect( $c->uri_for('/texts', $c->stash->{text}->id) );
87}
88
89sub destroy {
90    my ( $self, $c, $text_id ) = @_;
91}
92
93sub do_destroy {
94    my ( $self, $c, $text_id ) = @_;
95
96    $c->stash->{text}->timeline->delete;
97
98    $c->res->redirect( $c->uri_for('/texts') );
99}
100
101=head1 AUTHOR
102
103Daisuke Komatsu C<< <taro __at__ cpan.org> >>
104
105=head1 LICENSE
106
107This library is free software, you can redistribute it and/or modify
108it under the same terms as Perl itself.
109
110=cut
111
1121;
Note: See TracBrowser for help on using the browser.