1 package Reaction::UI::Controller::Collection::CRUD;
3 use base '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',
22 # 'Reaction::UI::Controller::Role::Action::Create',
23 'Reaction::UI::Controller::Role::Action::Update',
24 'Reaction::UI::Controller::Role::Action::Delete',
25 'Reaction::UI::Controller::Role::Action::DeleteAll',
28 around _build_action_viewport_map => sub {
30 my $map = shift->$orig( @_ );
31 $map->{list} = ListView;
35 sub _build_default_member_actions {
36 [ @{shift->next::method(@_)}, qw/update delete/ ];
39 sub _build_default_collection_actions {
40 [ @{shift->next::method(@_)}, qw/create delete_all/ ];
45 sub on_delete_all_close_callback {
47 $self->redirect_to($c, 'list');
50 sub on_create_apply_callback {
51 my ($self, $c, $vp, $result) = @_;
52 return $self->redirect_to
53 ( $c, 'update', [ @{$c->req->captures}, $result->id ] );
56 sub on_create_close_callback {
57 my($self, $c, $vp) = @_;
58 $self->redirect_to( $c, 'list' );
61 sub on_update_close_callback {
63 #this needs a better solution. currently thinking about it
64 my @cap = @{$c->req->captures};
65 pop(@cap); # object id
66 $self->redirect_to($c, 'list', \@cap);
69 sub on_delete_close_callback {
71 #this needs a better solution. currently thinking about it
72 my @cap = @{$c->req->captures};
73 pop(@cap); # object id
74 $self->redirect_to($c, 'list', \@cap);
77 #### DEPRECATED METHODS
79 sub get_model_action {
80 my ($self, $c, $name, $target) = @_;
82 my ($package,undef,$line,$sub_name,@rest) = caller(1);
83 my $message = "The method 'get_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
84 $c->log->debug( $message );
86 return $target->action_for($name, ctx => $c);
89 sub basic_model_action {
90 my ($self, $c, $vp_args) = @_;
92 my ($package,undef,$line,$sub_name,@rest) = caller(1);
93 my $message = "The method 'basic_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
94 $c->log->debug( $message );
96 my $stash = $c->stash;
97 my $target = delete $vp_args->{target};
98 $target ||= ($stash->{object} || $stash->{collection} || $self->get_collection($c));
100 my $action_name = join('', map{ ucfirst } split('_', $c->stack->[-1]->name));
101 my $model = $self->get_model_action($c, $action_name, $target);
102 return $self->basic_page($c, { model => $model, %{$vp_args||{}} });
111 Reaction::UI::Controller::Collection::CRUD - Basic CRUD functionality for Reaction::InterfaceModel data
115 Controller class which extends L<Reaction::UI::Controller::Collection> to
116 provide basic Create / Update / Delete / DeleteAll actions.
118 Building on the base of the Collection controller this controller allows you to
119 easily create complex and highly flexible CRUD functionality for your
120 InterfaceModel models by providing a simple way to render and process your
121 custom InterfaceModel Actions and customize built-ins.
123 =head1 ROLES CONSUMED
125 This role also consumes the following roles:
129 =item L<Reaction::UI::Controller::Role::Action::Create>
131 =item L<Reaction::UI::Controller::Role::Action::Update>
133 =item L<Reaction::UI::Controller::Role::Action::Delete>
135 =item L<Reaction::UI::Controller::Role::Action::DeleteAll>
141 =head2 get_model_action $c, $action_name, $target_im
143 DEPRECATED. Get an instance of the C<$action_name>
144 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> for model C<$target>
145 This action is suitable for passing to an
146 C<Action|Reaction::UI::ViewPort::Action> viewport
148 =head2 basic_model_action $c, \%vp_args
150 DEPRECTAED extension to C<basic_page> which automatically instantiates an
151 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> with the right
152 data target using C<get_model_action>
154 =head2 after_create_callback $c, $vp, $result
156 When a <create> action is applied, move the user to the new object's,
159 =head2 _build_action_viewport_map
161 Map C<list> to L<ListView|Reaction::UI::ViewPort::ListView>.
163 =head2 _build_default_member_actions
165 Add C<update> and C<delete> to the list of default actions.
167 =head2 _build_default_collection_actions
169 Add C<create> and C<delete_all> to the list of default actions.
175 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::Create>
179 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::DeleteAll>
183 Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Update>
187 Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Delete>
191 L<Reaction::UI::Controller::Collection>, L<Reaction::UI::Controller>
195 See L<Reaction::Class> for authors.
199 See L<Reaction::Class> for the license.