1 package Reaction::UI::Controller::Role::Action::Create;
3 use Moose::Role -traits => 'MethodAttributes';
4 use Reaction::UI::ViewPort::Action;
6 requires qw/get_collection make_context_closure setup_viewport/;
8 sub create :Action :Args(0) {
10 my $target = $c->stash->{collection} || $self->get_collection($c);
11 my %vp_args = ( model => $target->action_for('Create') );
13 if( $self->can('on_create_apply_callback') ){
14 my $apply = sub { $self->on_create_apply_callback( @_) };
15 $vp_args{on_apply_callback} = $self->make_context_closure( $apply );
17 if( $self->can('on_create_close_callback') ){
18 my $close = sub { $self->on_create_close_callback( @_) };
19 $vp_args{on_close_callback} = $self->make_context_closure( $close );
22 $self->setup_viewport( $c, \%vp_args );
25 around _build_action_viewport_map => sub {
27 my $map = shift->$orig( @_ );
28 $map->{create} = 'Reaction::UI::ViewPort::Action';
38 Reaction::UI::Controller::Role::Action::Create - Create action
42 Provides a C<create> action, which sets up an L<Action Viewport|Reaction::UI::Viewport::Action>
43 by calling C<action_for> on either the object located in the C<collection> slot
44 of the C<stash> or on the object returned by the method C<get_collection>.
48 package MyApp::Controller::Foo;
50 use base 'Reaction::Controller';
54 'Reaction::UI::Controller::Role::GetCollection',
55 'Reaction::UI::Controller::Role::Action::Simple',
56 'Reaction::UI::Controller::Role::Action::Create'
59 __PACKAGE__->config( action => {
60 create => { Chained => 'base' },
63 sub base :Chained('/base') :CaptureArgs(0) {
67 sub on_create_apply_callback{ #optional callback
68 my($self, $c, $vp, $result) = @_;
72 sub on_create_close_callback{ #optional callback
73 my($self, $c, $vp) = @_;
79 This role also consumes the following roles:
83 =item L<Reaction::UI::Controller::Role::Action::Simple>
87 =head1 REQUIRED METHODS
89 The following methods must be provided by the consuming class:
93 =item C<get_collection>
95 =item C<make_context_closure>
103 Chain endpoint with no args, sets up the viewport with the appropriate action.
104 If the methods C<on_create_apply_callback> and C<on_create_close_callback> are
105 present in the consuming class, they will be used as callbacks in the viewport.
109 =head2 _build_action_viewport_map
111 Extends to set the C<create> key in the map to L<Reaction::UI::ViewPort::Action>
117 =item L<Reaction::UI::Controller>
119 =item L<Reaction::UI::Controller::Role::GetCollection>
121 =item L<Reaction::UI::Controller::Role::Action::Simple>
123 =item L<Reaction::UI::Controller::Role::Action::List>
125 =item L<Reaction::UI::Controller::Role::Action::View>
127 =item L<Reaction::UI::Controller::Role::Action::Object>
129 =item L<Reaction::UI::Controller::Role::Action::Update>
131 =item L<Reaction::UI::Controller::Role::Action::Delete>
133 =item L<Reaction::UI::Controller::Role::Action::DeleteAll>
139 See L<Reaction::Class> for authors.
143 See L<Reaction::Class> for the license.