Presenter-Module für Listen von Verkaufs-/Einkaufsobjekte
[kivitendo-erp.git] / SL / Presenter / CustomerVendor.pm
1 package SL::Presenter::CustomerVendor;
2
3 use strict;
4
5 use parent qw(Exporter);
6
7 use Exporter qw(import);
8 our @EXPORT = qw(customer vendor);
9
10 use Carp;
11
12 sub customer {
13   my ($self, $customer, $type, %params) = @_;
14   return _customer_vendor($self, $customer, 'customer', %params);
15 }
16
17 sub vendor {
18   my ($self, $vendor, $type, %params) = @_;
19   return _customer_vendor($self, $vendor, 'vendor', %params);
20 }
21
22 sub _customer_vendor {
23   my ($self, $cv, $type, %params) = @_;
24
25   $params{display} ||= 'inline';
26
27   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
28
29   my $text = join '', (
30     $params{no_link} ? '' : '<a href="ct.pl?action=edit&amp;db=' . $type . '&amp;id=' . $self->escape($cv->id) . '">',
31     $self->escape($cv->name),
32     $params{no_link} ? '' : '</a>',
33   );
34   return $self->escaped_text($text);
35 }
36
37 1;
38
39 __END__
40
41 =pod
42
43 =encoding utf8
44
45 =head1 NAME
46
47 SL::Presenter::CustomerVendor - Presenter module for customer and
48 vendor Rose::DB objects
49
50 =head1 SYNOPSIS
51
52   # Customers:
53   my $customer = SL::DB::Manager::Customer->get_first;
54   my $html     = SL::Presenter->get->customer($customer, display => 'inline');
55
56   # Vendors:
57   my $vendor = SL::DB::Manager::Vendor->get_first;
58   my $html   = SL::Presenter->get->vendor($customer, display => 'inline');
59
60 =head1 FUNCTIONS
61
62 =over 4
63
64 =item C<customer $object, %params>
65
66 Returns a rendered version (actually an instance of
67 L<SL::Presenter::EscapedText>) of the customer object C<$object>.
68
69 C<%params> can include:
70
71 =over 2
72
73 =item * display
74
75 Either C<inline> (the default) or C<table-cell>. At the moment both
76 representations are identical and produce the customer's name linked
77 to the corresponding 'edit' action.
78
79 =item * no_link
80
81 If falsish (the default) then the customer's name will be linked to
82 the "edit customer" dialog from the master data menu.
83
84 =back
85
86 =item C<vendor $object, %params>
87
88 Returns a rendered version (actually an instance of
89 L<SL::Presenter::EscapedText>) of the vendor object C<$object>.
90
91 C<%params> can include:
92
93 =over 2
94
95 =item * display
96
97 Either C<inline> (the default) or C<table-cell>. At the moment both
98 representations are identical and produce the vendor's name linked
99 to the corresponding 'edit' action.
100
101 =item * no_link
102
103 If falsish (the default) then the vendor's name will be linked to
104 the "edit vendor" dialog from the master data menu.
105
106 =back
107
108 =back
109
110 =head1 BUGS
111
112 Nothing here yet.
113
114 =head1 AUTHOR
115
116 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
117
118 =cut