| Reaction documentation | Contained in the Reaction distribution. |
Reaction::UI::Controller::Collection
Controller class used to make displaying collections easier. Inherits from Reaction::UI::Controller.
This role also consumes the following roles:
Read-write lazy building arrayref. The names of the member actions (the actions that apply to each member of the collection and typically have an object as a target e.g. update,delete) to be enabled by default. By default, this is only 'view'
Read-write lazy building arrayref. The names of the collection actions (the actions that apply to the entire collection and typically have a collection as a target e.g. create, delete_all) to be enabled by default. By default, this is only empty.
Set list to Reaction::UI::ViewPort::Collection::Grid
By default will reurn a hashref containing action prototypes for all default
member and collection actions. The prototype URI generators are generated by
_build_member_action_prototype and _build_collection_action_prototype
respectively and labels are the result of replacing underscores in the name
with spaces and capitalizing the first letter. If you plan to use custom
actions that are not supported by this scheme or you would like to customize
the values it is suggested you wrap / override this method.
Default output for a controller having only 'view' enabled:
{ list => {
action_prototypes => {},
Member => {
action_prototypes => {
view => {label => 'View', uri => sub{...} },
},
},
},
}
Creates an action prototype suitable for creating action links in
Reaction::UI::ViewPort::Role::Actions. $action_name should be the name of
a Catalyst action in this controller.The prototype will generate a URI
based on the action, current captures.
Deprecated alias to setup_viewport.
Chain link, no-op.
Chained to base. See Reaction::UI::Controller::Role::Action::List
Chained to base. See Reaction::UI::Controller::Role::Action::Object
Chained to object. See Reaction::UI::Controller::Role::Action::View
See Reaction::Class for authors.
See Reaction::Class for the license.
| Reaction documentation | Contained in the Reaction distribution. |
package Reaction::UI::Controller::Collection; use Moose; BEGIN { extends 'Reaction::UI::Controller'; } use aliased 'Reaction::UI::ViewPort::Collection::Grid'; __PACKAGE__->config( action => { list => { Chained => 'base', PathPart => '' }, object => { Chained => 'base', PathPart => 'id' }, view => { Chained => 'object', }, }, ); with( 'Reaction::UI::Controller::Role::GetCollection', 'Reaction::UI::Controller::Role::Action::Simple', 'Reaction::UI::Controller::Role::Action::Object', 'Reaction::UI::Controller::Role::Action::View', 'Reaction::UI::Controller::Role::Action::List' ); has default_member_actions => ( isa => 'ArrayRef', is => 'rw', lazy_build => 1 ); has default_collection_actions => ( isa => 'ArrayRef', is => 'rw', lazy_build => 1 ); sub _build_default_member_actions { ['view'] } sub _build_default_collection_actions { [] } around _build_action_viewport_map => sub { my $orig = shift; my $map = shift->$orig( @_ ); $map->{list} = Grid; return $map; }; around _build_action_viewport_args => sub { my $orig = shift; my $self = shift; my $args = { list => { Member => {} } }; my $m_protos = $args->{list}{Member}{action_prototypes} = {}; for my $action_name( @{ $self->default_member_actions }){ my $label = join(' ', map { ucfirst } split(/_/, $action_name)); my $proto = $self->_build_member_action_prototype($label, $action_name); $m_protos->{$action_name} = $proto; } my $c_protos = $args->{list}{action_prototypes} = {}; for my $action_name( @{ $self->default_collection_actions }){ my $label = join(' ', map { ucfirst } split(/_/, $action_name)); my $proto = $self->_build_collection_action_prototype($label, $action_name); $c_protos->{$action_name} = $proto; } return $args; }; sub _build_member_action_prototype { my ($self, $label, $action_name) = @_; return { label => $label, uri => sub { my $action = $self->action_for($action_name); $_[1]->uri_for($action, [ @{$_[1]->req->captures}, $_[0]->__id ]); }, }; } sub _build_collection_action_prototype { my ($self, $label, $action_name) = @_; return { label => $label, uri => sub { my $action = $self->action_for($action_name); $_[1]->uri_for($action, $_[1]->req->captures); }, }; } sub base :CaptureArgs(0) { my ($self, $c) = @_; } ##DEPRECATED ACTION sub basic_page { my( $self, $c, @args) = @_; if( $c->debug ){ my ($package,undef,$line,$sub_name,@rest) = caller(1); my $message = "The method 'basic_page', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated. Please use 'setup_viewport' instead."; $c->log->debug( $message ); } $self->setup_viewport( $c, @args ); } 1; __END__;