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