From 7abae2f3a934a3147b20ec216ab89fbdad3b8522 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 10 Jun 2011 15:57:47 +0200 Subject: [PATCH] Autocomplete version 1 - mehrere eingabefelder, type filter, limit --- SL/Controller/Part.pm | 35 +++++++++++++++++++ .../webpages/part/ajax_autocomplete.html | 12 +++++++ 2 files changed, 47 insertions(+) create mode 100644 SL/Controller/Part.pm create mode 100644 templates/webpages/part/ajax_autocomplete.html diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm new file mode 100644 index 000000000..edcf544b6 --- /dev/null +++ b/SL/Controller/Part.pm @@ -0,0 +1,35 @@ +package SL::Controller::Part; + +use strict; +use parent qw(SL::Controller::Base); + +use SL::DB::Part; + +# safety +__PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') }); + +sub action_part_picker_testpage { + my ($self, %params) = @_; + $self->render('part/testpage'); +} + +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, SL::DB::Manager::Part->type_filter($type); + push @filter, ($::form->{column}) + ? ($::form->{column} => $query) + : (or => [ partnumber => $query, description => $query ]); + + $self->{parts} = SL::DB::Manager::Part->get_all(query => [ @filter ], limit => $limit); + $self->{value} = $::form->{column} || 'description'; + + $self->render('part/ajax_autocomplete', { no_layout => 1 }); +} + + +1; diff --git a/templates/webpages/part/ajax_autocomplete.html b/templates/webpages/part/ajax_autocomplete.html new file mode 100644 index 000000000..749cdc1a9 --- /dev/null +++ b/templates/webpages/part/ajax_autocomplete.html @@ -0,0 +1,12 @@ +[%- USE HTML %][% USE JSON %][ +[%- FOREACH part = SELF.parts %] + { + "label": [% JSON.json(part.partnumber _ " " _ part.description) %], + "value": [% part.${SELF.value}.json %], + "id": [% part.id.json %], + "partnumber": [% part.partnumber.json %], + "description": [% part.description.json %], + "type": [% part.type.json %] + }[% ',' UNLESS loop.last %] +[%- END %] +] -- 2.20.1