do not include .git directory
[catagits/Reaction.git] / lib / Reaction / UI / Widget / Action.pm
CommitLineData
2f670e13 1package Reaction::UI::Widget::Action;
9de685fc 2
3use Reaction::UI::WidgetClass;
4
bae75bee 5use namespace::clean -except => [ qw(meta) ];
599c1172 6extends 'Reaction::UI::Widget::Object::Mutable';
bae75bee 7
8after fragment widget {
7b5e71ad 9 my $vp = $_{viewport};
10 arg 'method' => $vp->method;
11 arg 'form_id' => $vp->location;
12 arg 'action' => $vp->has_action ? $vp->action : '';
bae75bee 13};
14
e29819c4 15implements fragment message {
16 return unless $_{viewport}->has_message;
17 arg message_string => $_{viewport}->message;
18 render 'message_layout';
19};
20
21implements fragment error_message {
22 return unless $_{viewport}->has_error_message;
23 arg message_string => $_{viewport}->error_message;
24 render 'error_message_layout';
25};
26
bae75bee 27implements fragment ok_button_fragment {
28 if (grep { $_ eq 'ok' } $_{viewport}->accept_events) {
29 arg 'event_id' => event_id 'ok';
d219104c 30 arg 'label' => localized $_{viewport}->ok_label;
bae75bee 31 render 'ok_button';
32 }
33};
34
35implements fragment apply_button_fragment {
36 if (grep { $_ eq 'apply' } $_{viewport}->accept_events) {
37 arg 'event_id' => event_id 'apply';
d219104c 38 arg 'label' => localized $_{viewport}->apply_label;
bae75bee 39 render 'apply_button';
40 }
41};
42
43implements fragment cancel_button_fragment {
44 if (grep { $_ eq 'close' } $_{viewport}->accept_events) {
45 arg 'event_id' => event_id 'close';
d219104c 46 arg 'label' => localized $_{viewport}->close_label;
bae75bee 47 render 'cancel_button';
48 }
9de685fc 49};
50
fc758fea 51implements fragment maybe_inner {
52 if( my $inner = $_{viewport}->inner ){
53 arg '_' => $inner;
54 render 'viewport';
55 }
56};
57
58
bae75bee 59__PACKAGE__->meta->make_immutable;
60
61
9de685fc 621;
63
64__END__;
65
5a1a893e 66=head1 NAME
9de685fc 67
2f670e13 68Reaction::UI::Widget::Action
9de685fc 69
5a1a893e 70=head1 DESCRIPTION
9de685fc 71
f9b32c83 72This is a subclass of L<Reaction::UI::Widget::Object::Mutable>.
73
5a1a893e 74=head1 FRAGMENTS
9de685fc 75
f9b32c83 76=head2 widget
77
78Additionally provides the C<method> argument containing the value of
79the viewport's C<method>.
80
81=head2 message
82
83Empty if the viewport's C<has_message> returns false. Otherwise sets
84the C<message_string> argument to the viewport's C<message> and
85renders the C<message_layout> fragment.
86
87=head2 error_message
88
89Same as the C<message> fragment above except that it checks
90C<has_error_message>, sets C<message_string> to the viewport's
91C<error_message> and renders C<error_message_layout>.
92
cc44a337 93=head2 ok_button_fragment
5a1a893e 94
f9b32c83 95Renders nothing unless the viewport accepts the C<ok> event.
96
97If it does, it provides the following arguments before rendering C<ok_button>:
98
99=over 4
100
101=item event_id
102
103Is set to the event id C<ok>.
104
105=item label
106
107Is set to the localized C<ok_label> of the viewport.
108
109=back
110
cc44a337 111=head2 apply_button_fragment
5a1a893e 112
f9b32c83 113Renders nothing unless the viewport accepts the C<apply> event.
114
115If it does, it provides the following arguments before rendering C<apply_button>:
116
117=over 4
118
119=item event_id
120
121Is set to the event id C<apply>.
122
123=item label
124
125Is set to the localized C<apply_label> of the viewport.
126
127=back
128
cc44a337 129=head2 cancel_button_fragment
5a1a893e 130
f9b32c83 131Renders nothing unless the viewport accepts the C<close> event.
132
133If it does, it provides the following arguments before rendering C<cancel_button>:
134
135=over 4
136
137=item event_id
138
139Is set to the event id C<close>.
140
141=item label
142
143Is set to the localized C<close_label> of the viewport.
144
145=back
146
147=head1 LAYOUT SETS
148
149=head2 base
150
151 share/skin/base/layout/action.tt
152
153The following layouts are provided:
154
155=over 4
156
157=item widget
158
159Renders a C<div> element containing a C<form>. The C<form> element contains the rendered
160C<header>, C<container_list>, C<buttons> and C<footer> fragments.
161
162=item header
163
164Renders the error message.
165
166=item container_list
167
168Simply renders the parent C<container_list>.
169
170=item container
171
172Simply renders the parent C<container>.
173
174=item buttons
175
176First renders the C<message> fragment, then the C<ok_button_fragment>, the C<apply_button_fragment>
177and the C<cancel_button_fragment>.
178
179=item message_layout
180
181Renders the C<message_string> argument in a C<span> element with an C<action_message> class.
182
183=item error_message_layout
184
185Renders the C<message_string> argument in a C<span> element with an C<action_error_message> class.
186
187=item standard_button
188
189Renders a submit button in a C<span> with the C<name> set to the C<event_id> argument, and the
190value set to the C<label> argument.
191
192=item ok_button
193
194Renders the C<standard_button> fragment.
195
196=item apply_button
197
198Renders the C<standard_button> fragment.
199
200=item cancel_button
201
202Renders the C<standard_button> fragment.
203
204=item footer
205
206Empty by default.
207
208=back
209
210=head2 default
211
212 share/skin/base/layout/action.tt
213
214Extends the layout set of the same name in the parent skin.
215
216The following layouts are provided:
217
218=over 4
219
220=item container
221
222Adds a C<br> element after the original C<container> fragment.
223
224=item message_layout
225
226Adds a C<br> element after the original C<message_layout> fragment.
227
228=back
229
230=head1 SEE ALSO
231
232=over 4
233
234=item L<Reaction::UI::Widget::Object::Mutable>
235
236=back
237
5a1a893e 238=head1 AUTHORS
239
240See L<Reaction::Class> for authors.
241
242=head1 LICENSE
243
244See L<Reaction::Class> for the license.
9de685fc 245
246=cut
5a1a893e 247