From: Moritz Bunkus Date: Mon, 23 Jan 2017 12:18:48 +0000 (+0100) Subject: Presenter: button_tag, submit_tag, ajax_submit_tag von L nach SL::Presenter::Tag... X-Git-Tag: release-3.5.4~1667^2~7 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=dc48be1ca22433a40ee8b24d9976d067c6dab022;p=kivitendo-erp.git Presenter: button_tag, submit_tag, ajax_submit_tag von L nach SL::Presenter::Tag verschoben --- diff --git a/SL/Presenter/Tag.pm b/SL/Presenter/Tag.pm index e1a041d09..0c2dff2d4 100644 --- a/SL/Presenter/Tag.pm +++ b/SL/Presenter/Tag.pm @@ -7,7 +7,7 @@ use SL::HTML::Restrict; use parent qw(Exporter); use Exporter qw(import); -our @EXPORT = qw(html_tag input_tag hidden_tag javascript man_days_tag name_to_id select_tag checkbox_tag stringify_attributes restricted_html); +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); use Carp; @@ -30,6 +30,11 @@ sub _id { } } +sub _J { + my $string = shift; + $string =~ s/(\"|\'|\\)/\\$1/g; + return $string; +} sub stringify_attributes { my ($self, %params) = @_; @@ -219,6 +224,39 @@ sub checkbox_tag { return $code; } +sub button_tag { + my ($self, $onclick, $value, %attributes) = @_; + + _set_id_attribute(\%attributes, $attributes{name}) if $attributes{name}; + $attributes{type} ||= 'button'; + + $onclick = 'if (!confirm("'. _J(delete($attributes{confirm})) .'")) return false; ' . $onclick if $attributes{confirm}; + + return $self->html_tag('input', undef, %attributes, value => $value, onclick => $onclick); +} + +sub submit_tag { + my ($self, $name, $value, %attributes) = @_; + + _set_id_attribute(\%attributes, $attributes{name}) if $attributes{name}; + + if ( $attributes{confirm} ) { + $attributes{onclick} = 'return confirm("'. _J(delete($attributes{confirm})) .'");'; + } + + return $self->input_tag($name, $value, %attributes, type => 'submit', class => 'submit'); +} + +sub ajax_submit_tag { + my ($self, $url, $form_selector, $text, %attributes) = @_; + + $url = _J($url); + $form_selector = _J($form_selector); + my $onclick = qq|kivi.submit_ajax_form('${url}', '${form_selector}')|; + + return $self->button_tag($onclick, $text, %attributes); +} + sub javascript { my ($self, $data) = @_; return $self->html_tag('script', $data, type => 'text/javascript'); @@ -329,6 +367,36 @@ Creates a HTML 'input type=text' tag named C<$name> with the value C<$value> and with arbitrary HTML attributes from C<%attributes>. The tag's C defaults to C. +=item C + +Creates a HTML 'input type=submit class=submit' tag named C<$name> with the +value C<$value> and with arbitrary HTML attributes from C<%attributes>. The +tag's C defaults to C. + +If C<$attributes{confirm}> is set then a JavaScript popup dialog will +be added via the C handler asking the question given with +C<$attributes{confirm}>. The request is only submitted if the user +clicks the dialog's ok/yes button. + +=item C + +Creates a HTML 'input type="button"' tag with a very specific onclick +handler that submits the form given by the jQuery selector +C<$form_selector> to the URL C<$url> (the actual JavaScript function +called for that is C in +C). The button's label will be C<$text>. + +=item C + +Creates a HTML 'input type="button"' tag with an onclick handler +C<$onclick> and a value of C<$text>. The button does not have a name +nor an ID by default. + +If C<$attributes{confirm}> is set then a JavaScript popup dialog will +be prepended to the C<$onclick> handler asking the question given with +C<$attributes{confirm}>. The request is only submitted if the user +clicks the dialog's "ok/yes" button. + =item C Creates two HTML inputs: a text input for entering a number and a drop diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index bd3edda55..56dd4fbe8 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -73,6 +73,9 @@ sub part_picker { return _call_presenter('part_picker', @_); } sub chart_picker { return _call_presenter('chart_picker', @_); } sub customer_vendor_picker { return _call_presenter('customer_vendor_picker', @_); } sub project_picker { return _call_presenter('project_picker', @_); } +sub button_tag { return _call_presenter('button_tag', @_); } +sub submit_tag { return _call_presenter('submit_tag', @_); } +sub ajax_submit_tag { return _call_presenter('ajax_submit_tag', @_); } sub _set_id_attribute { my ($attributes, $name, $unique) = @_; @@ -143,37 +146,6 @@ sub link { return $self->html_tag('a', $content, %params, href => $href); } -sub submit_tag { - my ($self, $name, $value, %attributes) = _hashify(3, @_); - - if ( $attributes{confirm} ) { - $attributes{onclick} = 'return confirm("'. _J(delete($attributes{confirm})) .'");'; - } - - return $self->input_tag($name, $value, %attributes, type => 'submit', class => 'submit'); -} - -sub button_tag { - my ($self, $onclick, $value, %attributes) = _hashify(3, @_); - - _set_id_attribute(\%attributes, $attributes{name}) if $attributes{name}; - $attributes{type} ||= 'button'; - - $onclick = 'if (!confirm("'. _J(delete($attributes{confirm})) .'")) return false; ' . $onclick if $attributes{confirm}; - - return $self->html_tag('input', undef, %attributes, value => $value, onclick => $onclick); -} - -sub ajax_submit_tag { - my ($self, $url, $form_selector, $text, @slurp) = @_; - - $url = _J($url); - $form_selector = _J($form_selector); - my $onclick = qq|kivi.submit_ajax_form('${url}', '${form_selector}')|; - - return $self->button_tag($onclick, $text, @slurp); -} - sub yes_no_tag { my ($self, $name, $value, %attributes) = _hashify(3, @_); @@ -528,36 +500,6 @@ Creates a HTML 'input type=hidden' tag named C<$name> with the value C<$value> and with arbitrary HTML attributes from C<%attributes>. The tag's C defaults to C. -=item C - -Creates a HTML 'input type=submit class=submit' tag named C<$name> with the -value C<$value> and with arbitrary HTML attributes from C<%attributes>. The -tag's C defaults to C. - -If C<$attributes{confirm}> is set then a JavaScript popup dialog will -be added via the C handler asking the question given with -C<$attributes{confirm}>. The request is only submitted if the user -clicks the dialog's ok/yes button. - -=item C - -Creates a HTML 'input type="button"' tag with a very specific onclick -handler that submits the form given by the jQuery selector -C<$form_selector> to the URL C<$url> (the actual JavaScript function -called for that is C in -C). The button's label will be C<$text>. - -=item C - -Creates a HTML 'input type="button"' tag with an onclick handler -C<$onclick> and a value of C<$text>. The button does not have a name -nor an ID by default. - -If C<$attributes{confirm}> is set then a JavaScript popup dialog will -be prepended to the C<$onclick> handler asking the question given with -C<$attributes{confirm}>. The request is only submitted if the user -clicks the dialog's "ok/yes" button. - =item C Creates a HTML 'textarea' tag named C<$name> with the content