|
1 |
package SL::Controller::TopQuickSearch::Project;
|
|
2 |
|
|
3 |
use strict;
|
|
4 |
use parent qw(Rose::Object);
|
|
5 |
|
|
6 |
use SL::Locale::String qw(t8);
|
|
7 |
use SL::DB::Project;
|
|
8 |
use SL::Controller::Helper::GetModels;
|
|
9 |
use SL::Controller::Base;
|
|
10 |
|
|
11 |
use Rose::Object::MakeMethods::Generic (
|
|
12 |
'scalar --get_set_init' => [ qw(models) ],
|
|
13 |
);
|
|
14 |
|
|
15 |
sub auth { 'project_edit' }
|
|
16 |
|
|
17 |
sub name { 'project' }
|
|
18 |
|
|
19 |
sub description_config { t8('Projects') }
|
|
20 |
|
|
21 |
sub description_field { t8('Projects') }
|
|
22 |
|
|
23 |
sub query_autocomplete {
|
|
24 |
my ($self) = @_;
|
|
25 |
|
|
26 |
my $objects = $self->models->get;
|
|
27 |
|
|
28 |
[
|
|
29 |
map {
|
|
30 |
value => $_->full_description,
|
|
31 |
label => $_->full_description,
|
|
32 |
id => $_->id,
|
|
33 |
}, @$objects
|
|
34 |
];
|
|
35 |
}
|
|
36 |
|
|
37 |
sub select_autocomplete {
|
|
38 |
$_[0]->redirect_to_object($::form->{id});
|
|
39 |
}
|
|
40 |
|
|
41 |
sub do_search {
|
|
42 |
my ($self) = @_;
|
|
43 |
|
|
44 |
my $objects = $self->models->get;
|
|
45 |
|
|
46 |
return !@$objects ? ()
|
|
47 |
: @$objects == 1 ? $self->redirect_to_object($objects->[0]->id)
|
|
48 |
: $self->redirect_to_search($::form->{term});
|
|
49 |
}
|
|
50 |
|
|
51 |
sub redirect_to_search {
|
|
52 |
my ($self, $term) = @_;
|
|
53 |
|
|
54 |
SL::Controller::Base->new->url_for(
|
|
55 |
controller => 'controller.pl',
|
|
56 |
action => 'Project/list',
|
|
57 |
all => $term,
|
|
58 |
);
|
|
59 |
|
|
60 |
}
|
|
61 |
|
|
62 |
sub redirect_to_object {
|
|
63 |
my ($self, $term) = @_;
|
|
64 |
SL::Controller::Base->new->url_for(
|
|
65 |
controller => 'controller.pl',
|
|
66 |
action => 'Project/edit',
|
|
67 |
id => $term,
|
|
68 |
);
|
|
69 |
}
|
|
70 |
|
|
71 |
sub init_models {
|
|
72 |
my ($self) = @_;
|
|
73 |
|
|
74 |
SL::Controller::Helper::GetModels->new(
|
|
75 |
controller => $self,
|
|
76 |
model => 'Project',
|
|
77 |
source => {
|
|
78 |
filter => {
|
|
79 |
'all:substr:multi::ilike' => $::form->{term},
|
|
80 |
},
|
|
81 |
},
|
|
82 |
sorted => {
|
|
83 |
_default => {
|
|
84 |
by => 'itime',
|
|
85 |
dir => 0,
|
|
86 |
},
|
|
87 |
itime => t8('Date'),
|
|
88 |
},
|
|
89 |
paginated => {
|
|
90 |
per_page => 10,
|
|
91 |
},
|
|
92 |
with_objects => [ qw(customer) ]
|
|
93 |
)
|
|
94 |
}
|
|
95 |
|
|
96 |
1;
|
Schnellsuche für Projekte