1 =head1 Changes to the Action Prototype Mechanism
5 After Reaction 0.001001 the API used to create links for different actions in
6 the L<ViewPort::Collection::Grid|Reaction::UI::ViewPort::Collection::Grid>
7 changed significantly. The aim of the changes was to create a simpler API that
8 was more concise, flexible, and didn't tie unneccessary controller logic in the
13 =head2 Controller Layer
15 =head3 L<Reaction::UI::Controller::Collection>
19 =item The default display class for the C<list> action is now
20 L<Grid|Reaction::UI::ViewPort::Collection::Grid>.
22 =item Addition of the C<default_member_actions> and C<default_collection_actions>
24 =item Addition of the C<_build_member_action_prototype> and
25 C<_build_collection_action_prototype> methods. These are used by
26 C<_build_action_viewport_args> to create prototypes for collection and member
31 =head3 L<Reaction::UI::Controller::Collection::CRUD>
33 By default, enable C<create>, C<update>, C<delete>, C<delete_all>, actions.
37 =head3 L<Reaction::UI::ViewPort::Collection::Grid>
41 =item Add the C<member_action_count> attribute. It allows the controller to
42 know how many actions to expect to lay out the UI properly.
44 =item Default to member-class
45 L<Grid::Member::WithActions|Reaction::UI::ViewPort::Collection::Grid::Member::WithActions>
49 =head2 L<Reaction::UI::ViewPort::Role::Actions>
51 Completely revamped the action-prototypes, added ordering support and moved to
52 using the new C<ViewPort::URI|Reaction::UI::ViewPort::URI>.
54 Most notably C<action_prototypes> is now a HASH ref.
58 In most cases, you shouldn't need to change much for migration, but if you had
59 custom actions in your controllers that were linked to by the CRUD system, or
60 you had excluded certain classes, you'll need to create some minor updates.
62 =head2 A custom collection action in your controller.
65 sub custom_action { ... }
66 sub _build_action_viewport_map {
67 my $map = shift->next::method(@_);
68 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
71 sub _build_action_viewport_args {
72 my $args = shift->next::method(@_);
75 action => sub { [ '', 'create', $_[1]->req->captures ] }
77 my $protos = $args->{list}->{action_prototypes};
78 push(@$protos, $custom_proto);
83 sub custom_action { ... }
84 sub _build_action_viewport_map {
85 my $map = shift->next::method(@_);
86 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
89 sub _build_default_collection_actions {
90 [ @{shift->next::method(@_)}, 'custom_action'];
93 =head2 A custom member action in your controller.
96 sub custom_action { ... }
97 sub _build_action_viewport_map {
98 my $map = shift->next::method(@_);
99 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
102 sub _build_action_viewport_args {
103 my $args = shift->next::method(@_);
106 action => sub { [ '', 'create', $_[1]->req->captures ] }
108 my $protos = $args->{list}->{Member}->{action_prototypes};
109 push(@$protos, $custom_proto);
114 sub custom_action { ... }
115 sub _build_action_viewport_map {
116 my $map = shift->next::method(@_);
117 $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
120 sub _build_default_member_actions {
121 [ @{shift->next::method(@_)}, 'custom_action'];
125 =head2 Disabling a default collection action
129 sub _build_action_viewport_args {
130 my $args = shift->next::method(@_);
131 #remove the delete all action
132 my $protos = $args->{list}->{action_prototypes};
133 @$protos = grep { $_->{label} !~ /Delete all/i } @$protos;
139 sub _build_default_collection_actions {
140 [ grep {$_ ne 'delete_all'} @{ shift->next::method(@_) } ];
145 sub _build_action_viewport_args {
146 my $args = shift->next::method(@_);
147 my $protos = $args->{list}->{action_prototypes};
148 delete $protos->{delete_all};
153 =head2 Changing the label of a collection action
156 sub _build_action_viewport_args {
157 my $args = shift->next::method(@_);
158 my $protos = $args->{list}->{action_prototypes};
159 $proto = grep { $_->{label} eq 'Delete all' } @$protos;
160 $proto->{label} = 'New Label';
166 sub _build_action_viewport_args {
167 my $args = shift->next::method(@_);
168 my $protos = $args->{list}->{action_prototypes};
169 $proto->{delete_all}->{label} = 'New Label';
174 __PACKAGE__->config(action => { list => { ViewPort => {
175 action_prototypes => { delete_all => {label => 'New Label'} }