X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FPresenter%2FTag.pm;h=e1a041d090d1d506f95bf41f8b74537b1fe69a16;hb=f1c3810f3ed25965f708ec96ac806bcac1b14bb7;hp=7ee8531d4278f6dd5036080714ba85d4fcf238c3;hpb=976b1ddfe4464dcb6d626484ec64b5a80260f12c;p=kivitendo-erp.git diff --git a/SL/Presenter/Tag.pm b/SL/Presenter/Tag.pm index 7ee8531d4..e1a041d09 100644 --- a/SL/Presenter/Tag.pm +++ b/SL/Presenter/Tag.pm @@ -7,13 +7,13 @@ use SL::HTML::Restrict; use parent qw(Exporter); use Exporter qw(import); -our @EXPORT = qw(html_tag input_tag man_days_tag name_to_id select_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 stringify_attributes restricted_html); use Carp; my %_valueless_attributes = map { $_ => 1 } qw( checked compact declare defer disabled ismap multiple noresize noshade nowrap - readonly selected + readonly selected hidden ); sub _call_on { @@ -62,6 +62,11 @@ sub input_tag { return $self->html_tag('input', undef, %attributes, name => $name, value => $value); } +sub hidden_tag { + my ($self, $name, $value, %attributes) = @_; + return $self->input_tag($name, $value, %attributes, type => 'hidden'); +} + sub man_days_tag { my ($self, $name, $object, %attributes) = @_; @@ -189,6 +194,36 @@ sub select_tag { return $self->html_tag('select', $code, %attributes, name => $name); } +sub checkbox_tag { + my ($self, $name, %attributes) = @_; + + _set_id_attribute(\%attributes, $name); + + $attributes{value} = 1 unless defined $attributes{value}; + my $label = delete $attributes{label}; + my $checkall = delete $attributes{checkall}; + my $for_submit = delete $attributes{for_submit}; + + if ($attributes{checked}) { + $attributes{checked} = 'checked'; + } else { + delete $attributes{checked}; + } + + my $code = ''; + $code .= $self->hidden_tag($name, 0, %attributes, id => $attributes{id} . '_hidden') if $for_submit; + $code .= $self->html_tag('input', undef, %attributes, name => $name, type => 'checkbox'); + $code .= $self->html_tag('label', $label, for => $attributes{id}) if $label; + $code .= $self->javascript(qq|\$('#$attributes{id}').checkall('$checkall');|) if $checkall; + + return $code; +} + +sub javascript { + my ($self, $data) = @_; + return $self->html_tag('script', $data, type => 'text/javascript'); +} + sub _set_id_attribute { my ($attributes, $name, $unique) = @_;