-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODOs em Deals e novos templates do FormFu para adequação com Twitter…
… Bootstrap
- Loading branch information
Showing
42 changed files
with
680 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package DealsManager::Controller::Deals::TODOs; | ||
use Moose; | ||
use namespace::autoclean; | ||
use Data::Dumper; | ||
BEGIN { extends 'Catalyst::Controller::HTML::FormFu'; } | ||
|
||
sub base :Chained('/deals/object') PathPart('todos') CaptureArgs(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{deal} = $c->stash->{deals_rs}->first; | ||
|
||
$c->stash->{todos_rs} = $c->model('DB::Todo'); | ||
} | ||
|
||
sub object :Chained('base') PathPart('') CaptureArgs(1) { | ||
my ( $self, $c, $todo_id ) = @_; | ||
|
||
$c->stash->{todos_rs} = $c->stash->{todos_rs}->search_rs({ id => $todo_id, | ||
deal_id => $c->stash->{deal}->id }); | ||
} | ||
|
||
sub index :Chained('base') PathPart('') Args(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{todos} = [ $c->stash->{todos_rs}->search_rs({ deal_id => $c->stash->{deal}->id })->all ]; | ||
} | ||
|
||
sub create :Chained('base') PathPart('create') Args(0) FormConfig('deals/todos/form.yml') { | ||
my ( $self, $c ) = @_; | ||
|
||
my $form = $c->stash->{form}; | ||
|
||
if ($form->submitted_and_valid) { | ||
$self->_save( $c, $form ); | ||
} | ||
} | ||
|
||
sub edit :Chained('object') PathPart('edit') Args(0) FormConfig('deals/todos/form.yml') { | ||
my ( $self, $c ) = @_; | ||
|
||
my $form = $c->stash->{form}; | ||
$form->model->default_values( $c->stash->{todos_rs}->first ); | ||
|
||
if ($form->submitted_and_valid) { | ||
$self->_save( $c, $form, $c->stash->{todos_rs}->first ); | ||
} | ||
} | ||
|
||
sub _save :Private { | ||
my ( $self, $c, $form, $todo ) = @_; | ||
|
||
if ($todo) { # edit | ||
$form->model->update( $todo ); | ||
|
||
$c->flash->{success} = 'TODO <b>' . $todo->title . '</b> edited.'; | ||
} | ||
else { # create | ||
my $new_todo = $c->stash->{todos_rs}->new_result({ deal_id => $c->stash->{deal}->id }); | ||
$form->model->update( $new_todo ); | ||
|
||
$c->flash->{success} = 'TODO <b>' . $new_todo->title . '</b> created.'; | ||
} | ||
$c->res->redirect( $c->uri_for('/deals', $c->stash->{deal}->id, 'todos') ); | ||
} | ||
|
||
sub show :Chained('object') PathPart('') Args(0) FormConfig('deals/todos/comments/form.yml') { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{todo} = $c->stash->{todos_rs}->first; | ||
$c->stash->{form}->action("/deals/" . $c->stash->{deal}->id . "/todos/" . | ||
$c->stash->{todo}->id . "/comments/create"); | ||
$c->stash->{form}->default_values({ deal_id => $c->stash->{deal}->id, | ||
todo_id => $c->stash->{todo}->id }); | ||
} | ||
|
||
sub delete :Chained('object') PathPart('delete') Args(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
my $todo = $c->stash->{todos_rs}->first; | ||
$c->flash->{success} = 'TODO <b>' . $todo->title . '</b> deleted.'; | ||
$todo->delete; | ||
|
||
$c->res->redirect( $c->uri_for('/deals', $c->stash->{deal}->id, 'todos') ); | ||
} | ||
|
||
=head1 LICENSE | ||
This library is free software. You can redistribute it and/or modify | ||
it under the same terms as Perl itself. | ||
=cut | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package DealsManager::Controller::Deals::TODOs::Comments; | ||
use Moose; | ||
use namespace::autoclean; | ||
|
||
BEGIN { extends 'Catalyst::Controller::HTML::FormFu'; } | ||
|
||
sub base :Chained('/deals/todos/object') :PathPart('comments') :CaptureArgs(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{object_note} = $c->model('DB::Note'); | ||
} | ||
|
||
sub object :Chained('base') :PathPart('') :CaptureArgs(1) { | ||
my ( $self, $c, $id ) = @_; | ||
|
||
$c->stash->{object_note} = $c->model('DB::Note')->search_rs({ 'me.id' => $id }); | ||
} | ||
|
||
sub index :Chained('base') :PathPart('') :Args(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{notes} = [$c->stash->{object}->first->notes]; | ||
} | ||
|
||
sub create :Chained('base') :PathPart('create') :Args(0) :FormConfig('deals/notes/form.yml') { | ||
my ( $self, $c ) = @_; | ||
|
||
my $form = $c->stash->{form}; | ||
|
||
use DateTime; | ||
|
||
my $datetime_now = DateTime->now; | ||
my $new_note = $c->stash->{object_note}->new_result({ | ||
created => $datetime_now | ||
}); | ||
|
||
$form->model->update( $new_note ); | ||
|
||
my $dashboard_item = { content => $new_note->note, | ||
type => 'note_created', | ||
created => $datetime_now, | ||
user_id => $c->user->id, | ||
deal_id => $new_note->deal->id }; | ||
|
||
my $dashboard_rs = $c->model('DB::Dashboard')->create( $dashboard_item ); | ||
|
||
$c->res->redirect( $c->uri_for('/deals', $c->stash->{object}->first->id) ); | ||
} | ||
|
||
sub delete :Chained('object') PathPart('delete') Args(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{object_note}->delete; | ||
$c->res->redirect( $c->uri_for('/deals', $c->stash->{object}->first->id) ); | ||
} | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.