1 package SL::Layout::Dispatcher;
6 use SL::Layout::AdminLogin;
8 use SL::Layout::Classic;
10 use SL::Layout::Javascript;
11 use SL::Layout::Material;
12 use SL::Layout::MobileLogin;
15 my ($class, %params) = @_;
17 return SL::Layout::Classic->new if $params{style} eq 'old';
18 return SL::Layout::V3->new if $params{style} eq 'v3';
19 return SL::Layout::Javascript->new if $params{style} eq 'neu';
20 return SL::Layout::Admin->new if $params{style} eq 'admin';
21 return SL::Layout::AdminLogin->new if $params{style} eq 'admin_login';
22 return SL::Layout::Login->new if $params{style} eq 'login';
23 return SL::Layout::Material->new if $params{style} eq 'mobile';
24 return SL::Layout::MobileLogin->new if $params{style} eq 'mobile_login';
25 return SL::Layout::None->new;
36 SL::Layout::Dispatcher - provides layouts by name.
40 use SL::Layout::Dispatcher;
41 $::request->layout(SL::Layout::Dispatcher->new(style => 'login'));
45 use SL::Layout::Login;
46 $::request->layout(SL::Layout::Login->new);
50 A layout in kivitendo is anything that should be included into a text/html
51 response without having each controller do it manually. This includes:
65 div containers for error handling and ajax responses
69 javascript and css includes
87 anthing that is not a text/html response
91 All of these tasks are handled by a layout object, which is stored in the
92 global L<$::request|SL::Request> object. An appropriate layout object will be
93 chosen during the login/session_restore process.
98 Every layout must be instantiated from L<SL::Layout::Base> and must implement
99 the following eight callbacks:
105 Content that must, for whatever reason, appear before the main content.
107 =item C<start_content>
109 An introcutory clause for the main content. Usually something like C<< <div
114 The corresponding end of L</start_content> like C<< </div> >>
116 =item C<post_content>
118 Any extra content that should appear after the main content in the response
119 source. Note that it is preferred to put extra content after the main content,
120 so that it gets rendered faster.
124 A list of stylesheets that should be included as a full relative web path. Will
125 be rendered into the html header.
127 =item C<stylesheets_inline>
129 A list of stylesheet snippets that need to be included in the response. Will be
130 added to the html header.
134 A list of javascripts that should be included as a full relative web path.
137 There is no guarantee where these will end up in the content. Currently they
138 will be rendered into the header, but are likely to be moved into the footer in
141 =item C<javascripts_inline>
143 A list of javascript snippets that need to be included in the response.
146 These will end up in the footer, so make sure they don't contain
147 initializations to static javascript includes that may be included earlier.
151 =head1 RUNTIME INTERFACE
153 Each layout object can add stylesheets and javascripts at runtime, as long as
154 its before the actual rendering has begun. This can be used to add special
155 javascripts only your controller needs.
159 =item C<add_stylesheets>
161 Adds the list of arguments to the list of used stylesheets.
163 These will first be searched in the theme folder for the current user, and only
164 after that be searched from the common C<css/> folder.
166 Duplicated files will be only included once.
168 Non-existing files will be pruned from the list.
170 =item C<use_stylesheet>
172 Backwards compatible alias for C<add_stylesheets>. Deprecated.
174 =item C<static_stylesheets>
176 Can be overwritten in sub-layouts to return a list of needed stylesheets. The
177 values will be resolved by the actual layout in addition to the
178 C<add_stylesheets> accumulator.
180 =item C<add_javascripts>
182 Adds the list of arguments to the list of used javascripts.
184 Duplicated files will be only included once.
186 Non-existing files will be pruned from the list.
188 =item C<use_javascript>
190 Backwards compatible alias for C<add_javascripts>. Deprecated.
193 =item C<static_javascripts>
195 Can be overwritten in sub-layouts to return a list of needed javascripts. The
196 values will be resolved by the actual layout in addition to the
197 C<add_javascripts> accumulator.
199 =item C<add_javascripts_inline>
201 Add a snippet of javascript.
203 =item C<add_stylesheets_inline>
205 Add a snippet of css.
209 If set with a selector, the layout will generate javascript to set the page
210 focus to that selector on document.ready.
220 non existing css or js includes should generate a log entry.
224 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>