X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FPresenter%2FTag.pm;h=770fa1c421ee91d5a6725818030fb45c2536ab2d;hb=4825c38f5775010136ae10a147dbb9bdc1194f16;hp=e1a041d090d1d506f95bf41f8b74537b1fe69a16;hpb=b5f4fac196509681df791bc5e4ee3d8c7d2a4a41;p=kivitendo-erp.git diff --git a/SL/Presenter/Tag.pm b/SL/Presenter/Tag.pm index e1a041d09..770fa1c42 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 link); 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'); @@ -244,6 +282,14 @@ sub restricted_html { return $html_restricter->process($value); } +sub link { + my ($self, $href, $content, %params) = @_; + + $href ||= '#'; + + return $self->html_tag('a', $content, %params, href => $href); +} + 1; __END__ @@ -329,6 +375,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 @@ -349,6 +425,26 @@ makes it possible to write statements like e.g. The attribute C can be used to set the text input's size. It defaults to 5. +=item C + +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=checkbox' tag named C<$name> with arbitrary +HTML attributes from C<%attributes>. The tag's C defaults to +C. The tag's C defaults to C<1>. + +If C<%attributes> contains a key C