]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Presenter/Project.pm
kivitendo 3.9.2-0.2
[mfinanz.git] / SL / Presenter / Project.pm
index 8aecdfe492d9692b1fd405c7e9c273088ba4faec..7ae4c79db91c0e5de41fb3e27a1af4d87186684f 100644 (file)
@@ -3,7 +3,7 @@ package SL::Presenter::Project;
 use strict;
 
 use SL::Presenter::EscapedText qw(escape is_escaped);
-use SL::Presenter::Tag qw(input_tag html_tag name_to_id select_tag);
+use SL::Presenter::Tag qw(input_tag html_tag name_to_id select_tag link_tag);
 
 use Exporter qw(import);
 our @EXPORT_OK = qw(project project_picker);
@@ -19,14 +19,19 @@ sub project {
 
   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
 
-  my $description = $project->full_description(style => $params{style});
-  my $callback    = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
+  my $description = $project->full_description(style => delete $params{style});
+  my $callback    = $params{callback} ?
+                      '&callback=' . $::form->escape(delete $params{callback})
+                    : '';
+
+  my $text = escape($description);
+  if (! delete $params{no_link}) {
+    my $href = 'controller.pl?action=Project/edit'
+               . '&id=' . escape($project->id)
+               . $callback;
+    $text = link_tag($href, $text, %params);
+  }
 
-  my $text = join '', (
-    $params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&amp;id=' . escape($project->id) . $callback . '">',
-    escape($description),
-    $params{no_link} ? '' : '</a>',
-  );
   is_escaped($text);
 }
 
@@ -41,6 +46,13 @@ sub project_picker {
 
   my %data_params = map { $_ => delete $params{$_}  } grep { defined $params{$_} } qw(customer_id active valid description_style);
 
+  # If there is no 'onClick' parameter, set it to 'this.select()',
+  # so that the user can type directly in the input field
+  # to search another project.
+  if (!grep { m{onclick}i } keys %params) {
+    $params{onClick} = 'this.select()';
+  }
+
   my $ret =
     input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id,
               'data-project-picker-data' => JSON::to_json(\%data_params),
@@ -81,22 +93,26 @@ SL::Presenter::Project - Presenter module for project Rose::DB objects
 Returns a rendered version (actually an instance of
 L<SL::Presenter::EscapedText>) of the project object C<$customer>.
 
-C<%params> can include:
+Remaining C<%params> are passed to the function
+C<SL::Presenter::Tag::link_tag>. It can include:
 
 =over 2
 
 =item * display
 
-Either C<inline> (the default) or C<table-cell>. At the moment both
-representations are identical and produce the project's description
-(controlled by the C<style> parameter) linked to the corresponding
-'edit' action.
+Either C<inline> (the default) or C<table-cell>. Is passed to the function
+C<SL::Presenter::Tag::link_tag>.
 
 =item * style
 
 Determines what exactly will be output. Can be one of the values with
 C<both> being the default if it is missing:
 
+=item * no_link
+
+If falsish (the default) then the description will be linked to the "edit"
+dialog.
+
 =over 2
 
 =item C<projectnumber> (or simply C<number>)