X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FPresenter%2FTag.pm;h=e65ca7722ef27abed26c402f62f22e58d6d2a242;hb=4252995520f5020735ca33d3fbbe63d9f6d4ef0b;hp=b42d61dbb6ffc8a89febc76f48236ee0edc147a5;hpb=d093f01c664ae2afaaed1a5b41e65ebc0ac154f3;p=kivitendo-erp.git diff --git a/SL/Presenter/Tag.pm b/SL/Presenter/Tag.pm index b42d61dbb..e65ca7722 100644 --- a/SL/Presenter/Tag.pm +++ b/SL/Presenter/Tag.pm @@ -5,7 +5,7 @@ use strict; use parent qw(Exporter); use Exporter qw(import); -our @EXPORT = qw(html_tag input_tag name_to_id select_tag stringify_attributes); +our @EXPORT = qw(html_tag input_tag man_days_tag name_to_id select_tag stringify_attributes); use Carp; @@ -14,6 +14,12 @@ my %_valueless_attributes = map { $_ => 1 } qw( readonly selected ); +sub _call_on { + my ($object, $method, @params) = @_; + return $object->$method(@params); +} + + sub stringify_attributes { my ($self, %params) = @_; @@ -45,6 +51,20 @@ sub input_tag { return $self->html_tag('input', undef, %attributes, name => $name, value => $value); } +sub man_days_tag { + my ($self, $name, $object, %attributes) = @_; + + my $size = delete($attributes{size}) || 5; + my $method = $name; + $method =~ s/^.*\.//; + + my $time_selection = $self->input_tag( "${name}_as_man_days_string", _call_on($object, "${method}_as_man_days_string"), %attributes, size => $size); + my $unit_selection = $self->select_tag("${name}_as_man_days_unit", [[ 'h', $::locale->text('h') ], [ 'man_day', $::locale->text('MD') ]], + %attributes, default => _call_on($object, "${method}_as_man_days_unit")); + + return $time_selection . $unit_selection; +} + sub name_to_id { my ($self, $name) = @_; @@ -88,10 +108,6 @@ sub select_tag { delete($attributes{default}); - - my @all_options; - push @all_options, [undef, $empty_title || ''] if $with_empty; - my $normalize_entry = sub { my ($type, $entry, $sub, $key) = @_; @@ -141,13 +157,14 @@ sub select_tag { return join '', map { $self->html_tag('option', $self->escape($_->[1]), value => $_->[0], selected => $_->[2]) } @options; }; - my $code; + my $code = ''; + $code .= $self->html_tag('option', $self->escape($empty_title || ''), value => '') if $with_empty; if (!$with_optgroups) { - $code = $list_to_code->($collection); + $code .= $list_to_code->($collection); } else { - $code = join '', map { + $code .= join '', map { my ($optgroup_title, $sub_collection) = @{ $_ }; $self->html_tag('optgroup', $list_to_code->($sub_collection), label => $optgroup_title) } @{ $collection }; @@ -225,6 +242,26 @@ 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 two HTML inputs: a text input for entering a number and a drop +down box for chosing the unit (either 'man days' or 'hours'). + +C<$object> must be a L instance using the +L helper. + +C<$name> is supposed to be the name of the underlying column, +e.g. C for an instance of +C. If C<$name> has the form +C then the full C<$name> is used for the input's base +names while the methods called on C<$object> are only the suffix. This +makes it possible to write statements like e.g. + + [% P.man_days_tag("requirement_spec_item.time_estimation", SELF.item) %] + +The attribute C can be used to set the text input's size. It +defaults to 5. + =item C Creates a HTML 'select' tag named C<$name> with the contents of one