From cb3a2467f28049de15810f7ddf1b04632639e530 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 11 Oct 2011 14:58:25 +0200 Subject: [PATCH] customer_picker testpage ist zu Dokumentationszwecken noch dabei, aber nicht mehr durch action erreichbar. --- SL/Controller/Customer.pm | 27 +++++++++++++ SL/Form.pm | 4 +- SL/Template/Plugin/L.pm | 34 ++++++++++++++++ templates/webpages/ct/ajax_autocomplete2.html | 11 +++++ templates/webpages/ct/testpage.html | 40 +++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 SL/Controller/Customer.pm create mode 100644 templates/webpages/ct/ajax_autocomplete2.html create mode 100644 templates/webpages/ct/testpage.html diff --git a/SL/Controller/Customer.pm b/SL/Controller/Customer.pm new file mode 100644 index 000000000..4358080fe --- /dev/null +++ b/SL/Controller/Customer.pm @@ -0,0 +1,27 @@ +package SL::Controller::Customer; + +use strict; +use parent qw(SL::Controller::Base); + +use SL::DB::Customer; + +# safety +__PACKAGE__->run_before(sub { $::auth->assert('customer_vendor_edit') }); + +sub action_ajax_autocomplete { + my ($self, %params) = @_; + + my $limit = $::form->{limit} || 20; + my $type = $::form->{type} || {}; + my $query = { ilike => "%$::form->{term}%" }; + my @filter; + push @filter, ($::form->{column}) + ? ($::form->{column} => $query) + : (or => [ customernumber => $query, name => $query ]); + + $self->{customers} = SL::DB::Manager::Customer->get_all(query => [ @filter ], limit => $limit); + $self->{value} = $::form->{column} || 'name'; + + $self->render('ct/ajax_autocomplete2', { no_layout => 1 }); +} + diff --git a/SL/Form.pm b/SL/Form.pm index a23bb4337..b21f94c71 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -701,7 +701,9 @@ sub header { '', '', '', - ''; + '', + '', + ''; push @header, $self->{javascript} if $self->{javascript}; push @header, map { $_->show_javascript } @{ $self->{AJAX} || [] }; push @header, "" if $self->{fokus}; diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 0ed2a8784..476b60a70 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -291,6 +291,40 @@ sub date_tag { ) : ''); } +sub customer_picker { + my ($self, $name, $value, %params) = @_; + my $name_e = _H($name); + + $self->hidden_tag($name, (ref $value && $value->can('id')) ? $value->id : '') . + $self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params) . + $self->javascript(< + +

Pick a customer

+id: [% L.input_tag('customer_id', '') %] +nr: [% L.input_tag('customer_customernumber', '') %] +desc: [% L.input_tag('customer_name', '') %] + + + -- 2.20.1