Revision 7a646681
Von Sven Schöling vor mehr als 11 Jahren hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
11 | 11 |
use SL::Controller::Helper::Paginated; |
12 | 12 |
use SL::Controller::Helper::Filtered; |
13 | 13 |
use SL::Locale::String qw(t8); |
14 |
use SL::JSON; |
|
14 | 15 |
|
15 | 16 |
use Rose::Object::MakeMethods::Generic ( |
16 | 17 |
'scalar --get_set_init' => [ qw(parts) ], |
... | ... | |
20 | 21 |
__PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') }); |
21 | 22 |
|
22 | 23 |
__PACKAGE__->make_filtered( |
23 |
ONLY => [ qw(part_picker_search part_picker_result) ], |
|
24 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
|
|
24 | 25 |
LAUNDER_TO => 'filter', |
25 | 26 |
); |
26 | 27 |
__PACKAGE__->make_paginated( |
27 |
ONLY => [ qw(part_picker_search part_picker_result) ], |
|
28 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
|
|
28 | 29 |
); |
29 | 30 |
|
30 | 31 |
__PACKAGE__->make_sorted( |
31 |
ONLY => [ qw(part_picker_search part_picker_result) ], |
|
32 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
|
|
32 | 33 |
|
33 | 34 |
DEFAULT_BY => 'partnumber', |
34 | 35 |
DEFAULT_DIR => 1, |
... | ... | |
39 | 40 |
sub action_ajax_autocomplete { |
40 | 41 |
my ($self, %params) = @_; |
41 | 42 |
|
42 |
my $limit = $::form->{limit} || 20; |
|
43 |
my $type = $::form->{type} || {}; |
|
44 |
my $query = { ilike => "%$::form->{term}%" }; |
|
45 |
my @filter; |
|
46 |
push @filter, SL::DB::Manager::Part->type_filter($type); |
|
47 |
push @filter, ($::form->{column}) |
|
48 |
? ($::form->{column} => $query) |
|
49 |
: (or => [ partnumber => $query, description => $query ]); |
|
50 |
|
|
51 |
$self->{parts} = SL::DB::Manager::Part->get_all(query => [ @filter ], limit => $limit); |
|
52 |
$self->{value} = $::form->{column} || 'description'; |
|
43 |
my $value = $::form->{column} || 'description'; |
|
53 | 44 |
|
54 | 45 |
# if someone types something, and hits enter, assume he entered the full name. |
55 | 46 |
# if something matches, treat that as sole match |
56 | 47 |
if ($::form->{prefer_exact}) { |
57 |
for my $part (@{ $self->{parts} }) { |
|
58 |
if ( lc $part->description eq lc $::form->{term} |
|
59 |
|| lc $part->partnumber eq lc $::form->{term}) { |
|
60 |
$self->{parts} = [ $part ]; |
|
61 |
last; |
|
62 |
} |
|
63 |
} |
|
48 |
# TODO! |
|
64 | 49 |
} |
65 | 50 |
|
66 |
$self->render('part/ajax_autocomplete', { layout => 0, type => 'json' }); |
|
51 |
my @hashes = map { |
|
52 |
+{ |
|
53 |
value => $_->$value, |
|
54 |
label => $_->long_description, |
|
55 |
id => $_->id, |
|
56 |
partnumber => $_->partnumber, |
|
57 |
description => $_->description, |
|
58 |
type => $_->type, |
|
59 |
} |
|
60 |
} @{ $self->parts }; |
|
61 |
|
|
62 |
$self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 }); |
|
67 | 63 |
} |
68 | 64 |
|
69 | 65 |
sub action_test_page { |
Auch abrufbar als: Unified diff
ajax_autocomplete umgestellt auf get_models und inline JSON (20% schneller als template)