From: Sven Schöling Date: Fri, 10 Jun 2011 13:57:47 +0000 (+0200) Subject: Autocomplete version 1 - mehrere eingabefelder, type filter, limit X-Git-Tag: release-2.7.0beta1~249 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7abae2f3a934a3147b20ec216ab89fbdad3b8522;p=kivitendo-erp.git Autocomplete version 1 - mehrere eingabefelder, type filter, limit --- 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 %] +]