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