1 package Reaction::UI::Controller::Collection;
3 use base 'Reaction::UI::Controller';
6 use aliased 'Reaction::UI::ViewPort::Collection::Grid';
10 list => { Chained => 'base', PathPart => '' },
11 object => { Chained => 'base', PathPart => 'id' },
12 view => { Chained => 'object', },
17 'Reaction::UI::Controller::Role::GetCollection',
18 'Reaction::UI::Controller::Role::Action::Simple',
19 'Reaction::UI::Controller::Role::Action::Object',
20 'Reaction::UI::Controller::Role::Action::View',
21 'Reaction::UI::Controller::Role::Action::List'
24 has default_member_actions => (
30 has default_collection_actions => (
36 sub _build_default_member_actions { ['view'] }
38 sub _build_default_collection_actions { [] }
40 around _build_action_viewport_map => sub {
42 my $map = shift->$orig( @_ );
47 around _build_action_viewport_args => sub {
50 my $args = { list => { Member => {} } };
52 my $m_protos = $args->{list}{Member}{action_prototypes} = {};
53 for my $action_name( @{ $self->default_member_actions }){
54 my $label = join(' ', map { ucfirst } split(/_/, $action_name));
55 my $proto = $self->_build_member_action_prototype($label, $action_name);
56 $m_protos->{$action_name} = $proto;
59 my $c_protos = $args->{list}{action_prototypes} = {};
60 for my $action_name( @{ $self->default_collection_actions }){
61 my $label = join(' ', map { ucfirst } split(/_/, $action_name));
62 my $proto = $self->_build_collection_action_prototype($label, $action_name);
63 $c_protos->{$action_name} = $proto;
69 sub _build_member_action_prototype {
70 my ($self, $label, $action_name) = @_;
74 my $action = $self->action_for($action_name);
75 $_[1]->uri_for($action, [ @{$_[1]->req->captures}, $_[0]->__id ]);
80 sub _build_collection_action_prototype {
81 my ($self, $label, $action_name) = @_;
85 my $action = $self->action_for($action_name);
86 $_[1]->uri_for($action, $_[1]->req->captures);
92 sub base :CaptureArgs(0) {
99 my( $self, $c, @args) = @_;
101 my ($package,undef,$line,$sub_name,@rest) = caller(1);
102 my $message = "The method 'basic_page', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated. Please use 'setup_viewport' instead.";
103 $c->log->debug( $message );
105 $self->setup_viewport( $c, @args );
114 Reaction::UI::Controller
118 Controller class used to make displaying collections easier.
119 Inherits from L<Reaction::UI::Controller>.
121 =head1 ROLES CONSUMED
123 This role also consumes the following roles:
127 =item L<Reaction::UI::Controller::Role::Action::GetCollection>
129 =item L<Reaction::UI::Controller::Role::Action::Simple>
131 =item L<Reaction::UI::Controller::Role::Action::Object>
133 =item L<Reaction::UI::Controller::Role::Action::List>
135 =item L<Reaction::UI::Controller::Role::Action::View>
141 =head2 default_member_actions
143 Read-write lazy building arrayref. The names of the member actions (the actions
144 that apply to each member of the collection and typically have an object as a
145 target e.g. update,delete) to be enabled by default. By default, this is only
150 =item B<_build_default_member_actions> - Provided builder method, see METHODS
152 =item B<has_default_member_actions> - Auto generated predicate
154 =item B<clear_default_member_actions>- Auto generated clearer method
158 =head2 default_collection_actions
160 Read-write lazy building arrayref. The names of the collection actions (the
161 actions that apply to the entire collection and typically have a collection as
162 a target e.g. create, delete_all) to be enabled by default. By default, this
167 =item B<_build_default_member_actions> - Provided builder method, see METHODS
169 =item B<has_default_member_actions> - Auto generated predicate
171 =item B<clear_default_member_actions>- Auto generated clearer method
177 =head2 _build_action_viewport_map
179 Set C<list> to L<Reaction::UI::ViewPort::Collection::Grid>
181 =head2 _build_action_viewport_args
183 By default will reurn a hashref containing action prototypes for all default
184 member and collection actions. The prototype URI generators are generated by
185 C<_build_member_action_prototype> and C<_build_collection_action_prototype>
186 respectively and labels are the result of replacing underscores in the name
187 with spaces and capitalizing the first letter. If you plan to use custom
188 actions that are not supported by this scheme or you would like to customize
189 the values it is suggested you wrap / override this method.
191 Default output for a controller having only 'view' enabled:
194 action_prototypes => {},
196 action_prototypes => {
197 view => {label => 'View', uri => sub{...} },
203 =head2 _build_member_action_prototype $label, $action_name
205 Creates an action prototype suitable for creating action links in
206 L<Reaction::UI::ViewPort::Role::Actions>. C<$action_name> should be the name of
207 a Catalyst action in this controller.The prototype will generate a URI
208 based on the action, current captures.
210 =head2 _build_collection_action_prototype $label, $action_name
212 =head2 basic_page $c, \%vp_args
214 Deprecated alias to C<setup_viewport>.
224 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::List>
228 Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::Object>
232 Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::View>
236 L<Reaction::UI::Controller>
240 See L<Reaction::Class> for authors.
244 See L<Reaction::Class> for the license.