Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7abae2f3

Von Sven Schöling vor etwa 13 Jahren hinzugefügt

  • ID 7abae2f3a934a3147b20ec216ab89fbdad3b8522
  • Vorgänger 60009b97
  • Nachfolger 7fa5f43b

Autocomplete version 1 - mehrere eingabefelder, type filter, limit

Unterschiede anzeigen:

SL/Controller/Part.pm
1
package SL::Controller::Part;
2

  
3
use strict;
4
use parent qw(SL::Controller::Base);
5

  
6
use SL::DB::Part;
7

  
8
# safety
9
__PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') });
10

  
11
sub action_part_picker_testpage {
12
  my ($self, %params) = @_;
13
  $self->render('part/testpage');
14
}
15

  
16
sub action_ajax_autocomplete {
17
  my ($self, %params) = @_;
18

  
19
  my $limit  = $::form->{limit}  || 20;
20
  my $type   = $::form->{type} || {};
21
  my $query  = { ilike => "%$::form->{term}%" };
22
  my @filter;
23
  push @filter, SL::DB::Manager::Part->type_filter($type);
24
  push @filter, ($::form->{column})
25
    ? ($::form->{column} => $query)
26
    : (or => [ partnumber => $query, description => $query ]);
27

  
28
  $self->{parts} = SL::DB::Manager::Part->get_all(query => [ @filter ], limit => $limit);
29
  $self->{value} = $::form->{column} || 'description';
30

  
31
  $self->render('part/ajax_autocomplete', { no_layout => 1 });
32
}
33

  
34

  
35
1;
templates/webpages/part/ajax_autocomplete.html
1
[%- USE HTML %][%  USE JSON %][
2
[%- FOREACH part = SELF.parts %]
3
 {
4
   "label": [% JSON.json(part.partnumber _ " " _ part.description) %],
5
   "value": [% part.${SELF.value}.json %],
6
   "id": [% part.id.json %],
7
   "partnumber": [% part.partnumber.json %],
8
   "description": [% part.description.json %],
9
   "type": [% part.type.json %]
10
  }[% ',' UNLESS loop.last %]
11
[%- END %]
12
]

Auch abrufbar als: Unified diff