1 package Reaction::UI::Controller::Collection::CRUD;
4 BEGIN { extends 'Reaction::UI::Controller::Collection'; }
6 use aliased 'Reaction::UI::ViewPort::ListView';
10 create => { Chained => 'base', },
11 delete_all => { Chained => 'base', },
12 update => { Chained => 'object', },
13 delete => { Chained => 'object', },
18 'Reaction::UI::Controller::Role::Action::Create',
19 'Reaction::UI::Controller::Role::Action::Update',
20 'Reaction::UI::Controller::Role::Action::Delete',
21 'Reaction::UI::Controller::Role::Action::DeleteAll',
24 around _build_action_viewport_map => sub {
26 my $map = shift->$orig( @_ );
27 $map->{list} = ListView;
31 sub _build_default_member_actions {
32 [ @{shift->next::method(@_)}, qw/update delete/ ];
35 sub _build_default_collection_actions {
36 [ @{shift->next::method(@_)}, qw/create delete_all/ ];
41 sub on_delete_all_close_callback {
43 $self->redirect_to($c, 'list');
46 sub on_create_apply_callback {
47 my ($self, $c, $vp, $result) = @_;
48 return $self->redirect_to
49 ( $c, 'update', [ @{$c->req->captures}, $result->id ] );
52 sub on_create_close_callback {
53 my($self, $c, $vp) = @_;
54 $self->redirect_to( $c, 'list' );
57 sub on_update_close_callback {
59 #this needs a better solution. currently thinking about it
60 my @cap = @{$c->req->captures};
61 pop(@cap); # object id
62 $self->redirect_to($c, 'list', \@cap);
65 sub on_delete_close_callback {
67 #this needs a better solution. currently thinking about it
68 my @cap = @{$c->req->captures};
69 pop(@cap); # object id
70 $self->redirect_to($c, 'list', \@cap);
73 #### DEPRECATED METHODS
75 sub get_model_action {
76 my ($self, $c, $name, $target) = @_;
78 my ($package,undef,$line,$sub_name,@rest) = caller(1);
79 my $message = "The method 'get_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
80 $c->log->debug( $message );
82 return $target->action_for($name, ctx => $c);
85 sub basic_model_action {
86 my ($self, $c, $vp_args) = @_;
88 my ($package,undef,$line,$sub_name,@rest) = caller(1);
89 my $message = "The method 'basic_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
90 $c->log->debug( $message );
92 my $stash = $c->stash;
93 my $target = delete $vp_args->{target};
94 $target ||= ($stash->{object} || $stash->{collection} || $self->get_collection($c));
96 my $action_name = join('', map{ ucfirst } split('_', $c->stack->[-1]->name));
97 my $model = $self->get_model_action($c, $action_name, $target);
98 return $self->basic_page($c, { model => $model, %{$vp_args||{}} });
107 Reaction::UI::Controller::Collection::CRUD - Basic CRUD functionality for Reaction::InterfaceModel data
111 Controller class which extends L<Reaction::UI::Controller::Collection> to
112 provide basic Create / Update / Delete / DeleteAll actions.
114 Building on the base of the Collection controller this controller allows you to
115 easily create complex and highly flexible CRUD functionality for your
116 InterfaceModel models by providing a simple way to render and process your
117 custom InterfaceModel Actions and customize built-ins.
119 =head1 ROLES CONSUMED
121 This role also consumes the following roles:
125 =item L<Reaction::UI::Controller::Role::Action::Create>
127 =item L<Reaction::UI::Controller::Role::Action::Update>
129 =item L<Reaction::UI::Controller::Role::Action::Delete>
131 =item L<Reaction::UI::Controller::Role::Action::DeleteAll>
137 =head2 get_model_action $c, $action_name, $target_im
139 DEPRECATED. Get an instance of the C<$action_name>
140 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> for model C<$target>
141 This action is suitable for passing to an
142 C<Action|Reaction::UI::ViewPort::Action> viewport
144 =head2 basic_model_action $c, \%vp_args
146 DEPRECTAED extension to C<basic_page> which automatically instantiates an
147 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> with the right
148 data target using C<get_model_action>
150 =head2 after_create_callback $c, $vp, $result
152 When a <create> action is applied, move the user to the new object's,
155 =head2 _build_action_viewport_map
157 Map C<list> to L<ListView|Reaction::UI::ViewPort::ListView>.
159 =head2 _build_default_member_actions
161 Add C<update> and C<delete> to the list of default actions.
163 =head2 _build_default_collection_actions
165 Add C<create> and C<delete_all> to the list of default actions.
171 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::Create>
175 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::DeleteAll>
179 Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Update>
183 Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Delete>
187 L<Reaction::UI::Controller::Collection>, L<Reaction::UI::Controller>
191 See L<Reaction::Class> for authors.
195 See L<Reaction::Class> for the license.