Projekt

Allgemein

Profil

Herunterladen (3,68 KB) Statistiken
| Zweig: | Markierung: | Revision:
b6fd15a8 Sven Schöling
package SL::Layout::Base;
4a12c839 Sven Schöling
use strict;
use parent qw(SL::Controller::Base);

2bed2abd Sven Schöling
use List::MoreUtils qw(uniq);
bae050e9 Moritz Bunkus
use Time::HiRes qw();
2bed2abd Sven Schöling
4a12c839 Sven Schöling
use Rose::Object::MakeMethods::Generic (
bae050e9 Moritz Bunkus
'scalar --get_set_init' => [ qw(menu auto_reload_resources_param) ],
4061ebb7 Sven Schöling
'scalar' => qw(focus),
a8814e0e Sven Schöling
'array' => [
'add_stylesheets_inline' => { interface => 'add', hash_key => 'stylesheets_inline' },
'add_javascripts_inline' => { interface => 'add', hash_key => 'javascripts_inline' },
8bed51b5 Sven Schöling
'sub_layouts', => { interface => 'get_set_init' },
'add_sub_layouts' => { interface => 'add', hash_key => 'sub_layouts' },
a8814e0e Sven Schöling
],
4a12c839 Sven Schöling
);

use SL::Menu;

my %menu_cache;

sub new {
my ($class, @slurp) = @_;

my $self = $class->SUPER::new(@slurp);
}

sub init_menu {
Menu->new('menu.ini');
}

bae050e9 Moritz Bunkus
sub init_auto_reload_resources_param {
return '' unless $::lx_office_conf{debug}->{auto_reload_resources};
return sprintf('?rand=%d-%d-%d', Time::HiRes::gettimeofday(), int(rand 1000000000000));
}

0f179c9a Sven Schöling
##########################################
# inheritable/overridable
##########################################

4a12c839 Sven Schöling
sub pre_content {
a8814e0e Sven Schöling
join '', map { $_->pre_content } $_[0]->sub_layouts;
4a12c839 Sven Schöling
}

sub start_content {
a8814e0e Sven Schöling
join '', map { $_->start_content } $_[0]->sub_layouts;
4a12c839 Sven Schöling
}

sub end_content {
a8814e0e Sven Schöling
join '', map { $_->end_content } $_[0]->sub_layouts;
4a12c839 Sven Schöling
}

sub post_content {
a8814e0e Sven Schöling
join '', map { $_->post_content } $_[0]->sub_layouts;
4a12c839 Sven Schöling
}

0f179c9a Sven Schöling
sub stylesheets_inline {
2bed2abd Sven Schöling
uniq ( map { $_->stylesheets_inline } $_[0]->sub_layouts ),
a8814e0e Sven Schöling
@{ $_[0]->{stylesheets_inline} || [] };
0f179c9a Sven Schöling
}

a8814e0e Sven Schöling
sub javascripts_inline {
2bed2abd Sven Schöling
uniq ( map { $_->javascripts_inline } $_[0]->sub_layouts ),
a8814e0e Sven Schöling
@{ $_[0]->{javascripts_inline} || [] };
0f179c9a Sven Schöling
}

8bed51b5 Sven Schöling
sub init_sub_layouts { [] }

a8814e0e Sven Schöling
0f179c9a Sven Schöling
#########################################
# Interface
########################################

4e7776aa Sven Schöling
sub add_stylesheets {
&use_stylesheet;
}

0f179c9a Sven Schöling
sub use_stylesheet {
my $self = shift;
push @{ $self->{stylesheets} ||= [] }, @_ if @_;
@{ $self->{stylesheets} ||= [] };
}

4a12c839 Sven Schöling
sub stylesheets {
0f179c9a Sven Schöling
my ($self) = @_;
my $css_path = $self->get_stylesheet_for_user;

2bed2abd Sven Schöling
return uniq grep { $_ } map { $self->_find_stylesheet($_, $css_path) }
a8814e0e Sven Schöling
$self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts;
4a12c839 Sven Schöling
}

0f179c9a Sven Schöling
sub _find_stylesheet {
my ($self, $stylesheet, $css_path) = @_;

return "$css_path/$stylesheet" if -f "$css_path/$stylesheet";
return "css/$stylesheet" if -f "css/$stylesheet";
return $stylesheet if -f $stylesheet;
4a12c839 Sven Schöling
}

0f179c9a Sven Schöling
sub get_stylesheet_for_user {
my $css_path = 'css';
if (my $user_style = $::myconfig{stylesheet}) {
$user_style =~ s/\.css$//; # nuke trailing .css, this is a remnand of pre 2.7.0 stylesheet handling
if (-d "$css_path/$user_style" &&
-f "$css_path/$user_style/main.css") {
$css_path = "$css_path/$user_style";
} else {
7e96b2d0 Moritz Bunkus
$css_path = "$css_path/kivitendo";
0f179c9a Sven Schöling
}
} else {
7e96b2d0 Moritz Bunkus
$css_path = "$css_path/kivitendo";
0f179c9a Sven Schöling
}
$::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here

return $css_path;
}

4e7776aa Sven Schöling
sub add_javascripts {
&use_javascript
}
0f179c9a Sven Schöling
sub use_javascript {
my $self = shift;
push @{ $self->{javascripts} ||= [] }, @_ if @_;
@{ $self->{javascripts} ||= [] };
}

sub javascripts {
my ($self) = @_;

baf1e895 Moritz Bunkus
return uniq grep { $_ } map { $self->_find_javascript($_) }
bc9a389f Sven Schöling
map({ $_->javascripts } $self->sub_layouts), $self->use_javascript;
0f179c9a Sven Schöling
}

sub _find_javascript {
my ($self, $javascript) = @_;

return "js/$javascript" if -f "js/$javascript";
return $javascript if -f $javascript;
4a12c839 Sven Schöling
}

2219d158 Sven Schöling
############################################
# track state of form header
############################################

sub header_done {
$_[0]{_header_done} = 1;
}

sub need_footer {
$_[0]{_header_done};
}

4a12c839 Sven Schöling
1;