1 package SL::Layout::Dispatcher;
6 use SL::Layout::AdminLogin;
8 use SL::Layout::Classic;
10 use SL::Layout::Javascript;
13 my ($class, %params) = @_;
15 return SL::Layout::Classic->new if $params{style} eq 'old';
16 return SL::Layout::V3->new if $params{style} eq 'v3';
17 return SL::Layout::Javascript->new if $params{style} eq 'neu';
18 return SL::Layout::Admin->new if $params{style} eq 'admin';
19 return SL::Layout::AdminLogin->new if $params{style} eq 'admin_login';
20 return SL::Layout::Login->new if $params{style} eq 'login';
21 return SL::Layout::None->new;
32 SL::Layout::Dispatcher - provides layouts by name.
36 use SL::Layout::Dispatcher;
37 $::request->layout(SL::Layout::Dispatcher->new(style => 'login'));
41 use SL::Layout::Login;
42 $::request->layout(SL::Layout::Login->new);
46 A layout in kivitendo is anything that should be included into a text/html
47 response without having each controller do it manually. This includes:
61 div containers for error handling and ajax responses
65 javascript and css includes
83 anthing that is not a text/html response
87 All of these tasks are handled by a layout object, which is stored in the
88 global L<$::request|SL::Request> object. An appropriate layout object will be
89 chosen during the login/session_restore process.
94 Every layout must be instantiated from L<SL::Layout::Base> and must implement
95 the following eight callbacks:
101 Content that must, for whatever reason, appear before the main content.
103 =item C<start_content>
105 An introcutory clause for the main content. Usually something like C<< <div
110 The corresponding end of L</start_content> like C<< </div> >>
112 =item C<post_content>
114 Any extra content that should appear after the main content in the response
115 source. Note that it is preferred to put extra content after the main content,
116 so that it gets rendered faster.
120 A list of stylesheets that should be included as a full relative web path. Will
121 be rendered into the html header.
123 =item C<stylesheets_inline>
125 A list of stylesheet snippets that need to be included in the response. Will be
126 added to the html header.
130 A list of javascripts that should be included as a full relative web path.
133 There is no guarantee where these will end up in the content. Currently they
134 will be rendered into the header, but are likely to be moved into the footer in
137 =item C<javascripts_inline>
139 A list of javascript snippets that need to be included in the response.
142 These will end up in the footer, so make sure they don't contain
143 initializations to static javascript includes that may be included earlier.
147 =head1 RUNTIME INTERFACE
149 Each layout object can add stylesheets and javascripts at runtime, as long as
150 its before the actual rendering has begun. This can be used to add special
151 javascripts only your controller needs.
155 =item C<add_stylesheets>
157 Adds the list of arguments to the list of used stylesheets.
159 These will first be searched in the theme folder for the current user, and only
160 after that be searched from the common C<css/> folder.
162 Duplicated files will be only included once.
164 Non-existing files will be pruned from the list.
166 =item C<use_stylesheet>
168 Backwards compatible alias for C<add_stylesheets>. Deprecated.
170 =item C<add_javascripts>
172 Adds the list of arguments to the list of used javascripts.
174 Duplicated files will be only included once.
176 Non-existing files will be pruned from the list.
178 =item C<use_javascript>
180 Backwards compatible alias for C<add_javascripts>. Deprecated.
182 =item C<add_javascripts_inline>
184 Add a snippet of javascript.
186 =item C<add_stylesheets_inline>
188 Add a snippet of css.
192 If set with a selector, the layout will generate javascript to set the page
193 focus to that selector on document.ready.
203 non existing css or js includes should generate a log entry.
207 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>