1 package SL::Presenter::Project;
5 use SL::Presenter::EscapedText qw(escape is_escaped);
6 use SL::Presenter::Tag qw(input_tag html_tag name_to_id select_tag link_tag);
8 use Exporter qw(import);
9 our @EXPORT_OK = qw(project project_picker);
14 my ($project, %params) = @_;
16 return '' unless $project;
18 $params{display} ||= 'inline';
20 croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
22 my $description = $project->full_description(style => delete $params{style});
23 my $callback = $params{callback} ?
24 '&callback=' . $::form->escape(delete $params{callback})
27 my $text = escape($description);
28 if (! delete $params{no_link}) {
29 my $href = 'controller.pl?action=Project/edit'
30 . '&id=' . escape($project->id)
32 $text = link_tag($href, $text, %params);
39 my ($name, $value, %params) = @_;
41 $value = SL::DB::Manager::Project->find_by(id => $value) if $value && !ref $value;
42 my $id = delete($params{id}) || name_to_id($name);
43 my @classes = $params{class} ? ($params{class}) : ();
44 push @classes, 'project_autocomplete';
47 my %data_params = map { $_ => delete $params{$_} } grep { defined $params{$_} } qw(customer_id active valid description_style);
49 # If there is no 'onClick' parameter, set it to 'this.select()',
50 # so that the user can type directly in the input field
51 # to search another project.
52 if (!grep { m{onclick}i } keys %params) {
53 $params{onClick} = 'this.select()';
57 input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id,
58 'data-project-picker-data' => JSON::to_json(\%data_params),
60 input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
62 $::request->layout->add_javascripts('autocomplete_project.js');
63 $::request->presenter->need_reinit_widgets($id);
65 html_tag('span', $ret, class => 'project_picker');
68 sub picker { goto &project_picker };
80 SL::Presenter::Project - Presenter module for project Rose::DB objects
84 my $project = SL::DB::Manager::Project->get_first;
85 my $html = SL::Presenter::Project->project($project, display => 'inline');
91 =item C<project $object, %params>
93 Returns a rendered version (actually an instance of
94 L<SL::Presenter::EscapedText>) of the project object C<$customer>.
96 Remaining C<%params> are passed to the function
97 C<SL::Presenter::Tag::link_tag>. It can include:
103 Either C<inline> (the default) or C<table-cell>. Is passed to the function
104 C<SL::Presenter::Tag::link_tag>.
108 Determines what exactly will be output. Can be one of the values with
109 C<both> being the default if it is missing:
113 If falsish (the default) then the description will be linked to the "edit"
118 =item C<projectnumber> (or simply C<number>)
120 Outputs only the project's number.
122 =item C<projectdescription> (or simply C<description>)
124 Outputs only the project's description.
128 Outputs the project's number followed by its description in
129 parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
130 description is already part of the project's number then it will not
137 If falsish (the default) then the project's description will be linked to
138 the "edit project" dialog from the master data menu.
150 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>