1 package SL::Controller::Part;
4 use parent qw(SL::Controller::Base);
8 use SL::Controller::Helper::GetModels;
9 use SL::Locale::String qw(t8);
12 use Rose::Object::MakeMethods::Generic (
13 'scalar --get_set_init' => [ qw(parts models) ],
17 __PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') });
19 sub action_ajax_autocomplete {
20 my ($self, %params) = @_;
22 my $value = $::form->{column} || 'description';
24 # if someone types something, and hits enter, assume he entered the full name.
25 # if something matches, treat that as sole match
26 # unfortunately get_models can't do more than one per package atm, so we d it
27 # the oldfashioned way.
28 if ($::form->{prefer_exact}) {
30 if (1 == scalar @{ $exact_matches = SL::DB::Manager::Part->get_all(
33 SL::DB::Manager::Part->type_filter($::form->{filter}{type}),
35 description => { ilike => $::form->{filter}{'all:substr::ilike'} },
36 partnumber => { ilike => $::form->{filter}{'all:substr::ilike'} },
41 $self->parts($exact_matches);
48 label => $_->long_description,
50 partnumber => $_->partnumber,
51 description => $_->description,
54 } @{ $self->parts }; # neato: if exact match triggers we don't even need the init_parts
56 $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
59 sub action_test_page {
60 $::request->{layout}->add_javascripts('autocomplete_part.js');
62 $_[0]->render('part/test_page');
65 sub action_part_picker_search {
66 $_[0]->render('part/part_picker_search', { layout => 0 }, parts => $_[0]->parts);
69 sub action_part_picker_result {
70 $_[0]->render('part/_part_picker_result', { layout => 0 });
80 SL::Controller::Helper::GetModels->new(
87 partnumber => t8('Partnumber'),
89 with_objects => [ qw(unit_obj) ],