r31712@martha (orig r1247): groditi | 2009-10-02 17:02:01 -0400
[catagits/Reaction.git] / lib / Reaction / UI / Controller / Role / Action / Delete.pm
1 package Reaction::UI::Controller::Role::Action::Delete;
2
3 use Moose::Role -traits => 'MethodAttributes';
4 use Reaction::UI::ViewPort::Action;
5
6 requires qw/make_context_closure setup_viewport/;
7
8 sub 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
25 around _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
32 1;
33
34 __END__;
35
36 =head1 NAME
37
38 Reaction::UI::Controller::Role::Action::Delete - Delete action
39
40 =head1 DESCRIPTION
41
42 Provides a C<delete> action, which sets up an L<Action Viewport|Reaction::UI::Viewport::Action>
43 by calling C<action_for> on the object located in the C<object> slot of the
44 C<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
81 This 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
91 The 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
103 Chain endpoint with no args, sets up the viewport with the appropriate action.
104 If the methods C<on_delete_apply_callback> and C<on_delete_close_callback> are
105 present 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
111 Extends 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
139 See L<Reaction::Class> for authors.
140
141 =head1 LICENSE
142
143 See L<Reaction::Class> for the license.
144
145 =cut