Revision dc48be1c
Von Moritz Bunkus vor fast 8 Jahren hinzugefügt
SL/Presenter/Tag.pm | ||
---|---|---|
7 | 7 |
use parent qw(Exporter); |
8 | 8 |
|
9 | 9 |
use Exporter qw(import); |
10 |
our @EXPORT = qw(html_tag input_tag hidden_tag javascript man_days_tag name_to_id select_tag checkbox_tag stringify_attributes restricted_html); |
|
10 |
our @EXPORT = qw(html_tag input_tag hidden_tag javascript man_days_tag name_to_id select_tag checkbox_tag button_tag submit_tag ajax_submit_tag stringify_attributes restricted_html);
|
|
11 | 11 |
|
12 | 12 |
use Carp; |
13 | 13 |
|
... | ... | |
30 | 30 |
} |
31 | 31 |
} |
32 | 32 |
|
33 |
sub _J { |
|
34 |
my $string = shift; |
|
35 |
$string =~ s/(\"|\'|\\)/\\$1/g; |
|
36 |
return $string; |
|
37 |
} |
|
33 | 38 |
|
34 | 39 |
sub stringify_attributes { |
35 | 40 |
my ($self, %params) = @_; |
... | ... | |
219 | 224 |
return $code; |
220 | 225 |
} |
221 | 226 |
|
227 |
sub button_tag { |
|
228 |
my ($self, $onclick, $value, %attributes) = @_; |
|
229 |
|
|
230 |
_set_id_attribute(\%attributes, $attributes{name}) if $attributes{name}; |
|
231 |
$attributes{type} ||= 'button'; |
|
232 |
|
|
233 |
$onclick = 'if (!confirm("'. _J(delete($attributes{confirm})) .'")) return false; ' . $onclick if $attributes{confirm}; |
|
234 |
|
|
235 |
return $self->html_tag('input', undef, %attributes, value => $value, onclick => $onclick); |
|
236 |
} |
|
237 |
|
|
238 |
sub submit_tag { |
|
239 |
my ($self, $name, $value, %attributes) = @_; |
|
240 |
|
|
241 |
_set_id_attribute(\%attributes, $attributes{name}) if $attributes{name}; |
|
242 |
|
|
243 |
if ( $attributes{confirm} ) { |
|
244 |
$attributes{onclick} = 'return confirm("'. _J(delete($attributes{confirm})) .'");'; |
|
245 |
} |
|
246 |
|
|
247 |
return $self->input_tag($name, $value, %attributes, type => 'submit', class => 'submit'); |
|
248 |
} |
|
249 |
|
|
250 |
sub ajax_submit_tag { |
|
251 |
my ($self, $url, $form_selector, $text, %attributes) = @_; |
|
252 |
|
|
253 |
$url = _J($url); |
|
254 |
$form_selector = _J($form_selector); |
|
255 |
my $onclick = qq|kivi.submit_ajax_form('${url}', '${form_selector}')|; |
|
256 |
|
|
257 |
return $self->button_tag($onclick, $text, %attributes); |
|
258 |
} |
|
259 |
|
|
222 | 260 |
sub javascript { |
223 | 261 |
my ($self, $data) = @_; |
224 | 262 |
return $self->html_tag('script', $data, type => 'text/javascript'); |
... | ... | |
329 | 367 |
C<$value> and with arbitrary HTML attributes from C<%attributes>. The |
330 | 368 |
tag's C<id> defaults to C<name_to_id($name)>. |
331 | 369 |
|
370 |
=item C<submit_tag $name, $value, %attributes> |
|
371 |
|
|
372 |
Creates a HTML 'input type=submit class=submit' tag named C<$name> with the |
|
373 |
value C<$value> and with arbitrary HTML attributes from C<%attributes>. The |
|
374 |
tag's C<id> defaults to C<name_to_id($name)>. |
|
375 |
|
|
376 |
If C<$attributes{confirm}> is set then a JavaScript popup dialog will |
|
377 |
be added via the C<onclick> handler asking the question given with |
|
378 |
C<$attributes{confirm}>. The request is only submitted if the user |
|
379 |
clicks the dialog's ok/yes button. |
|
380 |
|
|
381 |
=item C<ajax_submit_tag $url, $form_selector, $text, %attributes> |
|
382 |
|
|
383 |
Creates a HTML 'input type="button"' tag with a very specific onclick |
|
384 |
handler that submits the form given by the jQuery selector |
|
385 |
C<$form_selector> to the URL C<$url> (the actual JavaScript function |
|
386 |
called for that is C<kivi.submit_ajax_form()> in |
|
387 |
C<js/client_js.js>). The button's label will be C<$text>. |
|
388 |
|
|
389 |
=item C<button_tag $onclick, $text, %attributes> |
|
390 |
|
|
391 |
Creates a HTML 'input type="button"' tag with an onclick handler |
|
392 |
C<$onclick> and a value of C<$text>. The button does not have a name |
|
393 |
nor an ID by default. |
|
394 |
|
|
395 |
If C<$attributes{confirm}> is set then a JavaScript popup dialog will |
|
396 |
be prepended to the C<$onclick> handler asking the question given with |
|
397 |
C<$attributes{confirm}>. The request is only submitted if the user |
|
398 |
clicks the dialog's "ok/yes" button. |
|
399 |
|
|
332 | 400 |
=item C<man_days_tag $name, $object, %attributes> |
333 | 401 |
|
334 | 402 |
Creates two HTML inputs: a text input for entering a number and a drop |
SL/Template/Plugin/L.pm | ||
---|---|---|
73 | 73 |
sub chart_picker { return _call_presenter('chart_picker', @_); } |
74 | 74 |
sub customer_vendor_picker { return _call_presenter('customer_vendor_picker', @_); } |
75 | 75 |
sub project_picker { return _call_presenter('project_picker', @_); } |
76 |
sub button_tag { return _call_presenter('button_tag', @_); } |
|
77 |
sub submit_tag { return _call_presenter('submit_tag', @_); } |
|
78 |
sub ajax_submit_tag { return _call_presenter('ajax_submit_tag', @_); } |
|
76 | 79 |
|
77 | 80 |
sub _set_id_attribute { |
78 | 81 |
my ($attributes, $name, $unique) = @_; |
... | ... | |
143 | 146 |
return $self->html_tag('a', $content, %params, href => $href); |
144 | 147 |
} |
145 | 148 |
|
146 |
sub submit_tag { |
|
147 |
my ($self, $name, $value, %attributes) = _hashify(3, @_); |
|
148 |
|
|
149 |
if ( $attributes{confirm} ) { |
|
150 |
$attributes{onclick} = 'return confirm("'. _J(delete($attributes{confirm})) .'");'; |
|
151 |
} |
|
152 |
|
|
153 |
return $self->input_tag($name, $value, %attributes, type => 'submit', class => 'submit'); |
|
154 |
} |
|
155 |
|
|
156 |
sub button_tag { |
|
157 |
my ($self, $onclick, $value, %attributes) = _hashify(3, @_); |
|
158 |
|
|
159 |
_set_id_attribute(\%attributes, $attributes{name}) if $attributes{name}; |
|
160 |
$attributes{type} ||= 'button'; |
|
161 |
|
|
162 |
$onclick = 'if (!confirm("'. _J(delete($attributes{confirm})) .'")) return false; ' . $onclick if $attributes{confirm}; |
|
163 |
|
|
164 |
return $self->html_tag('input', undef, %attributes, value => $value, onclick => $onclick); |
|
165 |
} |
|
166 |
|
|
167 |
sub ajax_submit_tag { |
|
168 |
my ($self, $url, $form_selector, $text, @slurp) = @_; |
|
169 |
|
|
170 |
$url = _J($url); |
|
171 |
$form_selector = _J($form_selector); |
|
172 |
my $onclick = qq|kivi.submit_ajax_form('${url}', '${form_selector}')|; |
|
173 |
|
|
174 |
return $self->button_tag($onclick, $text, @slurp); |
|
175 |
} |
|
176 |
|
|
177 | 149 |
sub yes_no_tag { |
178 | 150 |
my ($self, $name, $value, %attributes) = _hashify(3, @_); |
179 | 151 |
|
... | ... | |
528 | 500 |
C<$value> and with arbitrary HTML attributes from C<%attributes>. The |
529 | 501 |
tag's C<id> defaults to C<name_to_id($name)>. |
530 | 502 |
|
531 |
=item C<submit_tag $name, $value, %attributes> |
|
532 |
|
|
533 |
Creates a HTML 'input type=submit class=submit' tag named C<$name> with the |
|
534 |
value C<$value> and with arbitrary HTML attributes from C<%attributes>. The |
|
535 |
tag's C<id> defaults to C<name_to_id($name)>. |
|
536 |
|
|
537 |
If C<$attributes{confirm}> is set then a JavaScript popup dialog will |
|
538 |
be added via the C<onclick> handler asking the question given with |
|
539 |
C<$attributes{confirm}>. The request is only submitted if the user |
|
540 |
clicks the dialog's ok/yes button. |
|
541 |
|
|
542 |
=item C<ajax_submit_tag $url, $form_selector, $text, %attributes> |
|
543 |
|
|
544 |
Creates a HTML 'input type="button"' tag with a very specific onclick |
|
545 |
handler that submits the form given by the jQuery selector |
|
546 |
C<$form_selector> to the URL C<$url> (the actual JavaScript function |
|
547 |
called for that is C<kivi.submit_ajax_form()> in |
|
548 |
C<js/client_js.js>). The button's label will be C<$text>. |
|
549 |
|
|
550 |
=item C<button_tag $onclick, $text, %attributes> |
|
551 |
|
|
552 |
Creates a HTML 'input type="button"' tag with an onclick handler |
|
553 |
C<$onclick> and a value of C<$text>. The button does not have a name |
|
554 |
nor an ID by default. |
|
555 |
|
|
556 |
If C<$attributes{confirm}> is set then a JavaScript popup dialog will |
|
557 |
be prepended to the C<$onclick> handler asking the question given with |
|
558 |
C<$attributes{confirm}>. The request is only submitted if the user |
|
559 |
clicks the dialog's "ok/yes" button. |
|
560 |
|
|
561 | 503 |
=item C<textarea_tag $name, $value, %attributes> |
562 | 504 |
|
563 | 505 |
Creates a HTML 'textarea' tag named C<$name> with the content |
Auch abrufbar als: Unified diff
Presenter: button_tag, submit_tag, ajax_submit_tag von L nach SL::Presenter::Tag verschoben