3 Reaction::Manual::ActionPrototypes - Changes to the Action Prototype Mechanism
7 After Reaction 0.001001 the API used to create links for different actions in
8 the L<ViewPort::Collection::Grid|Reaction::UI::ViewPort::Collection::Grid>
9 changed significantly. The aim of the changes was to create a simpler API that
10 was more concise, flexible, and didn't tie unneccessary controller logic in the
15 =head2 Controller Layer
17 =head3 L<Reaction::UI::Controller::Collection>
21 =item The default display class for the C<list> action is now
22 L<Grid|Reaction::UI::ViewPort::Collection::Grid>.
24 =item Addition of the C<default_member_actions> and C<default_collection_actions>
26 =item Addition of the C<_build_member_action_prototype> and
27 C<_build_collection_action_prototype> methods. These are used by
28 C<_build_action_viewport_args> to create prototypes for collection and member
33 =head3 L<Reaction::UI::Controller::Collection::CRUD>
35 By default, enable C<create>, C<update>, C<delete>, C<delete_all>, actions.
39 =head3 L<Reaction::UI::ViewPort::Collection::Grid>
43 =item Add the C<member_action_count> attribute. It allows the controller to
44 know how many actions to expect to lay out the UI properly.
46 =item Default to member-class
47 L<Grid::Member|Reaction::UI::ViewPort::Collection::Grid::Member>
51 =head2 L<Reaction::UI::ViewPort::Role::Actions>
53 Completely revamped the action-prototypes, added ordering support and moved to
54 using the new C<ViewPort::URI|Reaction::UI::ViewPort::URI>.
56 Most notably C<action_prototypes> is now a HASH ref.
60 In most cases, you shouldn't need to change much for migration, but if you had
61 custom actions in your controllers that were linked to by the CRUD system, or
62 you had excluded certain classes, you'll need to create some minor updates.
64 =head2 A custom collection action in your controller.
67 sub custom_action { ... }
68 sub _build_action_viewport_map {
69 my $map = shift->next::method(@_);
70 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
73 sub _build_action_viewport_args {
74 my $args = shift->next::method(@_);
77 action => sub { [ '', 'create', $_[1]->req->captures ] }
79 my $protos = $args->{list}->{action_prototypes};
80 push(@$protos, $custom_proto);
85 sub custom_action { ... }
86 sub _build_action_viewport_map {
87 my $map = shift->next::method(@_);
88 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
91 sub _build_default_collection_actions {
92 [ @{shift->next::method(@_)}, 'custom_action'];
95 =head2 A custom member action in your controller.
98 sub custom_action { ... }
99 sub _build_action_viewport_map {
100 my $map = shift->next::method(@_);
101 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
104 sub _build_action_viewport_args {
105 my $args = shift->next::method(@_);
108 action => sub { [ '', 'create', $_[1]->req->captures ] }
110 my $protos = $args->{list}->{Member}->{action_prototypes};
111 push(@$protos, $custom_proto);
116 sub custom_action { ... }
117 sub _build_action_viewport_map {
118 my $map = shift->next::method(@_);
119 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
122 sub _build_default_member_actions {
123 [ @{shift->next::method(@_)}, 'custom_action'];
127 =head2 Disabling a default collection action
131 sub _build_action_viewport_args {
132 my $args = shift->next::method(@_);
133 #remove the delete all action
134 my $protos = $args->{list}->{action_prototypes};
135 @$protos = grep { $_->{label} !~ /Delete all/i } @$protos;
141 sub _build_default_collection_actions {
142 [ grep {$_ ne 'delete_all'} @{ shift->next::method(@_) } ];
147 sub _build_action_viewport_args {
148 my $args = shift->next::method(@_);
149 my $protos = $args->{list}->{action_prototypes};
150 delete $protos->{delete_all};
155 =head2 Changing the label of a collection action
158 sub _build_action_viewport_args {
159 my $args = shift->next::method(@_);
160 my $protos = $args->{list}->{action_prototypes};
161 $proto = grep { $_->{label} eq 'Delete all' } @$protos;
162 $proto->{label} = 'New Label';
168 sub _build_action_viewport_args {
169 my $args = shift->next::method(@_);
170 my $protos = $args->{list}->{action_prototypes};
171 $proto->{delete_all}->{label} = 'New Label';
176 __PACKAGE__->config(action => { list => { ViewPort => {
177 action_prototypes => { delete_all => {label => 'New Label'} }