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::SalesQuotation',
 
  21   'SL::Controller::TopQuickSearch::SalesOrder',
 
  22   'SL::Controller::TopQuickSearch::RequestForQuotation',
 
  23   'SL::Controller::TopQuickSearch::PurchaseOrder',
 
  24   'SL::Controller::TopQuickSearch::GLTransaction',
 
  25   'SL::Controller::TopQuickSearch::Customer',
 
  26   'SL::Controller::TopQuickSearch::Vendor',
 
  30 sub action_query_autocomplete {
 
  33   my $hashes = $self->module->query_autocomplete;
 
  35   $self->render(\ SL::JSON::to_json($hashes), { layout => 0, type => 'json', process => 0 });
 
  38 sub action_select_autocomplete {
 
  41   my $redirect_url = $self->module->select_autocomplete;
 
  43   $self->js->redirect_to($redirect_url)->render;
 
  46 sub action_do_search {
 
  49   my $redirect_url = $self->module->do_search;
 
  52     $self->js->redirect_to($redirect_url)
 
  58 sub available_modules {
 
  61   $self->require_modules;
 
  63   map { $_->new } @available_modules;
 
  67   my %enabled_names = map {
 
  69   } @{ $::instance_conf->get_quick_search_modules };
 
  72     $enabled_names{$_->name}
 
  73   } $_[0]->available_modules
 
  78     $::auth->assert($_->auth, 1)
 
  79   } $_[0]->enabled_modules
 
  85   $self->require_modules;
 
  87   die 'Need module' unless $::form->{module};
 
  89   die 'Unknown module ' . $::form->{module} unless my $class = $modules_by_name{$::form->{module}};
 
  91   $::auth->assert($class->auth);
 
  97   SL::ClientJS->new(controller => $_[0])
 
 100 sub require_modules {
 
 103   if (!$self->{__modules_required}) {
 
 104     for my $class (@available_modules) {
 
 105       eval "require $class" or die $@;
 
 106       $modules_by_name{ $class->name } = $class;
 
 108     $self->{__modules_required} = 1;
 
 120 SL::Controller::TopQuickSearch - Framework for pluggable quicksearch fields in the layout top header.
 
 124   use SL::Controller::TopQuickSearch;
 
 125   my $search = SL::Controller::TopQuickSearch->new;
 
 126   $::request->layout->add_javascripts('kivi.QuickSearch.js');
 
 129   [%- FOREACH module = search.enabled_modules %]
 
 130   <input type='text' id='top-search-[% module.name %]'>
 
 135 This controller provides abstraction for different search plugins, and ensures
 
 136 that all follow a common useability scheme.
 
 138 Modules should be configurable per user, but currently are not. Disabling
 
 139 modules can be done by removing them from available_modules or in client_config.
 
 141 =head1 BEHAVIOUR REQUIREMENTS
 
 147 A single text input field with the html5 placeholder containing a small
 
 148 description of the target will be rendered from the plugin information.
 
 152 On typing, the autocompletion must be enabled.
 
 156 On C<Enter>, the search should redirect to an appropriate listing of matching
 
 159 If only one item matches the result, the plugin should instead redirect
 
 160 directly to the matched item.
 
 164 Search terms should accept the broadest possible matching, and if possible with
 
 169 In case nothing is found, a visual indicator should be given, but no actual
 
 170 redirect should occur.
 
 174 Each search must check rights and must not present a backdoor into data that
 
 175 the user should not see.
 
 179 By design the search must not try to guess C<exact matches>.
 
 185 The full interface is described in L<SL::Controller::TopQuickSeach::Base>
 
 197 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>