X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=SL%2FPresenter%2FCustomerVendor.pm;h=ab951720addaa3145c0d2afe6398b1a611e15336;hb=6974d60c25efcbc91f7a717baf251d6cb9d515e8;hp=4a370297040ce97f26d6bff3531eba7f51236166;hpb=e3810fbd565d14993f6b5a6fe89f0e4e27c95869;p=kivitendo-erp.git
diff --git a/SL/Presenter/CustomerVendor.pm b/SL/Presenter/CustomerVendor.pm
index 4a3702970..ab951720a 100644
--- a/SL/Presenter/CustomerVendor.pm
+++ b/SL/Presenter/CustomerVendor.pm
@@ -2,25 +2,31 @@ package SL::Presenter::CustomerVendor;
use strict;
-use parent qw(Exporter);
+use SL::Presenter::EscapedText qw(escape is_escaped);
+use SL::Presenter::Tag qw(input_tag html_tag name_to_id select_tag);
use Exporter qw(import);
-our @EXPORT = qw(customer vendor customer_vendor_picker);
+our @EXPORT_OK = qw(customer_vendor customer vendor customer_vendor_picker customer_picker vendor_picker);
use Carp;
+sub customer_vendor {
+ my ($customer_vendor, %params) = @_;
+ return _customer_vendor($customer_vendor, ref($customer_vendor) eq 'SL::DB::Customer' ? 'customer' : 'vendor', %params);
+}
+
sub customer {
- my ($self, $customer, %params) = @_;
- return _customer_vendor($self, $customer, 'customer', %params);
+ my ($customer, %params) = @_;
+ return _customer_vendor($customer, 'customer', %params);
}
sub vendor {
- my ($self, $vendor, %params) = @_;
- return _customer_vendor($self, $vendor, 'vendor', %params);
+ my ($vendor, %params) = @_;
+ return _customer_vendor($vendor, 'vendor', %params);
}
sub _customer_vendor {
- my ($self, $cv, $type, %params) = @_;
+ my ($cv, $type, %params) = @_;
$params{display} ||= 'inline';
@@ -29,41 +35,52 @@ sub _customer_vendor {
my $callback = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
my $text = join '', (
- $params{no_link} ? '' : '',
- $self->escape($cv->name),
+ $params{no_link} ? '' : '',
+ escape($cv->name),
$params{no_link} ? '' : '',
);
- return $self->escaped_text($text);
+
+ is_escaped($text);
}
sub customer_vendor_picker {
- my ($self, $name, $value, %params) = @_;
+ my ($name, $value, %params) = @_;
+
+ $params{type} //= 'customer' if 'SL::DB::Customer' eq ref $value;
+ $params{type} //= 'vendor' if 'SL::DB::Vendor' eq ref $value;
croak 'Unknown "type" parameter' unless $params{type} =~ m{^(?:customer|vendor)$};
- croak 'Unknown value class' if $value && (ref($value) !~ m{^SL::DB::(?: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 $id = delete($params{id}) || name_to_id($name);
my @classes = $params{class} ? ($params{class}) : ();
push @classes, 'customer_vendor_autocomplete';
- push @classes, 'customer-vendor-picker-fat-set-item' if $fat_set_item;
+
+ # do not use reserved html attribute 'type' for cv type
+ $params{cv_type} = delete $params{type};
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->can('name')) ? $value->name : '', id => "${id}_name", %params);
+ input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id,
+ 'data-customer-vendor-picker-data' => JSON::to_json(\%params),
+ ) .
+ input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
+ $::request->layout->add_javascripts('kivi.CustomerVendor.js');
$::request->presenter->need_reinit_widgets($id);
- $self->html_tag('span', $ret, class => 'customer_vendor_picker');
+ html_tag('span', $ret, class => 'customer_vendor_picker');
}
+sub customer_picker { my ($name, $value, @slurp) = @_; customer_vendor_picker($name, $value, @slurp, type => 'customer') }
+sub vendor_picker { my ($name, $value, @slurp) = @_; customer_vendor_picker($name, $value, @slurp, type => 'vendor') }
+sub picker { goto &customer_vendor_picker }
+
1;
__END__
@@ -81,11 +98,11 @@ vendor Rose::DB objects
# Customers:
my $customer = SL::DB::Manager::Customer->get_first;
- my $html = SL::Presenter->get->customer($customer, display => 'inline');
+ my $html = SL::Presenter::CustomerVendor::customer($customer, display => 'inline');
# Vendors:
my $vendor = SL::DB::Manager::Vendor->get_first;
- my $html = SL::Presenter->get->vendor($customer, display => 'inline');
+ my $html = SL::Presenter::Customer::Vendor::vendor($customer, display => 'inline');
=head1 FUNCTIONS
@@ -135,6 +152,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