1 package SL::Controller::Part;
4 use parent qw(SL::Controller::Base);
8 use SL::Controller::Helper::GetModels;
9 use SL::Controller::Helper::Filtered;
10 use SL::Controller::Helper::Sorted;
11 use SL::Controller::Helper::Paginated;
12 use SL::Controller::Helper::Filtered;
13 use SL::Locale::String qw(t8);
16 use Rose::Object::MakeMethods::Generic (
17 'scalar --get_set_init' => [ qw(parts) ],
21 __PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') });
23 __PACKAGE__->make_filtered(
24 ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
25 LAUNDER_TO => 'filter',
27 __PACKAGE__->make_paginated(
28 ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
31 __PACKAGE__->make_sorted(
32 ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
34 DEFAULT_BY => 'partnumber',
37 partnumber => t8('Partnumber'),
40 sub action_ajax_autocomplete {
41 my ($self, %params) = @_;
43 my $value = $::form->{column} || 'description';
45 # if someone types something, and hits enter, assume he entered the full name.
46 # if something matches, treat that as sole match
47 # unfortunately get_models can't do more than one per package atm, so we d it
48 # the oldfashioned way.
49 if ($::form->{prefer_exact}) {
51 if (1 == scalar @{ $exact_matches = SL::DB::Manager::Part->get_all(
54 SL::DB::Manager::Part->type_filter($::form->{filter}{type}),
56 description => { ilike => $::form->{filter}{'all:substr::ilike'} },
57 partnumber => { ilike => $::form->{filter}{'all:substr::ilike'} },
62 $self->parts($exact_matches);
69 label => $_->long_description,
71 partnumber => $_->partnumber,
72 description => $_->description,
75 } @{ $self->parts }; # neato: if exact match triggers we don't even need the init_parts
77 $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
80 sub action_test_page {
81 $::request->{layout}->add_javascripts('autocomplete_part.js');
83 $_[0]->render('part/test_page');
86 sub action_part_picker_search {
87 $_[0]->render('part/part_picker_search', { layout => 0 }, parts => $_[0]->parts);
90 sub action_part_picker_result {
91 $_[0]->render('part/_part_picker_result', { layout => 0 });
95 $_[0]->get_models(with_objects => [ qw(unit_obj) ]);