1package Reaction::UI::Controller::Role::Action::Delete;
2
3use Moose::Role -traits => 'MethodAttributes';
4use Reaction::UI::ViewPort::Action;
5
6requires qw/make_context_closure setup_viewport/;
7
8sub delete :Action :Args(0) {
9  my ($self, $c) = @_;
10  my $target = $c->stash->{object};
11  my %vp_args = ( model => $target->action_for('Delete') );
12
13  if( $self->can('on_delete_apply_callback') ){
14    my $apply = sub { $self->on_delete_apply_callback( @_) };
15    $vp_args{on_apply_callback} = $self->make_context_closure( $apply );
16  }
17  if( $self->can('on_delete_close_callback') ){
18    my $close = sub { $self->on_delete_close_callback( @_) };
19    $vp_args{on_close_callback} = $self->make_context_closure( $close );
20  }
21
22  $self->setup_viewport( $c, \%vp_args );
23}
24
25around _build_action_viewport_map => sub {
26  my $orig = shift;
27  my $map = shift->$orig( @_ );
28  $map->{delete} = 'Reaction::UI::ViewPort::Action';
29  return $map;
30};
31
321;
33
34__END__;
35
36=head1 NAME
37
38Reaction::UI::Controller::Role::Action::Delete - Delete action
39
40=head1 DESCRIPTION
41
42Provides a C<delete> action, which sets up an L<Action Viewport|Reaction::UI::Viewport::Action>
43by calling C<action_for> on the object located in the C<object> slot of the
44C<stash>.
45
46=head1 SYNOPSYS
47
48    package MyApp::Controller::Foo;
49
50    use base 'Reaction::Controller';
51    use Reaction::Class;
52
53    with(
54      'Reaction::UI::Controller::Role::GetCollection',
55      'Reaction::UI::Controller::Role::Action::Simple',
56      'Reaction::UI::Controller::Role::Action::Object',
57      'Reaction::UI::Controller::Role::Action::Delete'
58    );
59
60    __PACKAGE__->config( action => {
61      object => { Chained => 'base' },
62      delete => { Chained => 'object' },
63    } );
64
65    sub base :Chained('/base') :CaptureArgs(0) {
66      ...
67    }
68
69    sub on_delete_apply_callback{ #optional callback
70      my($self, $c, $vp, $result) = @_;
71      ...
72    }
73
74    sub on_delete_close_callback{ #optional callback
75      my($self, $c, $vp) = @_;
76      ...
77    }
78
79=head1 ROLES CONSUMED
80
81This role also consumes the following roles:
82
83=over4
84
85=item L<Reaction::UI::Controller::Role::Action::Simple>
86
87=back
88
89=head1 REQUIRED METHODS
90
91The following methods must be provided by the consuming class:
92
93=over4
94
95=item C<make_context_closure>
96
97=back
98
99=head1 ACTIONS
100
101=head2 delete
102
103Chain endpoint with no args, sets up the viewport with the appropriate action.
104If the methods C<on_delete_apply_callback> and C<on_delete_close_callback> are
105present in the consuming class, they will be used as callbacks in the viewport.
106
107=head1 METHODS
108
109=head2 _build_action_viewport_map
110
111Extends to set the C<delete> key in the map to L<Reaction::UI::ViewPort::Action>
112
113=head1 SEE ALSO
114
115=over4
116
117=item L<Reaction::UI::Controller>
118
119=item L<Reaction::UI::Controller::Role::GetCollection>
120
121=item L<Reaction::UI::Controller::Role::Action::Simple>
122
123=item L<Reaction::UI::Controller::Role::Action::List>
124
125=item L<Reaction::UI::Controller::Role::Action::View>
126
127=item L<Reaction::UI::Controller::Role::Action::Object>
128
129=item L<Reaction::UI::Controller::Role::Action::Create>
130
131=item L<Reaction::UI::Controller::Role::Action::Update>
132
133=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
134
135=back
136
137=head1 AUTHORS
138
139See L<Reaction::Class> for authors.
140
141=head1 LICENSE
142
143See L<Reaction::Class> for the license.
144
145=cut
146