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') },
18 except => [ qw(ajax_autocomplete part_picker_search part_picker_result) ]);
20 sub action_ajax_autocomplete {
21 my ($self, %params) = @_;
23 my $value = $::form->{column} || 'description';
25 # if someone types something, and hits enter, assume he entered the full name.
26 # if something matches, treat that as sole match
27 # unfortunately get_models can't do more than one per package atm, so we d it
28 # the oldfashioned way.
29 if ($::form->{prefer_exact}) {
31 if (1 == scalar @{ $exact_matches = SL::DB::Manager::Part->get_all(
34 SL::DB::Manager::Part->type_filter($::form->{filter}{type}),
36 description => { ilike => $::form->{filter}{'all:substr::ilike'} },
37 partnumber => { ilike => $::form->{filter}{'all:substr::ilike'} },
42 $self->parts($exact_matches);
49 label => $_->long_description,
51 partnumber => $_->partnumber,
52 description => $_->description,
56 } @{ $self->parts }; # neato: if exact match triggers we don't even need the init_parts
58 $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
61 sub action_test_page {
62 $::request->{layout}->add_javascripts('autocomplete_part.js');
64 $_[0]->render('part/test_page');
67 sub action_part_picker_search {
68 $_[0]->render('part/part_picker_search', { layout => 0 }, parts => $_[0]->parts);
71 sub action_part_picker_result {
72 $_[0]->render('part/_part_picker_result', { layout => 0 });
82 SL::Controller::Helper::GetModels->new(
89 partnumber => t8('Partnumber'),
91 with_objects => [ qw(unit_obj) ],