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);
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&id=' . escape($project->id) . $callback . '">',
- escape($description),
- $params{no_link} ? '' : '</a>',
- );
is_escaped($text);
}
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),
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>)