Anpassung für global eindeutige Artikelnummern
[kivitendo-erp.git] / SL / Presenter / Tag.pm
index b42d61d..e65ca77 100644 (file)
@@ -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<id> defaults to C<name_to_id($name)>.
 
+=item C<man_days_tag $name, $object, %attributes>
+
+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<Rose::DB::Object> instance using the
+L<SL::DB::Helper::AttrDuration> helper.
+
+C<$name> is supposed to be the name of the underlying column,
+e.g. C<time_estimation> for an instance of
+C<SL::DB::RequirementSpecItem>. If C<$name> has the form
+C<prefix.method> 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<size> can be used to set the text input's size. It
+defaults to 5.
+
 =item C<select_tag $name, \@collection, %attributes>
 
 Creates a HTML 'select' tag named C<$name> with the contents of one