aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/Controller/Collection/CRUD.pm
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-10-11 21:15:47 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-10-11 21:15:47 +0000
commit37728bbad6840485e4d0e3a504dfdc851e7378c3 (patch)
tree0b971b7451c5fff6e554090f22ff881005729d5f /lib/Reaction/UI/Controller/Collection/CRUD.pm
parent487c32080762a25ad34c785dc39753cbc941d355 (diff)
downloadreaction-37728bbad6840485e4d0e3a504dfdc851e7378c3.tar.gz
reaction-37728bbad6840485e4d0e3a504dfdc851e7378c3.zip
completely new way of handling action prototypes for actions in CRUD that is much saner and less reliant on $ctx. also more flexible and configurable
Diffstat (limited to 'lib/Reaction/UI/Controller/Collection/CRUD.pm')
-rw-r--r--lib/Reaction/UI/Controller/Collection/CRUD.pm53
1 files changed, 18 insertions, 35 deletions
diff --git a/lib/Reaction/UI/Controller/Collection/CRUD.pm b/lib/Reaction/UI/Controller/Collection/CRUD.pm
index 285947b..7552077 100644
--- a/lib/Reaction/UI/Controller/Collection/CRUD.pm
+++ b/lib/Reaction/UI/Controller/Collection/CRUD.pm
@@ -9,47 +9,30 @@ use aliased 'Reaction::UI::ViewPort::Action';
use aliased 'Reaction::UI::ViewPort::ListView';
sub _build_action_viewport_map {
- my $map = shift->next::method(@_);
- $map->{list} = ListView;
- $map->{$_} = Action for qw/create update delete delete_all/;
+ my $self = shift;
+ my $map = $self->next::method(@_);
+ $map->{list} = ListView if exists $map->{list};
+
+ my %allowed = map { $_ => undef }
+ ( @{$self->default_member_actions}, @{$self->default_collection_actions} );
+
+ my @local_actions = qw/create update delete delete_all/;
+ $map->{$_} = Action for grep { exists $allowed{$_} } @local_actions;
+
return $map;
}
-sub _build_action_viewport_args {
- my $args = shift->next::method(@_);
- $args->{list} =
- { action_prototypes =>
- [ { label => 'Create', action => sub {
- [ '', 'create', $_[1]->req->captures ] } },
- { label => 'Delete all', action => sub {
- [ '', 'delete_all', $_[1]->req->captures ] } },
- ],
- Member =>
- { action_prototypes =>
- [ { label => 'View', action => sub {
- [ '', 'view', [ @{$_[1]->req->captures}, $_[0]->__id ] ] } },
- { label => 'Edit', action => sub {
- [ '', 'update', [ @{$_[1]->req->captures}, $_[0]->__id ] ] } },
- { label => 'Delete', action => sub {
- [ '', 'delete', [ @{$_[1]->req->captures}, $_[0]->__id ] ] } },
- ],
- },
- };
- return $args;
+sub _build_default_member_actions {
+ [ @{shift->next::method(@_)}, qw/update delete/ ];
+}
+
+sub _build_default_collection_actions {
+ [ @{shift->next::method(@_)}, qw/create delete_all/ ];
}
sub get_model_action {
my ($self, $c, $name, $target) = @_;
-
- if ($target->can('action_for')) {
- return $target->action_for($name, ctx => $c);
- }
-
- #can we please kill this already?
- my $model_name = "Action::${name}".$self->model_name;
- my $model = $c->model($model_name);
- confess "no such Model $model_name" unless $model;
- return $model->new(target_model => $target, ctx => $c);
+ return $target->action_for($name, ctx => $c);
}
sub create :Chained('base') :PathPart('create') :Args(0) {
@@ -63,7 +46,7 @@ sub create :Chained('base') :PathPart('create') :Args(0) {
sub delete_all :Chained('base') :PathPart('delete_all') :Args(0) {
my ($self, $c) = @_;
- $self->basic_model_action( $c, {
+ $self->basic_model_action( $c, {
on_close_callback => sub { $self->on_delete_all_close_callback($c => @_) }
});
}