X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FPresenter%2FCustomerVendor.pm;h=fccfa1daf49207ac9d5c966c26cf586eac8621fd;hb=d4557a8bfab9f122ae19e91a8735e22a4b0c275b;hp=077c376c8f71a5b598878dc0f80728d55ee2c7d6;hpb=5b5dbec0272c91697acf33c4842ee9d63f041f22;p=kivitendo-erp.git
diff --git a/SL/Presenter/CustomerVendor.pm b/SL/Presenter/CustomerVendor.pm
index 077c376c8..fccfa1daf 100644
--- a/SL/Presenter/CustomerVendor.pm
+++ b/SL/Presenter/CustomerVendor.pm
@@ -5,17 +5,22 @@ use strict;
use parent qw(Exporter);
use Exporter qw(import);
-our @EXPORT = qw(customer vendor);
+our @EXPORT = qw(customer_vendor customer vendor customer_vendor_picker);
use Carp;
+sub customer_vendor {
+ my ($self, $customer_vendor, %params) = @_;
+ return _customer_vendor($self, $customer_vendor, ref($customer_vendor) eq 'SL::DB::Customer' ? 'customer' : 'vendor', %params);
+}
+
sub customer {
- my ($self, $customer, $type, %params) = @_;
+ my ($self, $customer, %params) = @_;
return _customer_vendor($self, $customer, 'customer', %params);
}
sub vendor {
- my ($self, $vendor, $type, %params) = @_;
+ my ($self, $vendor, %params) = @_;
return _customer_vendor($self, $vendor, 'vendor', %params);
}
@@ -26,14 +31,45 @@ sub _customer_vendor {
croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
+ my $callback = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
+
my $text = join '', (
- $params{no_link} ? '' : '',
+ $params{no_link} ? '' : '',
$self->escape($cv->name),
$params{no_link} ? '' : '',
);
return $self->escaped_text($text);
}
+sub customer_vendor_picker {
+ my ($self, $name, $value, %params) = @_;
+
+ croak 'Unknown "type" parameter' unless $params{type} =~ m{^(?:customer|vendor)$};
+ croak 'Unknown value class' if $value && ref($value) && (ref($value) !~ m{^SL::DB::(?:Customer|Vendor)$});
+
+ if ($value && !ref $value) {
+ my $class = $params{type} eq 'customer' ? 'SL::DB::Manager::Customer' : 'SL::DB::Manager::Vendor';
+ $value = $class->find_by(id => $value);
+ }
+
+ 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)) .
+ $self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
+
+ $::request->layout->add_javascripts('autocomplete_customer.js');
+ $::request->presenter->need_reinit_widgets($id);
+
+ $self->html_tag('span', $ret, class => 'customer_vendor_picker');
+}
+
1;
__END__
@@ -105,6 +141,14 @@ the "edit vendor" dialog from the master data menu.
=back
+=item C
+
+Returns a rendered version (actually an instance of
+L) of the customer or vendor object
+C<$object> by calling either L or L depending on
+C<$object>'s type. See the respective functions for available
+parameters.
+
=back
=head1 BUGS