kivitendo/SL/Controller/TopQuickSearch/Article.pm @ 68748667
2bccc0a2 | Sven Schöling | package SL::Controller::TopQuickSearch::Article;
|
||
use strict;
|
||||
use parent qw(Rose::Object);
|
||||
use SL::Locale::String qw(t8);
|
||||
use SL::DB::Part;
|
||||
use SL::Controller::Helper::GetModels;
|
||||
use SL::Controller::Base;
|
||||
use Rose::Object::MakeMethods::Generic (
|
||||
'scalar --get_set_init' => [ qw(parts models part) ],
|
||||
);
|
||||
sub auth { 'part_service_assembly_edit' }
|
||||
sub name { 'article' }
|
||||
343d3419 | Sven Schöling | sub description_config { t8('Articles') }
|
||
2bccc0a2 | Sven Schöling | |||
343d3419 | Sven Schöling | sub description_field { t8('Articles') }
|
||
2bccc0a2 | Sven Schöling | |||
sub query_autocomplete {
|
||||
my ($self) = @_;
|
||||
my $objects = $self->models->get;
|
||||
[
|
||||
map {
|
||||
value => $_->displayable_name,
|
||||
label => $_->displayable_name,
|
||||
id => $_->id,
|
||||
}, @$objects
|
||||
];
|
||||
}
|
||||
sub select_autocomplete {
|
||||
f8f23e03 | Sven Schöling | my ($self) = @_;
|
||
$self->redirect_to_part($::form->{id});
|
||||
2bccc0a2 | Sven Schöling | }
|
||
sub do_search {
|
||||
my ($self) = @_;
|
||||
my $objects = $self->models->get;
|
||||
return !@$objects ? ()
|
||||
f7027139 | Sven Schöling | : @$objects == 1 ? $self->redirect_to_part($objects->[0]->id)
|
||
: $self->redirect_to_search($::form->{term});
|
||||
2bccc0a2 | Sven Schöling | }
|
||
sub redirect_to_search {
|
||||
f7027139 | Sven Schöling | my ($self, $term) = @_;
|
||
2bccc0a2 | Sven Schöling | SL::Controller::Base->new->url_for(
|
||
f7027139 | Sven Schöling | controller => 'ic.pl',
|
||
action => 'generate_report',
|
||||
all => $term,
|
||||
aa01fd25 | Geoffrey Richardson | (searchitems => $self->part_type) x!!$self->part_type,
|
||
2bccc0a2 | Sven Schöling | );
|
||
}
|
||||
sub redirect_to_part {
|
||||
f7027139 | Sven Schöling | my ($self, $term) = @_;
|
||
2bccc0a2 | Sven Schöling | SL::Controller::Base->new->url_for(
|
||
65de6f61 | Geoffrey Richardson | controller => 'controller.pl',
|
||
action => 'Part/edit',
|
||||
7bbdbf2b | Geoffrey Richardson | 'part.id' => $term,
|
||
2bccc0a2 | Sven Schöling | );
|
||
}
|
||||
aa01fd25 | Geoffrey Richardson | sub part_type {
|
||
2bccc0a2 | Sven Schöling | ()
|
||
}
|
||||
sub init_models {
|
||||
my ($self) = @_;
|
||||
SL::Controller::Helper::GetModels->new(
|
||||
controller => $self,
|
||||
model => 'Part',
|
||||
source => {
|
||||
filter => {
|
||||
aa01fd25 | Geoffrey Richardson | (part_type => $self->part_type) x!!$self->part_type,
|
||
4cdfbd75 | Moritz Bunkus | or => [ obsolete => undef, obsolete => 0 ],
|
||
2bccc0a2 | Sven Schöling | 'all:substr:multi::ilike' => $::form->{term},
|
||
},
|
||||
},
|
||||
sorted => {
|
||||
_default => {
|
||||
by => 'partnumber',
|
||||
dir => 1,
|
||||
},
|
||||
partnumber => t8('Partnumber'),
|
||||
},
|
||||
paginated => {
|
||||
per_page => 10,
|
||||
},
|
||||
)
|
||||
}
|
||||
1;
|