X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLayout%2FBase.pm;h=c64a99ab06d3860e0969845e9a43c144aa59dec0;hb=78d19e27983335bbf6aae17a47799722c9e4b74c;hp=813db731555e779c3669956e37bbf34f896e5e5b;hpb=3b7f1516e724caf810293c52645b7d29fae3ef13;p=kivitendo-erp.git diff --git a/SL/Layout/Base.pm b/SL/Layout/Base.pm index 813db7315..c64a99ab0 100644 --- a/SL/Layout/Base.pm +++ b/SL/Layout/Base.pm @@ -38,27 +38,37 @@ sub init_sublayouts_by_name { {} } +sub webpages_path { + "templates/webpages"; +} + sub get { $_[0]->sub_layouts; return grep { $_ } ($_[0]->sub_layouts_by_name->{$_[1]}); } sub init_auto_reload_resources_param { - return sprintf('?rand=%d-%d-%d', Time::HiRes::gettimeofday(), int(rand 1000000000000)) if $::lx_office_conf{debug}->{auto_reload_resources}; + if ($::lx_office_conf{debug}->{auto_reload_resources}) { + return sprintf('?rand=%d-%d-%d', Time::HiRes::gettimeofday(), int(rand 1000000000000)); + } - my $git_dir = SL::System::Process::exe_dir() . '/.git'; + if ($::lx_office_conf{debug}{git_commit_reload_resources}) { + my $git_dir = SL::System::Process::exe_dir() . '/.git'; - return '' unless -d $git_dir; + return '' unless -d $git_dir; - my $content = eval { scalar(read_file($git_dir . '/HEAD')) }; + my $content = eval { scalar(read_file($git_dir . '/HEAD')) }; - return '' unless ($content // '') =~ m{\Aref: ([^\r\n]+)}; + return '' unless ($content // '') =~ m{\Aref: ([^\r\n]+)}; - $content = eval { scalar(read_file($git_dir . '/' . $1)) }; + $content = eval { scalar(read_file($git_dir . '/' . $1)) }; - return '' unless ($content // '') =~ m{\A([0-9a-fA-F]+)}; + return '' unless ($content // '') =~ m{\A([0-9a-fA-F]+)}; - return '?rand=' . $1; + return '?rand=' . $1; + } + + return ''; } ########################################## @@ -97,9 +107,12 @@ sub init_sub_layouts_by_name { +{} } ######################################### -# Interface +# Stylesheets ######################################## +# override in sub layouts +sub static_stylesheets {} + sub add_stylesheets { &use_stylesheet; } @@ -107,7 +120,7 @@ sub add_stylesheets { sub use_stylesheet { my $self = shift; push @{ $self->{stylesheets} ||= [] }, @_ if @_; - @{ $self->{stylesheets} ||= [] }; + (map { $_->use_stylesheet } $self->sub_layouts), $self->static_stylesheets, @{ $self->{stylesheets} ||= [] }; } sub stylesheets { @@ -115,7 +128,7 @@ sub stylesheets { my $css_path = $self->get_stylesheet_for_user; return uniq grep { $_ } map { $self->_find_stylesheet($_, $css_path) } - $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts; + $self->use_stylesheet; } sub _find_stylesheet { @@ -144,6 +157,13 @@ sub get_stylesheet_for_user { return $css_path; } +######################################### +# Javascripts +######################################## + +# override in sub layouts +sub static_javascripts {} + sub add_javascripts { &use_javascript } @@ -151,14 +171,14 @@ sub add_javascripts { sub use_javascript { my $self = shift; push @{ $self->{javascripts} ||= [] }, @_ if @_; - @{ $self->{javascripts} ||= [] }; + map({ $_->use_javascript } $self->sub_layouts), $self->static_javascripts, @{ $self->{javascripts} ||= [] }; } sub javascripts { my ($self) = @_; return uniq grep { $_ } map { $self->_find_javascript($_) } - map({ $_->javascripts } $self->sub_layouts), $self->use_javascript; + $self->use_javascript; } sub _find_javascript { @@ -279,15 +299,33 @@ For the C<*_content> callbacks this works if you just remember to dispatch to th $_[0]->SUPER::post_content } -For the stylesheet and javascript callbacks things are hard, because of the -backwards compatibility, and the built-in sanity checks. The best way currently -is to just add your content and dispatch to the base method. - sub stylesheets { - $_[0]->add_stylesheets(qw(mystyle1.css mystyle2.css); - $_[0]->SUPER::stylesheets; +Stylesheets and Javascripts can be added to every layout and sub-layout at +runtime with L and +L (C and +C are aliases for backwards compatibility): + + $layout->add_stylesheets("custom.css"); + $layout->add_javascripts("app.js", "widget.js"); + +Or they can be overwritten in sub layouts with the calls +L and +L: + + sub static_stylesheets { + "custom.css" } + sub static_javascripts { + qw(app.css widget.js) + } + +Note how these are relative to the base dirs of the currently selected +stylesheets. Javascripts are resolved relative to the C basedir. + +Setting directly with C and C is eprecated. + + =head1 GORY DETAILS ABOUT JAVASCRIPT AND STYLESHEET OVERLOADING The original code used to store one stylesheet in C<< $form->{stylesheet} >> and