Revision fac8417d
Von Moritz Bunkus vor mehr als 9 Jahren hinzugefügt
SL/Controller/Project.pm | ||
---|---|---|
23 | 23 |
use SL::Locale::String; |
24 | 24 |
|
25 | 25 |
use Data::Dumper; |
26 |
use JSON; |
|
27 |
use Rose::DB::Object::Helpers qw(as_tree); |
|
26 | 28 |
|
27 | 29 |
use Rose::Object::MakeMethods::Generic |
28 | 30 |
( |
29 | 31 |
scalar => [ qw(project linked_records) ], |
30 |
'scalar --get_set_init' => [ qw(models customers project_types project_statuses) ], |
|
32 |
'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects) ],
|
|
31 | 33 |
); |
32 | 34 |
|
33 |
__PACKAGE__->run_before('check_auth'); |
|
34 |
__PACKAGE__->run_before('load_project', only => [ qw(edit update destroy) ]);
|
|
35 |
__PACKAGE__->run_before('check_auth', except => [ qw(ajax_autocomplete) ]);
|
|
36 |
__PACKAGE__->run_before('load_project', only => [ qw(edit update destroy) ]);
|
|
35 | 37 |
|
36 | 38 |
# |
37 | 39 |
# actions |
... | ... | |
102 | 104 |
$self->redirect_to(action => 'search'); |
103 | 105 |
} |
104 | 106 |
|
107 |
sub action_ajax_autocomplete { |
|
108 |
my ($self, %params) = @_; |
|
109 |
|
|
110 |
$::form->{filter}{'all:substr:multi::ilike'} =~ s{[\(\)]+}{}g; |
|
111 |
|
|
112 |
# if someone types something, and hits enter, assume he entered the full name. |
|
113 |
# if something matches, treat that as sole match |
|
114 |
# unfortunately get_models can't do more than one per package atm, so we d it |
|
115 |
# the oldfashioned way. |
|
116 |
if ($::form->{prefer_exact}) { |
|
117 |
my $exact_matches; |
|
118 |
if (1 == scalar @{ $exact_matches = SL::DB::Manager::Project->get_all( |
|
119 |
query => [ |
|
120 |
obsolete => 0, |
|
121 |
SL::DB::Manager::Project->type_filter($::form->{filter}{type}), |
|
122 |
or => [ |
|
123 |
description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, |
|
124 |
projectnumber => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, |
|
125 |
] |
|
126 |
], |
|
127 |
limit => 2, |
|
128 |
) }) { |
|
129 |
$self->projects($exact_matches); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
$::form->{sort_by} = 'customer_and_description'; |
|
134 |
|
|
135 |
my @hashes = map { |
|
136 |
+{ |
|
137 |
value => $_->full_description(style => 'full'), |
|
138 |
label => $_->full_description(style => 'full'), |
|
139 |
id => $_->id, |
|
140 |
projectnumber => $_->projectnumber, |
|
141 |
description => $_->description, |
|
142 |
cvars => { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $_->cvars_by_config } }, |
|
143 |
} |
|
144 |
} @{ $self->projects }; # neato: if exact match triggers we don't even need the init_projects |
|
145 |
|
|
146 |
$self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 }); |
|
147 |
} |
|
148 |
|
|
149 |
sub action_test_page { |
|
150 |
$_[0]->render('project/test_page'); |
|
151 |
} |
|
152 |
|
|
105 | 153 |
# |
106 | 154 |
# filters |
107 | 155 |
# |
... | ... | |
117 | 165 |
sub init_project_statuses { SL::DB::Manager::ProjectStatus->get_all_sorted } |
118 | 166 |
sub init_project_types { SL::DB::Manager::ProjectType->get_all_sorted } |
119 | 167 |
|
168 |
sub init_projects { |
|
169 |
if ($::form->{no_paginate}) { |
|
170 |
$_[0]->models->disable_plugin('paginated'); |
|
171 |
} |
|
172 |
|
|
173 |
$_[0]->models->get; |
|
174 |
} |
|
175 |
|
|
120 | 176 |
sub init_customers { |
121 | 177 |
my ($self) = @_; |
122 | 178 |
my @customer_id = $self->project && $self->project->customer_id ? (id => $self->project->customer_id) : (); |
... | ... | |
251 | 307 |
projectnumber => t8('Project Number'), |
252 | 308 |
project_type => t8('Project Type'), |
253 | 309 |
project_status => t8('Project Status'), |
310 |
customer_and_description => 1, |
|
254 | 311 |
}, |
255 | 312 |
with_objects => [ 'customer', 'project_status', 'project_type' ], |
256 | 313 |
); |
Auch abrufbar als: Unified diff
Project-Picker basierend auf Part-Picker