1 package SL::Controller::TopQuickSearch;
 
   4 use parent qw(SL::Controller::Base);
 
   8 use SL::Locale::String qw(t8);
 
   9 use SL::Helper::UserPreferences;
 
  11 use Rose::Object::MakeMethods::Generic (
 
  12  'scalar --get_set_init' => [ qw(module js) ],
 
  15 my @available_modules = (
 
  16   'SL::Controller::TopQuickSearch::Article',
 
  17   'SL::Controller::TopQuickSearch::Part',
 
  18   'SL::Controller::TopQuickSearch::Service',
 
  19   'SL::Controller::TopQuickSearch::Assembly',
 
  20   'SL::Controller::TopQuickSearch::Assortment',
 
  21   'SL::Controller::TopQuickSearch::Contact',
 
  22   'SL::Controller::TopQuickSearch::SalesQuotation',
 
  23   'SL::Controller::TopQuickSearch::SalesOrder',
 
  24   'SL::Controller::TopQuickSearch::SalesDeliveryOrder',
 
  25   'SL::Controller::TopQuickSearch::RequestForQuotation',
 
  26   'SL::Controller::TopQuickSearch::PurchaseOrder',
 
  27   'SL::Controller::TopQuickSearch::PurchaseDeliveryOrder',
 
  28   'SL::Controller::TopQuickSearch::GLTransaction',
 
  29   'SL::Controller::TopQuickSearch::Customer',
 
  30   'SL::Controller::TopQuickSearch::Vendor',
 
  31   'SL::Controller::TopQuickSearch::PhoneNumber',
 
  35 sub action_query_autocomplete {
 
  38   my $hashes = $self->module->query_autocomplete;
 
  40   $self->render(\ SL::JSON::to_json($hashes), { layout => 0, type => 'json', process => 0 });
 
  43 sub action_select_autocomplete {
 
  46   my $redirect_url = $self->module->select_autocomplete;
 
  48   $self->js->redirect_to($redirect_url)->render;
 
  51 sub action_do_search {
 
  54   my $redirect_url = $self->module->do_search;
 
  57     $self->js->redirect_to($redirect_url)
 
  63 sub available_modules {
 
  66   $self->require_modules;
 
  68   map { $_->new } @available_modules;
 
  72   my $user_prefs = SL::Helper::UserPreferences->new(
 
  73     namespace         => 'TopQuickSearch',
 
  76   my @quick_search_modules;
 
  77   if (my $prefs_val = $user_prefs->get('quick_search_modules')) {
 
  78     @quick_search_modules = split ',', $prefs_val;
 
  80     @quick_search_modules = @{ $::instance_conf->get_quick_search_modules };
 
  83   my %enabled_names = map { $_ => 1 } @quick_search_modules;
 
  86     $enabled_names{$_->name}
 
  87   } $_[0]->available_modules
 
  92     !$_->auth || $::auth->assert($_->auth, 1)
 
  93   } $_[0]->enabled_modules
 
  99   $self->require_modules;
 
 101   die 'Need module' unless $::form->{module};
 
 103   die 'Unknown module ' . $::form->{module} unless my $class = $modules_by_name{$::form->{module}};
 
 105   $::auth->assert($class->auth) if $class->auth;
 
 111   SL::ClientJS->new(controller => $_[0])
 
 114 sub require_modules {
 
 117   if (!$self->{__modules_required}) {
 
 118     for my $class (@available_modules) {
 
 119       eval "require $class" or die $@;
 
 120       $modules_by_name{ $class->name } = $class;
 
 122     $self->{__modules_required} = 1;
 
 134 SL::Controller::TopQuickSearch - Framework for pluggable quicksearch fields in the layout top header.
 
 138   use SL::Controller::TopQuickSearch;
 
 139   my $search = SL::Controller::TopQuickSearch->new;
 
 140   $::request->layout->add_javascripts('kivi.QuickSearch.js');
 
 143   [%- FOREACH module = search.enabled_modules %]
 
 144   <input type='text' id='top-search-[% module.name %]'>
 
 149 This controller provides abstraction for different search plugins, and ensures
 
 150 that all follow a common useability scheme.
 
 152 Modules should be configurable per user, but currently are not. Disabling
 
 153 modules can be done by removing them from available_modules or in client_config.
 
 155 =head1 BEHAVIOUR REQUIREMENTS
 
 161 A single text input field with the html5 placeholder containing a small
 
 162 description of the target will be rendered from the plugin information.
 
 166 On typing, the autocompletion must be enabled.
 
 170 On C<Enter>, the search should redirect to an appropriate listing of matching
 
 173 If only one item matches the result, the plugin should instead redirect
 
 174 directly to the matched item.
 
 178 Search terms should accept the broadest possible matching, and if possible with
 
 183 In case nothing is found, a visual indicator should be given, but no actual
 
 184 redirect should occur.
 
 188 Each search must check rights and must not present a backdoor into data that
 
 189 the user should not see.
 
 193 By design the search must not try to guess C<exact matches>.
 
 199 The full interface is described in L<SL::Controller::TopQuickSeach::Base>
 
 211 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>