From: Sven Schöling Date: Fri, 14 Sep 2012 16:36:36 +0000 (+0200) Subject: besseres interface und delegating für layouts, inline accessoren X-Git-Tag: release-3.0.0beta1~170 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a8814e0ef7175fef00ba18195ba2d457095b96ad;p=kivitendo-erp.git besseres interface und delegating für layouts, inline accessoren html menü in footer verschoben --- diff --git a/SL/Controller/Layout/Base.pm b/SL/Controller/Layout/Base.pm index ed8701947..dbd5d8835 100644 --- a/SL/Controller/Layout/Base.pm +++ b/SL/Controller/Layout/Base.pm @@ -5,6 +5,12 @@ use parent qw(SL::Controller::Base); use Rose::Object::MakeMethods::Generic ( 'scalar --get_set_init' => qw(menu), + 'array' => [ + 'add_stylesheets_inline' => { interface => 'add', hash_key => 'stylesheets_inline' }, + 'add_javascripts_inline' => { interface => 'add', hash_key => 'javascripts_inline' }, + 'sub_layouts', + 'add_sub_layouts' => { interface => 'add', hash_key => 'sub_layouts' }, + ], ); use SL::Menu; @@ -26,23 +32,32 @@ sub init_menu { ########################################## sub pre_content { + join '', map { $_->pre_content } $_[0]->sub_layouts; } sub start_content { + join '', map { $_->start_content } $_[0]->sub_layouts; } sub end_content { + join '', map { $_->end_content } $_[0]->sub_layouts; } sub post_content { + join '', map { $_->post_content } $_[0]->sub_layouts; } sub stylesheets_inline { + ( map { $_->stylesheets_inline } $_[0]->sub_layouts ), + @{ $_[0]->{stylesheets_inline} || [] }; } -sub javascript_inline { +sub javascripts_inline { + ( map { $_->javascripts_inline } $_[0]->sub_layouts ), + @{ $_[0]->{javascripts_inline} || [] }; } + ######################################### # Interface ######################################## @@ -57,7 +72,8 @@ sub stylesheets { my ($self) = @_; my $css_path = $self->get_stylesheet_for_user; - return grep { $_ } map { $self->_find_stylesheet($_, $css_path) } $self->use_stylesheet; + return grep { $_ } map { $self->_find_stylesheet($_, $css_path) } + $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts; } sub _find_stylesheet { @@ -89,7 +105,6 @@ sub get_stylesheet_for_user { sub use_javascript { my $self = shift; - $::lxdebug->dump(0, "class", \@_); push @{ $self->{javascripts} ||= [] }, @_ if @_; @{ $self->{javascripts} ||= [] }; } @@ -97,7 +112,8 @@ sub use_javascript { sub javascripts { my ($self) = @_; - return map { $self->_find_javascript($_) } $self->use_javascript; + return map { $self->_find_javascript($_) } + $self->use_javascript, map { $_->javascripts } $self->sub_layouts; } sub _find_javascript { diff --git a/SL/Controller/Layout/Classic.pm b/SL/Controller/Layout/Classic.pm index 6aac3e574..a4d99b451 100644 --- a/SL/Controller/Layout/Classic.pm +++ b/SL/Controller/Layout/Classic.pm @@ -11,33 +11,12 @@ sub new { my $self = $class->SUPER::new(@slurp); - $self->{top} = SL::Controller::Layout::Top->new; - $self->{left} = SL::Controller::Layout::MenuLeft->new; - - $self->use_stylesheet( - $self->{top}->stylesheets, - $self->{left}->stylesheets, - ); - - $self->use_javascript( - $self->{top}->javascripts, - $self->{left}->javascripts, - ); + $self->add_sub_layouts([ + SL::Controller::Layout::Top->new, + SL::Controller::Layout::MenuLeft->new, + ]); $self; } -sub pre_content { - $_[0]{top}->render . - $_[0]{left}->render; -} - -sub start_content { - "
\n"; -} - -sub end_content { - "
\n"; -} - 1; diff --git a/SL/Controller/Layout/MenuLeft.pm b/SL/Controller/Layout/MenuLeft.pm index ed4c5e9d3..9aa230fec 100644 --- a/SL/Controller/Layout/MenuLeft.pm +++ b/SL/Controller/Layout/MenuLeft.pm @@ -12,18 +12,31 @@ sub new { my $self = $class->SUPER::new(@slurp); - $self->use_stylesheet(qw(css/icons16.css css/icons24.css)); - $self; } -sub render { - my ($self) = @_; - my $sections = [ section_menu($self->menu) ]; +sub stylesheets { + qw(css/icons16.css css/icons24.css) +} - $self->SUPER::render('menu/menu', { no_menu => 1, no_output => 1 }, +sub javascripts_inline { + my $self = shift; + my $sections = [ section_menu($self->menu) ]; + $self->render('menu/menu', { no_menu => 1, no_output => 1 }, sections => $sections, - ); + ) +} + +sub pre_content { + "
\n"; +} + +sub start_content { + "
\n"; +} + +sub end_content { + "
\n"; } sub section_menu { diff --git a/SL/Controller/Layout/Top.pm b/SL/Controller/Layout/Top.pm index f4305d6e0..b8e4c080d 100644 --- a/SL/Controller/Layout/Top.pm +++ b/SL/Controller/Layout/Top.pm @@ -3,7 +3,7 @@ package SL::Controller::Layout::Top; use strict; use parent qw(SL::Controller::Layout::Base); -sub render { +sub pre_content { my ($self) = @_; $self->SUPER::render('menu/header', { partial => 1, no_output => 1 }, diff --git a/SL/Controller/Layout/V4.pm b/SL/Controller/Layout/V4.pm index 6be1b551a..df61836fa 100644 --- a/SL/Controller/Layout/V4.pm +++ b/SL/Controller/Layout/V4.pm @@ -11,19 +11,10 @@ sub new { my ($class, @slurp) = @_; my $self = $class->SUPER::new(@slurp); - $self->{top} = SL::Controller::Layout::Top->new; + $self->add_sub_layouts(SL::Controller::Layout::Top->new); $self; } -sub pre_content { - $_[0]{top}->render . - &render; -} - -sub stylesheets { - $_[0]{top}->stylesheets -} - sub start_content { "
\n"; } @@ -32,7 +23,7 @@ sub end_content { "
\n"; } -sub render { +sub pre_content { my ($self) = @_; $self->{sub_class} = 1; @@ -41,6 +32,8 @@ sub render { $callback = URI->new($callback)->rel($callback) if $callback; $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/; + $self->SUPER::pre_content . + $self->SUPER::render('menu/menuv4', { no_menu => 1, no_output => 1 }, force_ul_width => 1, date => $self->clock_line, diff --git a/SL/Form.pm b/SL/Form.pm index 450dd792d..4dc311826 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -537,10 +537,10 @@ sub footer { print $::request->{layout}->end_content; print $::request->{layout}->post_content; -# print "\n" for $::request->{layout}->javascripts; -# if (my @inline_scripts = $::request->{layout}->javascript_inline) { -# print "\n" for @inline_scripts; -# } + + if (my @inline_scripts = $::request->{layout}->javascripts_inline) { + print "\n" for @inline_scripts; + } print < diff --git a/templates/webpages/menu/menu.html b/templates/webpages/menu/menu.html index 4019bdd2b..ef9aa211d 100644 --- a/templates/webpages/menu/menu.html +++ b/templates/webpages/menu/menu.html @@ -1,3 +1,2 @@ [%- USE JSON %] -
- +$(function(){$([% JSON.json(sections) %]).each(function(i,b){var a=$('').append($('').append($('
').addClass(b.i)),$('').append(b.l));if(b.h)a.attr('href', b.h);if(b.t)a.attr('target', b.t);$('#html-menu').append($('
').addClass(b.c).addClass(b.s).attr('id','mi'+b.id).append(a))});$('#html-menu div.i, #html-menu div.sm').not('[id^='+$.cookie('html-menu-selection')+'_]').hide();$('#html-menu div.m').each(function(){$(this).click(function(){$.cookie('html-menu-selection',$(this).attr('id'));$('#html-menu div.mi').not('div.m').not('[id^='+$(this).attr('id')+'_]').hide();$('#html-menu div.mi[id^='+$(this).attr('id')+'_]').toggle()})})})