From 2bccc0a27d0c6917ab219aeb60efcbc9ae043205 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 21 Mar 2016 18:47:26 +0100 Subject: [PATCH] TopQuickSearch: Alle Part Varianten for free --- SL/Controller/TopQuickSearch.pm | 3 + SL/Controller/TopQuickSearch/Article.pm | 97 ++++++++++++++++++++++++ SL/Controller/TopQuickSearch/Assembly.pm | 81 +------------------- SL/Controller/TopQuickSearch/Part.pm | 16 ++++ SL/Controller/TopQuickSearch/Service.pm | 16 ++++ 5 files changed, 134 insertions(+), 79 deletions(-) create mode 100644 SL/Controller/TopQuickSearch/Article.pm create mode 100644 SL/Controller/TopQuickSearch/Part.pm create mode 100644 SL/Controller/TopQuickSearch/Service.pm diff --git a/SL/Controller/TopQuickSearch.pm b/SL/Controller/TopQuickSearch.pm index 63d9b5b8b..1134b6a14 100644 --- a/SL/Controller/TopQuickSearch.pm +++ b/SL/Controller/TopQuickSearch.pm @@ -12,6 +12,9 @@ use Rose::Object::MakeMethods::Generic ( ); my @available_modules = qw( + SL::Controller::TopQuickSearch::Article + SL::Controller::TopQuickSearch::Part + SL::Controller::TopQuickSearch::Service SL::Controller::TopQuickSearch::Assembly SL::Controller::TopQuickSearch::Contact SL::Controller::TopQuickSearch::GLTransaction diff --git a/SL/Controller/TopQuickSearch/Article.pm b/SL/Controller/TopQuickSearch/Article.pm new file mode 100644 index 000000000..83ccedf00 --- /dev/null +++ b/SL/Controller/TopQuickSearch/Article.pm @@ -0,0 +1,97 @@ +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' } + +sub description_config { t8('Article') } + +sub description_field { t8('Article') } + +sub query_autocomplete { + my ($self) = @_; + + my $objects = $self->models->get; + + [ + map { + value => $_->displayable_name, + label => $_->displayable_name, + id => $_->id, + }, @$objects + ]; +} + +sub select_autocomplete { + redirect_to_part($::form->{id}); +} + +sub do_search { + my ($self) = @_; + + my $objects = $self->models->get; + + return !@$objects ? () + : @$objects == 1 ? redirect_to_part($objects->[0]->id) + : redirect_to_search($::form->{term}); +} + +sub redirect_to_search { + SL::Controller::Base->new->url_for( + controller => 'ic.pl', + action => 'generate_report', + searchitems => 'assembly', + all => $_[0], + ); +} + +sub redirect_to_part { + SL::Controller::Base->new->url_for( + controller => 'ic.pl', + action => 'edit', + id => $_[0], + ); +} + +sub type { + () +} + +sub init_models { + my ($self) = @_; + + SL::Controller::Helper::GetModels->new( + controller => $self, + model => 'Part', + source => { + filter => { + ($self->type), + 'all:substr:multi::ilike' => $::form->{term}, + }, + }, + sorted => { + _default => { + by => 'partnumber', + dir => 1, + }, + partnumber => t8('Partnumber'), + }, + paginated => { + per_page => 10, + }, + ) +} + +1; diff --git a/SL/Controller/TopQuickSearch/Assembly.pm b/SL/Controller/TopQuickSearch/Assembly.pm index 7622e66c0..bb7eccea1 100644 --- a/SL/Controller/TopQuickSearch/Assembly.pm +++ b/SL/Controller/TopQuickSearch/Assembly.pm @@ -1,18 +1,9 @@ package SL::Controller::TopQuickSearch::Assembly; use strict; -use parent qw(Rose::Object); +use parent qw(SL::Controller::TopQuickSearch::Article); 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 { 'assembly' } @@ -20,74 +11,6 @@ sub description_config { t8('Assemblies') } sub description_field { t8('Assemblies') } -sub query_autocomplete { - my ($self) = @_; - - my $objects = $self->models->get; - - [ - map { - value => $_->displayable_name, - label => $_->displayable_name, - id => $_->id, - }, @$objects - ]; -} - -sub select_autocomplete { - redirect_to_part($::form->{id}); -} - -sub do_search { - my ($self) = @_; - - my $objects = $self->models->get; - - return !@$objects ? () - : @$objects == 1 ? redirect_to_part($objects->[0]->id) - : redirect_to_search($::form->{term}); -} - -sub redirect_to_search { - SL::Controller::Base->new->url_for( - controller => 'ic.pl', - action => 'generate_report', - searchitems => 'assembly', - all => $_[0], - ); -} - -sub redirect_to_part { - SL::Controller::Base->new->url_for( - controller => 'ic.pl', - action => 'edit', - id => $_[0], - ); -} - -sub init_models { - my ($self) = @_; - - SL::Controller::Helper::GetModels->new( - controller => $self, - model => 'Part', - source => { - filter => { - type => 'assembly', - 'all:substr:multi::ilike' => $::form->{term}, - }, - }, - sorted => { - _default => { - by => 'partnumber', - dir => 1, - }, - partnumber => t8('Partnumber'), - }, - paginated => { - per_page => 10, - }, - ) -} +sub type { type => 'assembly' } 1; diff --git a/SL/Controller/TopQuickSearch/Part.pm b/SL/Controller/TopQuickSearch/Part.pm new file mode 100644 index 000000000..d6b01e021 --- /dev/null +++ b/SL/Controller/TopQuickSearch/Part.pm @@ -0,0 +1,16 @@ +package SL::Controller::TopQuickSearch::Part; + +use strict; +use parent qw(SL::Controller::TopQuickSearch::Article); + +use SL::Locale::String qw(t8); + +sub name { 'part' } + +sub description_config { t8('Parts') } + +sub description_field { t8('Parts') } + +sub type { type => 'part' } + +1; diff --git a/SL/Controller/TopQuickSearch/Service.pm b/SL/Controller/TopQuickSearch/Service.pm new file mode 100644 index 000000000..f1f1507e6 --- /dev/null +++ b/SL/Controller/TopQuickSearch/Service.pm @@ -0,0 +1,16 @@ +package SL::Controller::TopQuickSearch::Service; + +use strict; +use parent qw(SL::Controller::TopQuickSearch::Article); + +use SL::Locale::String qw(t8); + +sub name { 'service' } + +sub description_config { t8('Services') } + +sub description_field { t8('Services') } + +sub type { type => 'service' } + +1; -- 2.20.1