1 package SL::Layout::Dispatcher;
 
   7 use SL::Layout::Classic;
 
   9 use SL::Layout::Javascript;
 
  12   my ($class, %params) = @_;
 
  14   return SL::Layout::Classic->new    if $params{style} eq 'old';
 
  15   return SL::Layout::V3->new         if $params{style} eq 'v3';
 
  16   return SL::Layout::Javascript->new if $params{style} eq 'neu';
 
  17   return SL::Layout::Admin->new      if $params{style} eq 'admin';
 
  18   return SL::Layout::Login->new      if $params{style} eq 'login';
 
  19   return SL::Layout::None->new;
 
  30 SL::Layout::Dispatcher - provides layouts by name.
 
  34   use SL::Layout::Dispatcher;
 
  35   $::request->layout(SL::Layout::Dispatcher->new(style => 'login'));
 
  39   use SL::Layout::Login;
 
  40   $::request->layout(SL::Layout::Login->new);
 
  44 A layout in kivitendo is anything that should be included into a text/html
 
  45 response without having each controller do it manually. This includes:
 
  59 div containers for error handling and ajax responses
 
  63 javascript and css includes
 
  81 anthing that is not a text/html response
 
  85 All of these tasks are handled by a layout object, which is stored in the
 
  86 global L<$::request|SL::Request> object. An appropriate layout object will be
 
  87 chosen during the login/session_restore process.
 
  92 Every layout must be instantiated from L<SL::Layout::Base> and must implement
 
  93 the following eight callbacks:
 
  99 Content that must, for whatever reason, appear before the main content.
 
 101 =item C<start_content>
 
 103 An introcutory clause for the main content. Usually something like C<< <div
 
 108 The corresponding end of L</start_content> like C<< </div> >>
 
 110 =item C<post_content>
 
 112 Any extra content that should appear after the main content in the response
 
 113 source. Note that it is preferred to put extra content after the main content,
 
 114 so that it gets rendered faster.
 
 118 A list of stylesheets that should be included as a full relative web path. Will
 
 119 be rendered into the html header.
 
 121 =item C<stylesheets_inline>
 
 123 A list of stylesheet snippets that need to be included in the response. Will be
 
 124 added to the html header.
 
 128 A list of javascripts that should be included as a full relative web path.
 
 131 There is no guarantee where these will end up in the content. Currently they
 
 132 will be rendered into the header, but are likely to be moved into the footer in
 
 135 =item C<javascripts_inline>
 
 137 A list of javascript snippets that need to be included in the response.
 
 140 These will end up in the footer, so make sure they don't contain
 
 141 initializations to static javascript includes that may be included earlier.
 
 145 =head1 RUNTIME INTERFACE
 
 147 Each layout object can add stylesheets and javascripts at runtime, as long as
 
 148 its before the actual rendering has begun. This can be used to add special
 
 149 javascripts only your controller needs.
 
 153 =item C<add_stylesheets>
 
 155 Adds the list of arguments to the list of used stylesheets.
 
 157 These will first be searched in the theme folder for the current user, and only
 
 158 after that be searched from the common C<css/> folder.
 
 160 Duplicated files will be only included once.
 
 162 Non-existing files will be pruned from the list.
 
 164 =item C<use_stylesheet>
 
 166 Backwards compatible alias for C<add_stylesheets>. Deprecated.
 
 168 =item C<add_javascripts>
 
 170 Adds the list of arguments to the list of used javascripts.
 
 172 Duplicated files will be only included once.
 
 174 Non-existing files will be pruned from the list.
 
 176 =item C<use_javascript>
 
 178 Backwards compatible alias for C<add_javascripts>. Deprecated.
 
 180 =item C<add_javascripts_inline>
 
 182 Add a snippet of javascript.
 
 184 =item C<add_stylesheets_inline>
 
 186 Add a snippet of css.
 
 190 If set with a selector, the layout will generate javascript to set the page
 
 191 focus to that selector on document.ready.
 
 201 non existing css or js includes should generate a log entry.
 
 205 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>