Project-Picker basierend auf Part-Picker
[kivitendo-erp.git] / SL / Presenter / Project.pm
1 package SL::Presenter::Project;
2
3 use strict;
4
5 use parent qw(Exporter);
6
7 use Exporter qw(import);
8 our @EXPORT = qw(project project_picker);
9
10 use Carp;
11
12 sub project {
13   my ($self, $project, %params) = @_;
14
15   return '' unless $project;
16
17   $params{display} ||= 'inline';
18
19   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
20
21   my $description = $project->full_description(style => $params{style});
22   my $callback    = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
23
24   my $text = join '', (
25     $params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&amp;id=' . $self->escape($project->id) . $callback . '">',
26     $self->escape($description),
27     $params{no_link} ? '' : '</a>',
28   );
29   return $self->escaped_text($text);
30 }
31
32 sub project_picker {
33   my ($self, $name, $value, %params) = @_;
34
35   $value      = SL::DB::Manager::Project->find_by(id => $value) if $value && !ref $value;
36   my $id      = delete($params{id}) || $self->name_to_id($name);
37   my @classes = $params{class} ? ($params{class}) : ();
38   push @classes, 'project_autocomplete';
39
40   my $ret =
41     $self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id) .
42     join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(customer_id)) .
43     $self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
44
45   $::request->layout->add_javascripts('autocomplete_project.js');
46   $::request->presenter->need_reinit_widgets($id);
47
48   $self->html_tag('span', $ret, class => 'project_picker');
49 }
50
51 1;
52
53 __END__
54
55 =pod
56
57 =encoding utf8
58
59 =head1 NAME
60
61 SL::Presenter::Project - Presenter module for project Rose::DB objects
62
63 =head1 SYNOPSIS
64
65   my $project = SL::DB::Manager::Project->get_first;
66   my $html    = SL::Presenter->get->project($project, display => 'inline');
67
68 =head1 FUNCTIONS
69
70 =over 4
71
72 =item C<project $object, %params>
73
74 Returns a rendered version (actually an instance of
75 L<SL::Presenter::EscapedText>) of the project object C<$customer>.
76
77 C<%params> can include:
78
79 =over 2
80
81 =item * display
82
83 Either C<inline> (the default) or C<table-cell>. At the moment both
84 representations are identical and produce the project's description
85 (controlled by the C<style> parameter) linked to the corresponding
86 'edit' action.
87
88 =item * style
89
90 Determines what exactly will be output. Can be one of the values with
91 C<both> being the default if it is missing:
92
93 =over 2
94
95 =item C<projectnumber> (or simply C<number>)
96
97 Outputs only the project's number.
98
99 =item C<projectdescription> (or simply C<description>)
100
101 Outputs only the project's description.
102
103 =item C<both>
104
105 Outputs the project's number followed by its description in
106 parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
107 description is already part of the project's number then it will not
108 be appended.
109
110 =back
111
112 =item * no_link
113
114 If falsish (the default) then the project's description will be linked to
115 the "edit project" dialog from the master data menu.
116
117 =back
118
119 =back
120
121 =head1 BUGS
122
123 Nothing here yet.
124
125 =head1 AUTHOR
126
127 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
128
129 =cut