Presenter->customer und ->vendor brauchen keinen $type.
[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, %params) = @_;
14   return _customer_vendor($self, $customer, 'customer', %params);
15 }
16
17 sub vendor {
18   my ($self, $vendor, %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 $callback = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
30
31   my $text = join '', (
32     $params{no_link} ? '' : '<a href="controller.pl?action=CustomerVendor/edit&amp;db=' . $type . '&amp;id=' . $self->escape($cv->id) . '">',
33     $self->escape($cv->name),
34     $params{no_link} ? '' : '</a>',
35   );
36   return $self->escaped_text($text);
37 }
38
39 1;
40
41 __END__
42
43 =pod
44
45 =encoding utf8
46
47 =head1 NAME
48
49 SL::Presenter::CustomerVendor - Presenter module for customer and
50 vendor Rose::DB objects
51
52 =head1 SYNOPSIS
53
54   # Customers:
55   my $customer = SL::DB::Manager::Customer->get_first;
56   my $html     = SL::Presenter->get->customer($customer, display => 'inline');
57
58   # Vendors:
59   my $vendor = SL::DB::Manager::Vendor->get_first;
60   my $html   = SL::Presenter->get->vendor($customer, display => 'inline');
61
62 =head1 FUNCTIONS
63
64 =over 4
65
66 =item C<customer $object, %params>
67
68 Returns a rendered version (actually an instance of
69 L<SL::Presenter::EscapedText>) of the customer object C<$object>.
70
71 C<%params> can include:
72
73 =over 2
74
75 =item * display
76
77 Either C<inline> (the default) or C<table-cell>. At the moment both
78 representations are identical and produce the customer's name linked
79 to the corresponding 'edit' action.
80
81 =item * no_link
82
83 If falsish (the default) then the customer's name will be linked to
84 the "edit customer" dialog from the master data menu.
85
86 =back
87
88 =item C<vendor $object, %params>
89
90 Returns a rendered version (actually an instance of
91 L<SL::Presenter::EscapedText>) of the vendor object C<$object>.
92
93 C<%params> can include:
94
95 =over 2
96
97 =item * display
98
99 Either C<inline> (the default) or C<table-cell>. At the moment both
100 representations are identical and produce the vendor's name linked
101 to the corresponding 'edit' action.
102
103 =item * no_link
104
105 If falsish (the default) then the vendor's name will be linked to
106 the "edit vendor" dialog from the master data menu.
107
108 =back
109
110 =back
111
112 =head1 BUGS
113
114 Nothing here yet.
115
116 =head1 AUTHOR
117
118 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
119
120 =cut