1 package SL::Controller::TopQuickSearch;
4 use parent qw(SL::Controller::Base);
8 use SL::Locale::String qw(t8);
10 use Rose::Object::MakeMethods::Generic (
11 'scalar --get_set_init' => [ qw(module js) ],
14 my @available_modules = (
15 'SL::Controller::TopQuickSearch::Article',
16 'SL::Controller::TopQuickSearch::Part',
17 'SL::Controller::TopQuickSearch::Service',
18 'SL::Controller::TopQuickSearch::Assembly',
19 'SL::Controller::TopQuickSearch::Assortment',
20 'SL::Controller::TopQuickSearch::Contact',
21 'SL::Controller::TopQuickSearch::SalesQuotation',
22 'SL::Controller::TopQuickSearch::SalesOrder',
23 'SL::Controller::TopQuickSearch::RequestForQuotation',
24 'SL::Controller::TopQuickSearch::PurchaseOrder',
25 'SL::Controller::TopQuickSearch::GLTransaction',
26 'SL::Controller::TopQuickSearch::Customer',
27 'SL::Controller::TopQuickSearch::Vendor',
31 sub action_query_autocomplete {
34 my $hashes = $self->module->query_autocomplete;
36 $self->render(\ SL::JSON::to_json($hashes), { layout => 0, type => 'json', process => 0 });
39 sub action_select_autocomplete {
42 my $redirect_url = $self->module->select_autocomplete;
44 $self->js->redirect_to($redirect_url)->render;
47 sub action_do_search {
50 my $redirect_url = $self->module->do_search;
53 $self->js->redirect_to($redirect_url)
59 sub available_modules {
62 $self->require_modules;
64 map { $_->new } @available_modules;
68 my %enabled_names = map {
70 } @{ $::instance_conf->get_quick_search_modules };
73 $enabled_names{$_->name}
74 } $_[0]->available_modules
79 $::auth->assert($_->auth, 1)
80 } $_[0]->enabled_modules
86 $self->require_modules;
88 die 'Need module' unless $::form->{module};
90 die 'Unknown module ' . $::form->{module} unless my $class = $modules_by_name{$::form->{module}};
92 $::auth->assert($class->auth);
98 SL::ClientJS->new(controller => $_[0])
101 sub require_modules {
104 if (!$self->{__modules_required}) {
105 for my $class (@available_modules) {
106 eval "require $class" or die $@;
107 $modules_by_name{ $class->name } = $class;
109 $self->{__modules_required} = 1;
121 SL::Controller::TopQuickSearch - Framework for pluggable quicksearch fields in the layout top header.
125 use SL::Controller::TopQuickSearch;
126 my $search = SL::Controller::TopQuickSearch->new;
127 $::request->layout->add_javascripts('kivi.QuickSearch.js');
130 [%- FOREACH module = search.enabled_modules %]
131 <input type='text' id='top-search-[% module.name %]'>
136 This controller provides abstraction for different search plugins, and ensures
137 that all follow a common useability scheme.
139 Modules should be configurable per user, but currently are not. Disabling
140 modules can be done by removing them from available_modules or in client_config.
142 =head1 BEHAVIOUR REQUIREMENTS
148 A single text input field with the html5 placeholder containing a small
149 description of the target will be rendered from the plugin information.
153 On typing, the autocompletion must be enabled.
157 On C<Enter>, the search should redirect to an appropriate listing of matching
160 If only one item matches the result, the plugin should instead redirect
161 directly to the matched item.
165 Search terms should accept the broadest possible matching, and if possible with
170 In case nothing is found, a visual indicator should be given, but no actual
171 redirect should occur.
175 Each search must check rights and must not present a backdoor into data that
176 the user should not see.
180 By design the search must not try to guess C<exact matches>.
186 The full interface is described in L<SL::Controller::TopQuickSeach::Base>
198 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>