aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/Controller/Collection/CRUD.pm
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-12-31 01:24:34 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-12-31 01:24:34 +0000
commit893bf4f1e774c47122cbc222d35ce1667d35d49f (patch)
tree923259b3bd55e32337e32405e4161cbabaa06538 /lib/Reaction/UI/Controller/Collection/CRUD.pm
parent32a4b1a431ecd8e488062fc73af8ff532a1d1a74 (diff)
downloadreaction-893bf4f1e774c47122cbc222d35ce1667d35d49f.tar.gz
reaction-893bf4f1e774c47122cbc222d35ce1667d35d49f.zip
allow list, create, and delete_all to act on a user-provided collection stored in the stash, similar to how object works. additionally, change how basic_model_action picks a default target if none is given. the exists() check for stash->{object} is just asking for autovivification-related bugs and the new behavior should be 100% compatible with the added benefit of DTRT if a collection is placed in {collection}. This whole system really needs an overhaul at some point, but I am waiting for catamoose to support roles in controllers so we can do it right.
Diffstat (limited to 'lib/Reaction/UI/Controller/Collection/CRUD.pm')
-rw-r--r--lib/Reaction/UI/Controller/Collection/CRUD.pm8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/Reaction/UI/Controller/Collection/CRUD.pm b/lib/Reaction/UI/Controller/Collection/CRUD.pm
index 352b142..cf2e3ad 100644
--- a/lib/Reaction/UI/Controller/Collection/CRUD.pm
+++ b/lib/Reaction/UI/Controller/Collection/CRUD.pm
@@ -39,6 +39,7 @@ sub create :Chained('base') :PathPart('create') :Args(0) {
my $apply = sub { $self->after_create_callback( @_) };
my $close = sub { $self->on_create_close_callback( @_) };
my $vp_args = {
+ target => ($c->stash->{collection} || $self->get_collection($c)),
on_apply_callback => $self->make_context_closure($apply),
on_close_callback => $self->make_context_closure($close),
};
@@ -49,6 +50,7 @@ sub delete_all :Chained('base') :PathPart('delete_all') :Args(0) {
my ($self, $c) = @_;
my $close = sub { $self->on_delete_all_close_callback( @_) };
$self->basic_model_action( $c, {
+ target => ($c->stash->{collection} || $self->get_collection($c)),
on_close_callback => $self->make_context_closure($close),
});
}
@@ -97,9 +99,9 @@ sub delete :Chained('object') :Args(0) {
sub basic_model_action {
my ($self, $c, $vp_args) = @_;
-
- my $target = exists $c->stash->{object} ?
- $c->stash->{object} : $self->get_collection($c);
+ my $stash = $c->stash;
+ my $target = delete $vp_args->{target};
+ $target ||= ($stash->{object} || $stash->{collection} || $self->get_collection($c));
my $action_name = join('', map{ ucfirst } split('_', $c->stack->[-1]->name));
my $model = $self->get_model_action($c, $action_name, $target);