Skip to content

Commit

Permalink
TODOs em Deals e novos templates do FormFu para adequação com Twitter…
Browse files Browse the repository at this point in the history
… Bootstrap
  • Loading branch information
gilmagno committed Aug 1, 2012
1 parent 57fb8a1 commit ce3e3fc
Show file tree
Hide file tree
Showing 42 changed files with 680 additions and 60 deletions.
18 changes: 9 additions & 9 deletions lib/DealsManager/Controller/Deals/Notes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ BEGIN { extends 'Catalyst::Controller::HTML::FormFu'; }
sub base :Chained('/deals/object') :PathPart('notes') :CaptureArgs(0) {
my ( $self, $c ) = @_;

$c->stash->{object_note} = $c->model('DB::Note');
$c->stash->{notes_rs} = $c->model('DB::Note');
}

sub object :Chained('/deals/object') :PathPart('notes') :CaptureArgs(1) {
my ( $self, $c, $id ) = @_;

$c->stash->{object_note} = $c->model('DB::Note')->search_rs({ 'me.id' => $id });
$c->stash->{notes_rs} = $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];
$c->stash->{notes} = [$c->stash->{deals_rs}->first->notes];
}

sub create :Chained('base') :PathPart('create') :Args(0) :FormConfig('deals/notes/form.yml') {
Expand All @@ -30,9 +30,9 @@ sub create :Chained('base') :PathPart('create') :Args(0) :FormConfig('deals/note
use DateTime;

my $datetime_now = DateTime->now;
my $new_note = $c->stash->{object_note}->new_result({
created => $datetime_now
});
my $new_note = $c->stash->{notes_rs}->new_result({
created => $datetime_now
});

$form->model->update( $new_note );

Expand All @@ -44,14 +44,14 @@ sub create :Chained('base') :PathPart('create') :Args(0) :FormConfig('deals/note

my $dashboard_rs = $c->model('DB::Dashboard')->create( $dashboard_item );

$c->res->redirect( $c->uri_for('/deals', $c->stash->{object}->first->id) );
$c->res->redirect( $c->uri_for('/deals', $c->stash->{deals_rs}->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) );
$c->stash->{notes_rs}->first->delete;
$c->res->redirect( $c->uri_for('/deals', $c->stash->{deals_rs}->first->id) );
}

__PACKAGE__->meta->make_immutable;
Expand Down
95 changes: 95 additions & 0 deletions lib/DealsManager/Controller/Deals/TODOs.pm
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;
59 changes: 59 additions & 0 deletions lib/DealsManager/Controller/Deals/TODOs/Comments.pm
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;
18 changes: 10 additions & 8 deletions lib/DealsManager/Schema/Result/Contact.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ __PACKAGE__->table("contacts");
data_type: 'text'
is_nullable: 1
original: {data_type => "varchar"}
=head2 email
Expand All @@ -64,6 +63,11 @@ __PACKAGE__->table("contacts");
data_type: 'timestamp with time zone'
is_nullable: 1
=head2 updated
data_type: 'timestamp with time zone'
is_nullable: 1
=cut

__PACKAGE__->add_columns(
Expand All @@ -87,11 +91,7 @@ __PACKAGE__->add_columns(
original => { data_type => "varchar" },
},
"address",
{
data_type => "text",
is_nullable => 1,
original => { data_type => "varchar" },
},
{ data_type => "text", is_nullable => 1 },
"email",
{
data_type => "text",
Expand All @@ -102,6 +102,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"created",
{ data_type => "timestamp with time zone", is_nullable => 1 },
"updated",
{ data_type => "timestamp with time zone", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");

Expand All @@ -123,8 +125,8 @@ __PACKAGE__->has_many(
);


# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-07-03 18:36:09
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dAmGz1m5UVH4oMbErSf2Gw
# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-07-31 17:42:01
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HtMRqHYT6sIcjm9uJyxfig


# You can replace this text with custom code or comments, and it will be preserved on regeneration
Expand Down
19 changes: 17 additions & 2 deletions lib/DealsManager/Schema/Result/Deal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,24 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 todos
# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-07-16 19:29:22
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:s+rSd2i0W6ol4rLqf6hn5A
Type: has_many
Related object: L<DealsManager::Schema::Result::Todo>
=cut

__PACKAGE__->has_many(
"todos",
"DealsManager::Schema::Result::Todo",
{ "foreign.deal_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);


# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-07-31 17:42:01
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uCdksqXsyLxsQw1ZnCUgQA


# You can replace this text with custom code or comments, and it will be preserved on regeneration
Expand Down
Loading

0 comments on commit ce3e3fc

Please sign in to comment.