Commit | Line | Data |
2f670e13 |
1 | package Reaction::UI::Widget::Field::Mutable; |
2 | |
3 | use Reaction::UI::WidgetClass; |
4 | |
bae75bee |
5 | use namespace::clean -except => [ qw(meta) ]; |
6 | extends 'Reaction::UI::Widget::Field'; |
7 | |
8 | |
9 | |
10 | before fragment widget { |
11 | arg 'field_id' => event_id 'value_string'; |
12 | arg 'field_name' => event_id 'value_string' unless defined $_{field_name}; |
13 | arg 'field_type' => 'text'; |
14 | arg 'field_class' => "action-field " . $_{viewport}->name; |
15 | |
16 | # these two are to fire force_events in viewports |
17 | # where you can end up without an event for e.g. |
18 | # HTML checkbox fields |
19 | |
20 | arg 'exists_event' => event_id 'exists'; |
21 | arg 'exists_value' => 1; |
22 | }; |
23 | |
24 | implements fragment message_fragment { |
b44e101f |
25 | my $vp = $_{viewport}; |
c72dfafb |
26 | return unless $vp->has_message; |
27 | my $message = $vp->message; |
b44e101f |
28 | if ($message) { |
d219104c |
29 | arg message => localized $message; |
bae75bee |
30 | render 'message'; |
31 | } |
32 | }; |
33 | |
34 | implements fragment field_is_required { |
39453d9d |
35 | my $vp = $_{viewport}; |
36 | if ( $vp->value_is_required && !$vp->value_string ) { |
bae75bee |
37 | render 'field_is_required_yes'; |
38 | } else { |
39 | render 'field_is_required_no'; |
40 | } |
41 | }; |
42 | |
43 | __PACKAGE__->meta->make_immutable; |
44 | |
2f670e13 |
45 | |
46 | 1; |
47 | |
48 | __END__; |
f9b32c83 |
49 | |
50 | =head1 NAME |
51 | |
52 | Reaction::UI::Widget::Field::Mutable - Mutable fields |
53 | |
54 | =head1 DESCRIPTION |
55 | |
56 | An extension of L<Reaction::UI::Widget::Field> representing fields |
57 | whose values can be mutated. |
58 | |
59 | =head1 FRAGMENTS |
60 | |
61 | =head2 widget |
62 | |
63 | The following additional arguments are provided: |
64 | |
65 | =over 4 |
66 | |
67 | =item field_id |
68 | |
69 | Contains the viewport's event id for C<value_string>. |
70 | |
71 | =item field_name |
72 | |
73 | Defaults to the C<field_id> argument unless already defined |
74 | |
75 | =item field_type |
76 | |
77 | Defaults to C<text>. |
78 | |
79 | =item field_class |
80 | |
81 | A string containing the joined class attribute. Defaults to |
82 | C<action-field> and the current viewport's C<name>. |
83 | |
84 | =item exists_event |
85 | |
86 | Contains the event id for C<exists>. |
87 | |
88 | =item exists_value |
89 | |
90 | Defaults to C<1>. |
91 | |
92 | =back |
93 | |
94 | =head2 message_fragment |
95 | |
96 | Renders nothing if the viewport doesn't have a message. |
97 | |
98 | Otherwise, the C<message> argument will be set to the localised string contained |
99 | in the viewport's C<message> attribute and the C<message> fragment will be rendered. |
100 | |
101 | =head2 field_is_required |
102 | |
103 | Will render either C<field_is_required_yes> or C<field_is_required_no> depending on |
104 | if C<value_is_required> on the viewport returns true and the viewports C<value_string> |
105 | is empty. |
106 | |
107 | =head1 LAYOUT SETS |
108 | |
109 | =head2 base |
110 | |
111 | share/skin/base/layout/field/mutable.tt |
112 | |
113 | The following layouts are provided: |
114 | |
115 | =over 4 |
116 | |
117 | =item widget |
118 | |
119 | Builds a C<span> element with a class attribute set to the C<field_class> argument. |
120 | The element contents will be the C<label_fragment>, C<field> and C<message_fragment> |
121 | fragments. |
122 | |
123 | =item label |
124 | |
125 | Builds a C<label> element with the C<for> attribute set to the value of C<field_id> and |
126 | the other attributes used from the C<field_is_required> argument. The content will be |
127 | the C<label> argument. |
128 | |
129 | =item field_is_required_yes |
130 | |
131 | Sets the class attribute to C<required_field>. |
132 | |
133 | =item field_is_required_no |
134 | |
135 | Empty. |
136 | |
137 | =item message |
138 | |
139 | Renders a C<span> element with the C<message> as content. |
140 | |
141 | =item field |
142 | |
143 | Renders the input field. The C<field_body> fragment is used to set the value. |
144 | |
145 | =item field_body |
146 | |
147 | Creates the C<value> attribute for the input element. |
148 | |
149 | =back |
150 | |
151 | =head2 default |
152 | |
153 | share/skin/default/layout/field/mutable.tt |
154 | |
155 | The following layouts are provided: |
156 | |
157 | =over 4 |
158 | |
159 | =item message |
160 | |
161 | Will render the original C<message> fragment followed by a C<br> element. |
162 | |
163 | =back |
164 | |
165 | =head1 SUBCLASSES |
166 | |
167 | =over 4 |
168 | |
169 | =item L<Reaction::UI::Widget::Field::Mutable::Boolean> |
170 | |
171 | A widget allowing the manipulation of boolean values. |
172 | |
173 | =item L<Reaction::UI::Widget::Field::Mutable::ChooseMany> |
174 | |
175 | Allows the user to choose many items from a list of available values. |
176 | |
177 | =item L<Reaction::UI::Widget::Field::Mutable::ChooseOne> |
178 | |
179 | Allows the user to choose a single item from a list of available values. |
180 | |
181 | =item L<Reaction::UI::Widget::Field::Mutable::DateTime> |
182 | |
183 | A simple DateTime L<Reaction::UI::Widget::Field::Mutable> subclass. |
184 | |
185 | =item L<Reaction::UI::Widget::Field::Mutable::File> |
186 | |
187 | A simple file input field. |
188 | |
189 | =item L<Reaction::UI::Widget::Field::Mutable::HiddenArray> |
190 | |
191 | Renders an array reference value as a series of hidden fields. |
192 | |
193 | =item L<Reaction::UI::Widget::Field::Mutable::Integer> |
194 | |
195 | A simple integer L<Reaction::UI::Widget::Field::Mutable>. |
196 | |
197 | =item L<Reaction::UI::Widget::Field::Mutable::MatchingPasswords> |
198 | |
199 | Password input requiring that the password be entered twice, e.g. to input a new |
200 | password. |
201 | |
202 | =item L<Reaction::UI::Widget::Field::Mutable::Password> |
203 | |
204 | A password input L<Reaction::UI::Widget::Field::Mutable>. |
205 | |
206 | =item L<Reaction::UI::Widget::Field::Mutable::Number> |
207 | |
208 | A simple number L<Reaction::UI::Widget::Field::Mutable> input field. |
209 | |
210 | =item L<Reaction::UI::Widget::Field::Mutable::String> |
211 | |
212 | A simple string L<Reaction::UI::Widget::Field::Mutable> input field. |
213 | |
214 | =item L<Reaction::UI::Widget::Field::Mutable::Text> |
215 | |
216 | A multiline input L<Reaction::UI::Widget::Field::Mutable>. |
217 | |
218 | =back |
219 | |
220 | =head1 SEE ALSO |
221 | |
222 | =over 4 |
223 | |
224 | =item * L<Reaction::UI::Widget::Field> |
225 | |
226 | =back |
227 | |
228 | =head1 AUTHORS |
229 | |
230 | See L<Reaction::Class> for authors. |
231 | |
232 | =head1 LICENSE |
233 | |
234 | See L<Reaction::Class> for the license. |
235 | |
236 | =cut |