Commit | Line | Data |
2f670e13 |
1 | package Reaction::UI::Widget::Action; |
9de685fc |
2 | |
3 | use Reaction::UI::WidgetClass; |
4 | |
bae75bee |
5 | use namespace::clean -except => [ qw(meta) ]; |
599c1172 |
6 | extends 'Reaction::UI::Widget::Object::Mutable'; |
bae75bee |
7 | |
8 | after 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 |
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 | |
bae75bee |
27 | implements 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 | |
35 | implements 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 | |
43 | implements 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 |
51 | implements 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 |
62 | 1; |
63 | |
64 | __END__; |
65 | |
5a1a893e |
66 | =head1 NAME |
9de685fc |
67 | |
2f670e13 |
68 | Reaction::UI::Widget::Action |
9de685fc |
69 | |
5a1a893e |
70 | =head1 DESCRIPTION |
9de685fc |
71 | |
f9b32c83 |
72 | This is a subclass of L<Reaction::UI::Widget::Object::Mutable>. |
73 | |
5a1a893e |
74 | =head1 FRAGMENTS |
9de685fc |
75 | |
f9b32c83 |
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 | |
cc44a337 |
93 | =head2 ok_button_fragment |
5a1a893e |
94 | |
f9b32c83 |
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 | |
cc44a337 |
111 | =head2 apply_button_fragment |
5a1a893e |
112 | |
f9b32c83 |
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 | |
cc44a337 |
129 | =head2 cancel_button_fragment |
5a1a893e |
130 | |
f9b32c83 |
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 | |
5a1a893e |
238 | =head1 AUTHORS |
239 | |
240 | See L<Reaction::Class> for authors. |
241 | |
242 | =head1 LICENSE |
243 | |
244 | See L<Reaction::Class> for the license. |
9de685fc |
245 | |
246 | =cut |
5a1a893e |
247 | |