From 3c6e133b2e272859f39c7541c8b10eb567831989 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 11 Mar 2013 12:20:44 +0100 Subject: [PATCH] Tag-Presenter: man_days_tag()-Funktion --- SL/Presenter/Tag.pm | 42 +++++++++++++++++++++++++++++++++++++++++- locale/de/all | 2 ++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/SL/Presenter/Tag.pm b/SL/Presenter/Tag.pm index b42d61dbb..6fefd12be 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) = @_; @@ -225,6 +245,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 diff --git a/locale/de/all b/locale/de/all index ded08693b..5e12166c9 100644 --- a/locale/de/all +++ b/locale/de/all @@ -1162,6 +1162,7 @@ $self->{texts} = { 'Long Dates' => 'Lange Monatsnamen', 'Long Description' => 'Langtext', 'MAILED' => 'Gesendet', + 'MD' => 'PT', 'Main Preferences' => 'Grundeinstellungen', 'Main sorting' => 'Hauptsortierung', 'Make' => 'Lieferant', @@ -2416,6 +2417,7 @@ $self->{texts} = { 'found' => 'Gefunden', 'from (time)' => 'von', 'general_ledger_list' => 'buchungsjournal', + 'h' => 'h', 'history' => 'Historie', 'history search engine' => 'Historien Suchmaschine', 'inactive' => 'inaktiv', -- 2.20.1