Autocomplete version 1 - mehrere eingabefelder, type filter, limit
authorSven Schöling <s.schoeling@linet-services.de>
Fri, 10 Jun 2011 13:57:47 +0000 (15:57 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Mon, 10 Oct 2011 12:55:25 +0000 (14:55 +0200)
SL/Controller/Part.pm [new file with mode: 0644]
templates/webpages/part/ajax_autocomplete.html [new file with mode: 0644]

diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm
new file mode 100644 (file)
index 0000000..edcf544
--- /dev/null
@@ -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 (file)
index 0000000..749cdc1
--- /dev/null
@@ -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 %]
+]