do not include .git directory
[catagits/Reaction.git] / lib / Reaction / Manual / ActionPrototypes.pod
1 =head1 NAME
2
3 Reaction::Manual::ActionPrototypes - Changes to the Action Prototype Mechanism
4
5 =head1 DESCRIPTION
6
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
11 ViewPort layer.
12
13 =head1 Major Changes
14
15 =head2 Controller Layer
16
17 =head3 L<Reaction::UI::Controller::Collection>
18
19 =over 4
20
21 =item The default display class for the C<list> action is now
22 L<Grid|Reaction::UI::ViewPort::Collection::Grid>.
23
24 =item Addition of the C<default_member_actions> and C<default_collection_actions>
25
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
29 actions.
30
31 =back
32
33 =head3 L<Reaction::UI::Controller::Collection::CRUD>
34
35 By default, enable C<create>, C<update>, C<delete>, C<delete_all>, actions. 
36
37 =head2 ViewPort Layer
38
39 =head3 L<Reaction::UI::ViewPort::Collection::Grid>
40
41 =over 4
42
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.
45
46 =item Default to member-class
47 L<Grid::Member|Reaction::UI::ViewPort::Collection::Grid::Member>
48
49 =back
50
51 =head2 L<Reaction::UI::ViewPort::Role::Actions>
52
53 Completely revamped the action-prototypes, added ordering support and moved to
54 using the new C<ViewPort::URI|Reaction::UI::ViewPort::URI>.
55
56 Most notably C<action_prototypes> is now a HASH ref.
57
58 =head1 Migration
59
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.
63
64 =head2 A custom collection action in your controller.
65
66     #old code
67     sub custom_action { ... }
68     sub _build_action_viewport_map {
69       my $map = shift->next::method(@_);
70       $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
71       return $map;
72     }
73     sub _build_action_viewport_args {
74       my $args = shift->next::method(@_);
75       my $custom_proto = {
76         label => 'Create',
77         action => sub { [ '', 'create',    $_[1]->req->captures ] } 
78       };
79       my $protos = $args->{list}->{action_prototypes};
80       push(@$protos, $custom_proto);
81       return $args;
82     }
83
84     #new code:
85     sub custom_action { ... }
86     sub _build_action_viewport_map {
87       my $map = shift->next::method(@_);
88       $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
89       return $map;
90     }
91     sub _build_default_collection_actions {
92       [ @{shift->next::method(@_)}, 'custom_action'];
93     }
94
95 =head2 A custom member action in your controller.
96
97     #old code
98     sub custom_action { ... }
99     sub _build_action_viewport_map {
100       my $map = shift->next::method(@_);
101       $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
102       return $map;
103     }
104     sub _build_action_viewport_args {
105       my $args = shift->next::method(@_);
106       my $custom_proto = {
107         label => 'Create',
108         action => sub { [ '', 'create',    $_[1]->req->captures ] } 
109       };
110       my $protos = $args->{list}->{Member}->{action_prototypes};
111       push(@$protos, $custom_proto);
112       return $args;
113     }
114
115     #new code:
116     sub custom_action { ... }
117     sub _build_action_viewport_map {
118       my $map = shift->next::method(@_);
119       $map->{custom_action} = 'Reaction::UI::ViewPort::Action';
120       return $map;
121     }
122     sub _build_default_member_actions {
123       [ @{shift->next::method(@_)}, 'custom_action'];
124     }
125
126
127 =head2 Disabling a default collection action
128
129     #old code
130     sub delete_all {}
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;
136       return $args;
137     }
138
139     #new code
140     sub delete_all {}
141     sub _build_default_collection_actions {
142       [ grep {$_ ne 'delete_all'} @{ shift->next::method(@_) } ];
143     }
144
145     #or ...
146     sub delete_all {}
147     sub _build_action_viewport_args {
148       my $args = shift->next::method(@_);
149       my $protos = $args->{list}->{action_prototypes};
150       delete $protos->{delete_all};
151       return $args;
152     }
153
154
155 =head2 Changing the label of a collection action
156
157     #old code
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';
163       return $args;
164     }
165
166     #new code
167     sub delete_all {}
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';
172       return $args;
173     }
174
175     #or ...
176     __PACKAGE__->config(action => { list => { ViewPort => {
177         action_prototypes => { delete_all => {label => 'New Label'} }
178       },
179     );
180
181 =cut