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::Contact',
20 'SL::Controller::TopQuickSearch::GLTransaction',
24 sub action_query_autocomplete {
27 my $hashes = $self->module->query_autocomplete;
29 $self->render(\ SL::JSON::to_json($hashes), { layout => 0, type => 'json', process => 0 });
32 sub action_select_autocomplete {
35 my $redirect_url = $self->module->select_autocomplete;
37 $self->js->redirect_to($redirect_url)->render;
40 sub action_do_search {
43 my $redirect_url = $self->module->do_search;
46 $self->js->redirect_to($redirect_url)
52 sub available_modules {
55 $self->require_modules;
57 map { $_->new } @available_modules;
62 $::auth->assert($_->auth, 1)
63 } $_[0]->available_modules
69 $self->require_modules;
71 die 'Need module' unless $::form->{module};
73 die 'Unknown module ' . $::form->{module} unless my $class = $modules_by_name{$::form->{module}};
75 $::auth->assert($class->auth);
81 SL::ClientJS->new(controller => $_[0])
87 if (!$self->{__modules_required}) {
88 for my $class (@available_modules) {
89 eval "require $class" or die $@;
90 $modules_by_name{ $class->name } = $class;
92 $self->{__modules_required} = 1;
104 SL::Controller::TopQuickSearch - Framework for pluggable quicksearch fields in the layout top header.
108 use SL::Controller::TopQuickSearch;
109 my $search = SL::Controller::TopQuickSearch->new;
112 [%- FOREACH module = search.available_modules %]
113 <input type='text' id='top-search-[% module.name %]'>
118 This controller provides abstraction for different search plugins, and ensures
119 that all follow a common useability scheme.
121 Modules should be configurable, but currently are not. Diabling modules can be
122 done by removing them from available_modules.
124 =head1 BEHAVIOUR REQUIREMENTS
130 A single text input field with the html5 placeholder containing a small
131 description of the target will be rendered from the plugin information.
135 On typing, the autocompletion must be enabled.
139 On C<Enter>, the search should redirect to an appropriate listing of matching
142 If only one item matches the result, the plugin should instead redirect
143 directly to the matched item.
147 Search terms should accept the broadest possible matching, and if possible with
152 In case nothing is found, a visual indicator should be given, but no actual
153 redirect should occur.
157 Each search must check rights and must not present a backdoor into data that
158 the user should not see.
164 Plugins need to provide:
167 - localized description for config
168 - localized description for textfield
169 - autocomplete callback
172 the frontend will only generate urls of the forms:
173 action=TopQuickSearch/autocomplete&module=<module>&term=<term>
174 action=TopQuickSearch/search&module=<module>&term=<term>
178 - filter available searches with auth
179 - toggling with cofiguration doesn't work yet
187 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>