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 if( $self->can('after_create_callback') ){
49 $c->log->debug("'after_create_callback' has been replaced with 'on_create_apply_callback' and is deprecated.");
51 return $self->after_create_callback(@_);
53 return $self->redirect_to
54 ( $c, 'update', [ @{$c->req->captures}, $result->id ] );
57 sub on_create_close_callback {
58 my($self, $c, $vp) = @_;
59 $self->redirect_to( $c, 'list' );
62 sub on_update_close_callback {
64 #this needs a better solution. currently thinking about it
65 my @cap = @{$c->req->captures};
66 pop(@cap); # object id
67 $self->redirect_to($c, 'list', \@cap);
70 sub on_delete_close_callback {
72 #this needs a better solution. currently thinking about it
73 my @cap = @{$c->req->captures};
74 pop(@cap); # object id
75 $self->redirect_to($c, 'list', \@cap);
78 #### DEPRECATED METHODS
80 sub get_model_action {
81 my ($self, $c, $name, $target) = @_;
83 my ($package,undef,$line,$sub_name,@rest) = caller(1);
84 my $message = "The method 'get_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
85 $c->log->debug( $message );
87 return $target->action_for($name, ctx => $c);
90 sub basic_model_action {
91 my ($self, $c, $vp_args) = @_;
93 my ($package,undef,$line,$sub_name,@rest) = caller(1);
94 my $message = "The method 'basic_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
95 $c->log->debug( $message );
97 my $stash = $c->stash;
98 my $target = delete $vp_args->{target};
99 $target ||= ($stash->{object} || $stash->{collection} || $self->get_collection($c));
101 my $action_name = join('', map{ ucfirst } split('_', $c->stack->[-1]->name));
102 my $model = $self->get_model_action($c, $action_name, $target);
103 return $self->basic_page($c, { model => $model, %{$vp_args||{}} });
112 Reaction::UI::Controller::Collection::CRUD - Basic CRUD functionality for Reaction::InterfaceModel data
116 Controller class which extends L<Reaction::UI::Controller::Collection> to
117 provide basic Create / Update / Delete / DeleteAll actions.
119 Building on the base of the Collection controller this controller allows you to
120 easily create complex and highly flexible CRUD functionality for your
121 InterfaceModel models by providing a simple way to render and process your
122 custom InterfaceModel Actions and customize built-ins.
124 =head1 ROLES CONSUMED
126 This role also consumes the following roles:
130 =item L<Reaction::UI::Controller::Role::Action::Create>
132 =item L<Reaction::UI::Controller::Role::Action::Update>
134 =item L<Reaction::UI::Controller::Role::Action::Delete>
136 =item L<Reaction::UI::Controller::Role::Action::DeleteAll>
142 =head2 get_model_action $c, $action_name, $target_im
144 DEPRECATED. Get an instance of the C<$action_name>
145 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> for model C<$target>
146 This action is suitable for passing to an
147 C<Action|Reaction::UI::ViewPort::Action> viewport
149 =head2 basic_model_action $c, \%vp_args
151 DEPRECTAED extension to C<basic_page> which automatically instantiates an
152 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> with the right
153 data target using C<get_model_action>
155 =head2 after_create_callback $c, $vp, $result
157 When a <create> action is applied, move the user to the new object's,
160 =head2 _build_action_viewport_map
162 Map C<list> to L<ListView|Reaction::UI::ViewPort::ListView>.
164 =head2 _build_default_member_actions
166 Add C<update> and C<delete> to the list of default actions.
168 =head2 _build_default_collection_actions
170 Add C<create> and C<delete_all> to the list of default actions.
176 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::Create>
180 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::DeleteAll>
184 Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Update>
188 Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Delete>
192 L<Reaction::UI::Controller::Collection>, L<Reaction::UI::Controller>
196 See L<Reaction::Class> for authors.
200 See L<Reaction::Class> for the license.