kivitendo/SL/Presenter/CustomerVendor.pm @ 79b7fc43
5b5dbec0 | Moritz Bunkus | package SL::Presenter::CustomerVendor;
|
||
use strict;
|
||||
use parent qw(Exporter);
|
||||
use Exporter qw(import);
|
||||
f16c5520 | Sven Schöling | our @EXPORT = qw(customer vendor customer_vendor_picker);
|
||
5b5dbec0 | Moritz Bunkus | |||
use Carp;
|
||||
sub customer {
|
||||
2309ac25 | Sven Schöling | my ($self, $customer, %params) = @_;
|
||
5b5dbec0 | Moritz Bunkus | return _customer_vendor($self, $customer, 'customer', %params);
|
||
}
|
||||
sub vendor {
|
||||
2309ac25 | Sven Schöling | my ($self, $vendor, %params) = @_;
|
||
5b5dbec0 | Moritz Bunkus | return _customer_vendor($self, $vendor, 'vendor', %params);
|
||
}
|
||||
sub _customer_vendor {
|
||||
my ($self, $cv, $type, %params) = @_;
|
||||
$params{display} ||= 'inline';
|
||||
croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
|
||||
b2e1809f | Moritz Bunkus | my $callback = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
|
||
5b5dbec0 | Moritz Bunkus | my $text = join '', (
|
||
e03993be | Thomas Heck | $params{no_link} ? '' : '<a href="controller.pl?action=CustomerVendor/edit&db=' . $type . '&id=' . $self->escape($cv->id) . '">',
|
||
5b5dbec0 | Moritz Bunkus | $self->escape($cv->name),
|
||
$params{no_link} ? '' : '</a>',
|
||||
);
|
||||
return $self->escaped_text($text);
|
||||
}
|
||||
f16c5520 | Sven Schöling | sub customer_vendor_picker {
|
||
my ($self, $name, $value, %params) = @_;
|
||||
3b01b816 | Moritz Bunkus | croak 'Unknown "type" parameter' unless $params{type} =~ m{^(?:customer|vendor)$};
|
||
273b5e04 | Moritz Bunkus | croak 'Unknown value class' if $value && ref($value) && (ref($value) !~ m{^SL::DB::(?:Customer|Vendor)$});
|
||
3b01b816 | Moritz Bunkus | |||
if ($value && !ref $value) {
|
||||
my $class = $params{type} eq 'customer' ? 'SL::DB::Manager::Customer' : 'SL::DB::Manager::Vendor';
|
||||
$value = $class->find_by(id => $value);
|
||||
}
|
||||
f16c5520 | Sven Schöling | my $id = delete($params{id}) || $self->name_to_id($name);
|
||
my $fat_set_item = delete $params{fat_set_item};
|
||||
my @classes = $params{class} ? ($params{class}) : ();
|
||||
push @classes, 'customer_vendor_autocomplete';
|
||||
push @classes, 'customer-vendor-picker-fat-set-item' if $fat_set_item;
|
||||
my $ret =
|
||||
$self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id) .
|
||||
join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(type)) .
|
||||
7bc44f0f | Geoffrey Richardson | $self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
|
||
f16c5520 | Sven Schöling | |||
0e92b99c | Geoffrey Richardson | $::request->layout->add_javascripts('autocomplete_customer.js');
|
||
f16c5520 | Sven Schöling | $::request->presenter->need_reinit_widgets($id);
|
||
$self->html_tag('span', $ret, class => 'customer_vendor_picker');
|
||||
}
|
||||
5b5dbec0 | Moritz Bunkus | 1;
|
||
__END__
|
||||
=pod
|
||||
=encoding utf8
|
||||
=head1 NAME
|
||||
SL::Presenter::CustomerVendor - Presenter module for customer and
|
||||
vendor Rose::DB objects
|
||||
=head1 SYNOPSIS
|
||||
# Customers:
|
||||
my $customer = SL::DB::Manager::Customer->get_first;
|
||||
my $html = SL::Presenter->get->customer($customer, display => 'inline');
|
||||
# Vendors:
|
||||
my $vendor = SL::DB::Manager::Vendor->get_first;
|
||||
my $html = SL::Presenter->get->vendor($customer, display => 'inline');
|
||||
=head1 FUNCTIONS
|
||||
=over 4
|
||||
=item C<customer $object, %params>
|
||||
Returns a rendered version (actually an instance of
|
||||
L<SL::Presenter::EscapedText>) of the customer object C<$object>.
|
||||
C<%params> 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 customer's name linked
|
||||
to the corresponding 'edit' action.
|
||||
=item * no_link
|
||||
If falsish (the default) then the customer's name will be linked to
|
||||
the "edit customer" dialog from the master data menu.
|
||||
=back
|
||||
=item C<vendor $object, %params>
|
||||
Returns a rendered version (actually an instance of
|
||||
L<SL::Presenter::EscapedText>) of the vendor object C<$object>.
|
||||
C<%params> 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 vendor's name linked
|
||||
to the corresponding 'edit' action.
|
||||
=item * no_link
|
||||
If falsish (the default) then the vendor's name will be linked to
|
||||
the "edit vendor" dialog from the master data menu.
|
||||
=back
|
||||
=back
|
||||
=head1 BUGS
|
||||
Nothing here yet.
|
||||
=head1 AUTHOR
|
||||
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
|
||||
=cut
|