From: Sven Schöling Date: Tue, 16 Oct 2012 10:58:50 +0000 (+0200) Subject: Layout package names refactored X-Git-Tag: release-3.0.0beta1~130 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=b6fd15a8dc44f9b09d5a2bce766cda14b87c6e13;p=kivitendo-erp.git Layout package names refactored SL::Controller::Layout::* -> SL::Layout::* SL::Controller::Layout -> SL::Layout::Dispatcher --- diff --git a/SL/Controller/Layout.pm b/SL/Controller/Layout.pm deleted file mode 100644 index 82d5da848..000000000 --- a/SL/Controller/Layout.pm +++ /dev/null @@ -1,28 +0,0 @@ -package SL::Controller::Layout; - -use strict; -use parent qw(SL::Controller::Base); - -use SL::Menu; -use SL::Controller::Layout::Admin; -use SL::Controller::Layout::Login; -use SL::Controller::Layout::Classic; -use SL::Controller::Layout::V3; -use SL::Controller::Layout::V4; -use SL::Controller::Layout::Javascript; - -my %menu_cache; - -sub new { - my ($class, %params) = @_; - - return SL::Controller::Layout::Classic->new if $params{style} eq 'old'; - return SL::Controller::Layout::V3->new if $params{style} eq 'v3'; - return SL::Controller::Layout::V4->new if $params{style} eq 'v4'; - return SL::Controller::Layout::Javascript->new if $params{style} eq 'neu'; - return SL::Controller::Layout::Admin->new if $params{style} eq 'admin'; - return SL::Controller::Layout::Login->new if $params{style} eq 'login'; - return SL::Controller::Layout::None->new; -} - -1; diff --git a/SL/Controller/Layout/Admin.pm b/SL/Controller/Layout/Admin.pm deleted file mode 100644 index 9d8f30c61..000000000 --- a/SL/Controller/Layout/Admin.pm +++ /dev/null @@ -1,26 +0,0 @@ -package SL::Controller::Layout::Admin; - -use strict; -use parent qw(SL::Controller::Layout::Base); - -sub new { - my ($class, @slurp) = @_; - - my $self = $class->SUPER::new(@slurp); - - $self->add_sub_layouts([ - SL::Controller::Layout::None->new, - ]); - - $self; -} - -sub start_content { - "
\n"; -} - -sub end_content { - "
\n"; -} - -1; diff --git a/SL/Controller/Layout/Base.pm b/SL/Controller/Layout/Base.pm deleted file mode 100644 index ed25f1b78..000000000 --- a/SL/Controller/Layout/Base.pm +++ /dev/null @@ -1,140 +0,0 @@ -package SL::Controller::Layout::Base; - -use strict; -use parent qw(SL::Controller::Base); - -use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => qw(menu), - 'scalar' => qw(focus), - '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; - -my %menu_cache; - -sub new { - my ($class, @slurp) = @_; - - my $self = $class->SUPER::new(@slurp); -} - -sub init_menu { - Menu->new('menu.ini'); -} - -########################################## -# inheritable/overridable -########################################## - -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 javascripts_inline { - ( map { $_->javascripts_inline } $_[0]->sub_layouts ), - @{ $_[0]->{javascripts_inline} || [] }; -} - - -######################################### -# Interface -######################################## - -sub use_stylesheet { - my $self = shift; - push @{ $self->{stylesheets} ||= [] }, @_ if @_; - @{ $self->{stylesheets} ||= [] }; -} - -sub stylesheets { - my ($self) = @_; - my $css_path = $self->get_stylesheet_for_user; - - return grep { $_ } map { $self->_find_stylesheet($_, $css_path) } - $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts; -} - -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; -} - -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 { - $css_path = "$css_path/lx-office-erp"; - } - } else { - $css_path = "$css_path/lx-office-erp"; - } - $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here - - return $css_path; -} - - -sub use_javascript { - my $self = shift; - push @{ $self->{javascripts} ||= [] }, @_ if @_; - @{ $self->{javascripts} ||= [] }; -} - -sub javascripts { - my ($self) = @_; - - return map { $self->_find_javascript($_) } - $self->use_javascript, map { $_->javascripts } $self->sub_layouts; -} - -sub _find_javascript { - my ($self, $javascript) = @_; - - return "js/$javascript" if -f "js/$javascript"; - return $javascript if -f $javascript; -} - - -############################################ -# track state of form header -############################################ - -sub header_done { - $_[0]{_header_done} = 1; -} - -sub need_footer { - $_[0]{_header_done}; -} - -1; diff --git a/SL/Controller/Layout/Classic.pm b/SL/Controller/Layout/Classic.pm deleted file mode 100644 index b7438740c..000000000 --- a/SL/Controller/Layout/Classic.pm +++ /dev/null @@ -1,23 +0,0 @@ -package SL::Controller::Layout::Classic; - -use strict; -use parent qw(SL::Controller::Layout::Base); - -use SL::Controller::Layout::Top; -use SL::Controller::Layout::MenuLeft; - -sub new { - my ($class, @slurp) = @_; - - my $self = $class->SUPER::new(@slurp); - - $self->add_sub_layouts([ - SL::Controller::Layout::Top->new, - SL::Controller::Layout::MenuLeft->new, - SL::Controller::Layout::None->new, - ]); - - $self; -} - -1; diff --git a/SL/Controller/Layout/Css.pm b/SL/Controller/Layout/Css.pm deleted file mode 100644 index 43e2b68de..000000000 --- a/SL/Controller/Layout/Css.pm +++ /dev/null @@ -1,129 +0,0 @@ -package SL::Controller::Layout::Css; - -use strict; - -use List::Util qw(max); -use Exporter qw(import); - -our @EXPORT = qw(clock_line print_menu menuitem_v3); - -sub clock_line { - my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, - $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) - = localtime(time); - $Monat += 1; - $Jahrestag += 1; - $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat; - $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag; - $Jahr += 1900; - my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch", - "Donnerstag", "Freitag", "Samstag"); - my @Monatsnamen = ("", "Januar", "Februar", "März", - "April", "Mai", "Juni", "Juli", - "August", "September", "Oktober", "November", - "Dezember"); - return - $Wochentage[$Wochentag] . ", der " - . $Monatstag . "." - . $Monat . "." - . $Jahr . " - "; -} - -sub print_menu { - my ($self, $parent, $depth) = @_; - - my $html; - - die if ($depth * 1 > 5); - - my @menuorder; - my $menu = $self->menu; - - @menuorder = $menu->access_control(\%::myconfig, $parent); - - $parent .= "--" if ($parent); - - foreach my $item (@menuorder) { - substr($item, 0, length($parent)) = ""; - next if (($item eq "") || ($item =~ /--/)); - - my $menu_item = $menu->{"${parent}${item}"}; - my $menu_title = $::locale->text($item); - my $menu_text = $menu_title; - - if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) || - ($menu_item->{"module"} eq "menu.pl")) { - - my $h = $self->print_menu("${parent}${item}", $depth * 1 + 1)."\n"; - if (!$parent) { - $html .= qq|\n|; - } else { - $html .= qq|
  • ${menu_text}
  • \n|; - } - } else { - if ($self->{sub_class} && $depth > 1) { - $html .= qq|
  • |; - } else { - $html .= qq|
  • |; - } - $html .= $self->menuitem_v3("${parent}$item", { "title" => $menu_title }); - $html .= qq|${menu_text}
  • \n|; - } - } - - return $html; -} - -sub menuitem_v3 { - $main::lxdebug->enter_sub(); - - my ($self, $item, $other) = @_; - my $menuitem = $self->menu->{$item}; - - my $action = "section_menu"; - my $module; - - if ($menuitem->{module}) { - $module = $menuitem->{module}; - } - if ($menuitem->{action}) { - $action = $menuitem->{action}; - } - - my $level = $::form->escape($item); - - my $str = qq|escape($key, 1) . "="; - my ($value, $conf) = split(/=/, $menuitem->{$key}, 2); - $value = $::myconfig{$value} . "/$conf" if ($conf); - $str .= $::form->escape($value, 1); - } - - $str .= '"'; - - if ($other) { - foreach my $key (keys(%{$other})) { - $str .= qq| ${key}="| . $::form->quote($other->{$key}) . qq|"|; - } - } - - $str .= ">"; - - $main::lxdebug->leave_sub(); - - return $str; -} - -1; diff --git a/SL/Controller/Layout/Javascript.pm b/SL/Controller/Layout/Javascript.pm deleted file mode 100644 index f9ee831bf..000000000 --- a/SL/Controller/Layout/Javascript.pm +++ /dev/null @@ -1,141 +0,0 @@ -package SL::Controller::Layout::Javascript; - -use strict; -use parent qw(SL::Controller::Layout::Base); - -use List::Util qw(max); -use URI; - -sub new { - my ($class, @slurp) = @_; - - my $self = $class->SUPER::new(@slurp); - - $self->add_sub_layouts([ - SL::Controller::Layout::None->new, - ]); - - $self; -} - -sub pre_content { - &display -} - -sub start_content { - "
    \n"; -} - -sub end_content { - "
    \n"; -} - -sub display { - my ($self) = @_; - my $form = $main::form; - - my $callback = $form->unescape($form->{callback}); - $callback = URI->new($callback)->rel($callback) if $callback; - $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/; - - $form->parse_html_template("menu/menunew", { -# $self->render("menu/menunew", { no_menu => 1, no_output => 1 }, # buggy, no idea why - force_ul_width => 1, - date => $self->clock_line, - menu_items => $self->acc_menu, - callback => $callback, - }); -} - -sub clock_line { - my $form = $main::form; - - my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, - $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) - = localtime(time); - $Monat += 1; - $Jahrestag += 1; - $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat; - $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag; - $Jahr += 1900; - my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch", - "Donnerstag", "Freitag", "Samstag"); - my @Monatsnamen = ("", "Januar", "Februar", "März", - "April", "Mai", "Juni", "Juli", - "August", "September", "Oktober", "November", - "Dezember"); - return - $Wochentage[$Wochentag] . ", der " - . $Monatstag . "." - . $Monat . "." - . $Jahr . " - "; -} - -sub acc_menu { - my ($self) = @_; - - my $menu = $self->menu; - - my $all_items = []; - $self->create_menu($menu, $all_items); - - my $item = { 'subitems' => $all_items }; - calculate_width($item); - - return $all_items; -} - -sub calculate_width { - my $item = shift; - - $item->{max_width} = max map { length $_->{title} } @{ $item->{subitems} }; - - foreach my $subitem (@{ $item->{subitems} }) { - calculate_width($subitem) if ($subitem->{subitems}); - } -} - -sub create_menu { - my ($self, $menu, $all_items, $parent, $depth) = @_; - my $html; - - my $form = $main::form; - my %myconfig = %main::myconfig; - - die if ($depth * 1 > 5); - - my @menuorder = $menu->access_control(\%myconfig, $parent); - $parent .= "--" if ($parent); - - foreach my $name (@menuorder) { - substr($name, 0, length($parent), ""); - next if (($name eq "") || ($name =~ /--/)); - - my $menu_item = $menu->{"${parent}${name}"}; - my $item = { 'title' => $::locale->text($name) }; - push @{ $all_items }, $item; - - if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) { - $item->{subitems} = []; - $item->{image} = _icon_path("$name.png"); - $self->create_menu($menu, $item->{subitems}, "${parent}${name}", $depth * 1 + 1); - - } else { - $item->{image} = _icon_path("${parent}${name}.png"); - $menu->menuitem_new("${parent}${name}", $item); - } - } -} - -sub _icon_path { - my ($label, $size) = @_; - - $size ||= 16; - - my $img = "image/icons/${size}x${size}/$label"; - - return unless -f $img; - return $img; -} - -1; diff --git a/SL/Controller/Layout/Login.pm b/SL/Controller/Layout/Login.pm deleted file mode 100644 index 60f6e940a..000000000 --- a/SL/Controller/Layout/Login.pm +++ /dev/null @@ -1,26 +0,0 @@ -package SL::Controller::Layout::Login; - -use strict; -use parent qw(SL::Controller::Layout::Base); - -sub new { - my ($class, @slurp) = @_; - - my $self = $class->SUPER::new(@slurp); - - $self->add_sub_layouts([ - SL::Controller::Layout::None->new, - ]); - - $self; -} - -sub start_content { - "\n"; -} - -1; diff --git a/SL/Controller/Layout/MenuLeft.pm b/SL/Controller/Layout/MenuLeft.pm deleted file mode 100644 index 75c99e3b1..000000000 --- a/SL/Controller/Layout/MenuLeft.pm +++ /dev/null @@ -1,105 +0,0 @@ -package SL::Controller::Layout::MenuLeft; - -use strict; -use parent qw(SL::Controller::Layout::Base); - -use URI; - -use List::MoreUtils qw(apply); - -sub stylesheets { - qw(css/icons16.css css/icons24.css) -} - -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 { - $::lxdebug->enter_sub(2); - my ($menu, $level, $id_prefix) = @_; - my @menuorder = $menu->access_control(\%::myconfig, $level); - my @items; - - my $id = 0; - - for my $item (@menuorder) { - my $menuitem = $menu->{$item}; - my $olabel = apply { s/.*--// } $item; - my $ml = apply { s/--.*// } $item; - my $icon_class = apply { y/ /-/ } $item; - my $spacer = "s" . (0 + $item =~ s/--/--/g); - - next if $level && $item ne "$level--$olabel"; - - my $label = $::locale->text($olabel); - - $menuitem->{module} ||= $::form->{script}; - $menuitem->{action} ||= "section_menu"; - $menuitem->{href} ||= "$menuitem->{module}?action=$menuitem->{action}"; - - # add other params - foreach my $key (keys %$menuitem) { - next if $key =~ /target|module|action|href/; - $menuitem->{href} .= "&" . $::form->escape($key, 1) . "="; - my ($value, $conf) = split(/=/, $menuitem->{$key}, 2); - $value = $::myconfig{$value} . "/$conf" if ($conf); - $menuitem->{href} .= $::form->escape($value, 1); - } - - my $anchor = $menuitem->{href}; - - my @common_args = ($label, $spacer, "$id_prefix\_$id"); - - if (!$level) { # toplevel - push @items, [ @common_args, "icon24 $icon_class", 'm' ]; - # make_image(size => 24, label => $item), - push @items, section_menu($menu, $item, "$id_prefix\_$id"); - } elsif ($menuitem->{submenu}) { - push @items, [ @common_args, "icon16 submenu", 'sm' ]; - #make_image(label => 'submenu'), - push @items, section_menu($menu, $item, "$id_prefix\_$id"); - } elsif ($menuitem->{module}) { - push @items, [ @common_args, "icon16 $icon_class", 'i', $anchor ]; - #make_image(size => 16, label => $item), - } - } continue { - $id++; - } - - $::lxdebug->leave_sub(2); - return @items; -} - -sub _calc_framesize { - my $is_lynx_browser = $ENV{HTTP_USER_AGENT} =~ /links/i; - my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i; - my $is_mobile_style = $::form->{stylesheet} =~ /mobile/i; - - return $is_mobile_browser && $is_mobile_style ? 130 - : $is_lynx_browser ? 240 - : 200; -} - -sub _show_images { - # don't show images in links - _calc_framesize() != 240; -} - -1; diff --git a/SL/Controller/Layout/None.pm b/SL/Controller/Layout/None.pm deleted file mode 100644 index 204b8ee36..000000000 --- a/SL/Controller/Layout/None.pm +++ /dev/null @@ -1,27 +0,0 @@ -package SL::Controller::Layout::None; - -use strict; -use parent qw(SL::Controller::Layout::Base); - -sub javascripts_inline { - _setup_formats(), - _setup_focus(), -} - - -sub _setup_formats { - $::form->parse_html_template('generic/javascript_setup') -} - -sub _setup_focus { - if ($::request->{layout}->focus || $::form->{fokus}) { - return $::form->parse_html_template('generic/focus_setup', { - focus => $::request->{layout}->focus, - fokus => $::form->{fokus}, - }) - } else { - return (); - } -} - -1; diff --git a/SL/Controller/Layout/Top.pm b/SL/Controller/Layout/Top.pm deleted file mode 100644 index b8e4c080d..000000000 --- a/SL/Controller/Layout/Top.pm +++ /dev/null @@ -1,19 +0,0 @@ -package SL::Controller::Layout::Top; - -use strict; -use parent qw(SL::Controller::Layout::Base); - -sub pre_content { - my ($self) = @_; - - $self->SUPER::render('menu/header', { partial => 1, no_output => 1 }, - now => DateTime->now_local, - is_fastcgi => scalar($::dispatcher->interface_type =~ /fastcgi/i), - is_links => scalar($ENV{HTTP_USER_AGENT} =~ /links/i)); -} - -sub stylesheets { -# 'frame_header/header.css'; -} - -1; diff --git a/SL/Controller/Layout/V3.pm b/SL/Controller/Layout/V3.pm deleted file mode 100644 index 3a2c9848b..000000000 --- a/SL/Controller/Layout/V3.pm +++ /dev/null @@ -1,48 +0,0 @@ -package SL::Controller::Layout::V3; - -use strict; -use parent qw(SL::Controller::Layout::Base); -use SL::Controller::Layout::Css; - -use URI; - -sub new { - my ($class, @slurp) = @_; - - my $self = $class->SUPER::new(@slurp); - - $self->add_sub_layouts([ - SL::Controller::Layout::None->new, - ]); - - $self; -} - -sub pre_content { - &render; -} - -sub start_content { - "
    \n"; -} - -sub end_content { - "
    \n"; -} - -sub render { - my ($self) = @_; - - my $callback = $::form->unescape($::form->{callback}); - $callback = URI->new($callback)->rel($callback) if $callback; - $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/; - - $self->SUPER::render('menu/menuv3', { no_menu => 1, no_output => 1 }, - force_ul_width => 1, - date => $self->clock_line, - menu => $self->print_menu, - callback => $callback, - ); -} - -1; diff --git a/SL/Controller/Layout/V4.pm b/SL/Controller/Layout/V4.pm deleted file mode 100644 index aee0b1318..000000000 --- a/SL/Controller/Layout/V4.pm +++ /dev/null @@ -1,48 +0,0 @@ -package SL::Controller::Layout::V4; - -use strict; -use parent qw(SL::Controller::Layout::Base); -use SL::Controller::Layout::Css; -use SL::Controller::Layout::Top; - -use URI; - -sub new { - my ($class, @slurp) = @_; - - my $self = $class->SUPER::new(@slurp); - $self->add_sub_layouts( - SL::Controller::Layout::Top->new, - SL::Controller::Layout::None->new, - ); - $self; -} - -sub start_content { - "
    \n"; -} - -sub end_content { - "
    \n"; -} - -sub pre_content { - my ($self) = @_; - - $self->{sub_class} = 1; - - my $callback = $::form->unescape($::form->{callback}); - $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, - menu => $self->print_menu, - callback => $callback, - ); -} - -1; diff --git a/SL/Controller/LoginScreen.pm b/SL/Controller/LoginScreen.pm index e73224bcc..89909c00d 100644 --- a/SL/Controller/LoginScreen.pm +++ b/SL/Controller/LoginScreen.pm @@ -39,7 +39,7 @@ sub action_login { $::form->{login} = $::myconfig{login}; $::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode}; my $user = User->new(login => $::myconfig{login}); - $::request->{layout} = SL::Controller::Layout->new(style => $user->{menustyle}); + $::request->{layout} = SL::Layout->new(style => $user->{menustyle}); # if we get an error back, bale out my $result = $user->login($::form); @@ -118,7 +118,7 @@ sub error_state { } sub set_layout { - $::request->{layout} = SL::Controller::Layout->new(style => 'login'); + $::request->{layout} = SL::Layout::Dispatcher->new(style => 'login'); } 1; diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index d65e5d5e0..35a351877 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -35,7 +35,7 @@ use SL::Form; use SL::Helper::DateTime; use SL::InstanceConfiguration; use SL::Template::Plugin::HTMLFixes; -use SL::Controller::Layout::None; +use SL::Layout::None; # Trailing new line is added so that Perl will not add the line # number 'die' was called in. @@ -184,7 +184,7 @@ sub handle_request { $::instance_conf = SL::InstanceConfiguration->new; $::request = { cgi => CGI->new({}), - layout => SL::Controller::Layout::None->new, + layout => SL::Layout::None->new, }; my $session_result = $::auth->restore_session; diff --git a/SL/Dispatcher/AuthHandler/Admin.pm b/SL/Dispatcher/AuthHandler/Admin.pm index 86efbb2dc..2e41ee90e 100644 --- a/SL/Dispatcher/AuthHandler/Admin.pm +++ b/SL/Dispatcher/AuthHandler/Admin.pm @@ -3,7 +3,7 @@ package SL::Dispatcher::AuthHandler::Admin; use strict; use parent qw(Rose::Object); -use SL::Controller::Layout; +use SL::Layout::Dispatcher; sub handle { %::myconfig = (); @@ -11,7 +11,7 @@ sub handle { return if $::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::form->{'{AUTH}admin_password'}) == $::auth->OK()); return if !$::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::auth->get_session_value('admin_password')) == $::auth->OK()); - $::request->{layout} = SL::Controller::Layout->new(style => 'admin'); + $::request->{layout} = SL::Layout::Dispatcher->new(style => 'admin'); $::auth->punish_wrong_login; $::auth->delete_session_value('admin_password'); diff --git a/SL/Dispatcher/AuthHandler/User.pm b/SL/Dispatcher/AuthHandler/User.pm index 6dc200bae..1273d679f 100644 --- a/SL/Dispatcher/AuthHandler/User.pm +++ b/SL/Dispatcher/AuthHandler/User.pm @@ -3,7 +3,7 @@ package SL::Dispatcher::AuthHandler::User; use strict; use parent qw(Rose::Object); -use SL::Controller::Layout; +use SL::Layout::Dispatcher; sub handle { my ($self, %param) = @_; @@ -16,7 +16,7 @@ sub handle { $self->_error(%param) unless $::myconfig{login}; $::locale = Locale->new($::myconfig{countrycode}); - $::request->{layout} = SL::Controller::Layout->new(style => $::myconfig{menustyle}); + $::request->{layout} = SL::Layout::Dispatcher->new(style => $::myconfig{menustyle}); my $ok = $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'})); $ok ||= !$::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef)); diff --git a/SL/Form.pm b/SL/Form.pm index 591e02df3..aa83e2913 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -56,6 +56,7 @@ use SL::DBUtils; use SL::DO; use SL::IC; use SL::IS; +use SL::Layout::Dispatcher; use SL::Locale; use SL::Mailer; use SL::Menu; @@ -457,7 +458,7 @@ sub header { $::lxdebug->leave_sub and return if !$ENV{HTTP_USER_AGENT} || $self->{header}++; if ($params{no_layout}) { - $::request->{layout} = SL::Controller::Layout->new(style => 'none'); + $::request->{layout} = SL::Layout::Dispatcher->new(style => 'none'); } my $layout = $::request->{layout}; diff --git a/SL/Layout/Admin.pm b/SL/Layout/Admin.pm new file mode 100644 index 000000000..188655fae --- /dev/null +++ b/SL/Layout/Admin.pm @@ -0,0 +1,26 @@ +package SL::Layout::Admin; + +use strict; +use parent qw(SL::Layout::Base); + +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); + + $self->add_sub_layouts([ + SL::Layout::None->new, + ]); + + $self; +} + +sub start_content { + "
    \n"; +} + +sub end_content { + "
    \n"; +} + +1; diff --git a/SL/Layout/Base.pm b/SL/Layout/Base.pm new file mode 100644 index 000000000..56d5b8e2f --- /dev/null +++ b/SL/Layout/Base.pm @@ -0,0 +1,140 @@ +package SL::Layout::Base; + +use strict; +use parent qw(SL::Controller::Base); + +use Rose::Object::MakeMethods::Generic ( + 'scalar --get_set_init' => qw(menu), + 'scalar' => qw(focus), + '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; + +my %menu_cache; + +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); +} + +sub init_menu { + Menu->new('menu.ini'); +} + +########################################## +# inheritable/overridable +########################################## + +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 javascripts_inline { + ( map { $_->javascripts_inline } $_[0]->sub_layouts ), + @{ $_[0]->{javascripts_inline} || [] }; +} + + +######################################### +# Interface +######################################## + +sub use_stylesheet { + my $self = shift; + push @{ $self->{stylesheets} ||= [] }, @_ if @_; + @{ $self->{stylesheets} ||= [] }; +} + +sub stylesheets { + my ($self) = @_; + my $css_path = $self->get_stylesheet_for_user; + + return grep { $_ } map { $self->_find_stylesheet($_, $css_path) } + $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts; +} + +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; +} + +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 { + $css_path = "$css_path/lx-office-erp"; + } + } else { + $css_path = "$css_path/lx-office-erp"; + } + $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here + + return $css_path; +} + + +sub use_javascript { + my $self = shift; + push @{ $self->{javascripts} ||= [] }, @_ if @_; + @{ $self->{javascripts} ||= [] }; +} + +sub javascripts { + my ($self) = @_; + + return map { $self->_find_javascript($_) } + $self->use_javascript, map { $_->javascripts } $self->sub_layouts; +} + +sub _find_javascript { + my ($self, $javascript) = @_; + + return "js/$javascript" if -f "js/$javascript"; + return $javascript if -f $javascript; +} + + +############################################ +# track state of form header +############################################ + +sub header_done { + $_[0]{_header_done} = 1; +} + +sub need_footer { + $_[0]{_header_done}; +} + +1; diff --git a/SL/Layout/Classic.pm b/SL/Layout/Classic.pm new file mode 100644 index 000000000..a2ef7702d --- /dev/null +++ b/SL/Layout/Classic.pm @@ -0,0 +1,23 @@ +package SL::Layout::Classic; + +use strict; +use parent qw(SL::Layout::Base); + +use SL::Layout::Top; +use SL::Layout::MenuLeft; + +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); + + $self->add_sub_layouts([ + SL::Layout::Top->new, + SL::Layout::MenuLeft->new, + SL::Layout::None->new, + ]); + + $self; +} + +1; diff --git a/SL/Layout/Css.pm b/SL/Layout/Css.pm new file mode 100644 index 000000000..2bb0455ca --- /dev/null +++ b/SL/Layout/Css.pm @@ -0,0 +1,129 @@ +package SL::Layout::Css; + +use strict; + +use List::Util qw(max); +use Exporter qw(import); + +our @EXPORT = qw(clock_line print_menu menuitem_v3); + +sub clock_line { + my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, + $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) + = localtime(time); + $Monat += 1; + $Jahrestag += 1; + $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat; + $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag; + $Jahr += 1900; + my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch", + "Donnerstag", "Freitag", "Samstag"); + my @Monatsnamen = ("", "Januar", "Februar", "März", + "April", "Mai", "Juni", "Juli", + "August", "September", "Oktober", "November", + "Dezember"); + return + $Wochentage[$Wochentag] . ", der " + . $Monatstag . "." + . $Monat . "." + . $Jahr . " - "; +} + +sub print_menu { + my ($self, $parent, $depth) = @_; + + my $html; + + die if ($depth * 1 > 5); + + my @menuorder; + my $menu = $self->menu; + + @menuorder = $menu->access_control(\%::myconfig, $parent); + + $parent .= "--" if ($parent); + + foreach my $item (@menuorder) { + substr($item, 0, length($parent)) = ""; + next if (($item eq "") || ($item =~ /--/)); + + my $menu_item = $menu->{"${parent}${item}"}; + my $menu_title = $::locale->text($item); + my $menu_text = $menu_title; + + if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) || + ($menu_item->{"module"} eq "menu.pl")) { + + my $h = $self->print_menu("${parent}${item}", $depth * 1 + 1)."\n"; + if (!$parent) { + $html .= qq|\n|; + } else { + $html .= qq|
  • ${menu_text}
      ${h}
  • \n|; + } + } else { + if ($self->{sub_class} && $depth > 1) { + $html .= qq|
  • |; + } else { + $html .= qq|
  • |; + } + $html .= $self->menuitem_v3("${parent}$item", { "title" => $menu_title }); + $html .= qq|${menu_text}
  • \n|; + } + } + + return $html; +} + +sub menuitem_v3 { + $main::lxdebug->enter_sub(); + + my ($self, $item, $other) = @_; + my $menuitem = $self->menu->{$item}; + + my $action = "section_menu"; + my $module; + + if ($menuitem->{module}) { + $module = $menuitem->{module}; + } + if ($menuitem->{action}) { + $action = $menuitem->{action}; + } + + my $level = $::form->escape($item); + + my $str = qq|escape($key, 1) . "="; + my ($value, $conf) = split(/=/, $menuitem->{$key}, 2); + $value = $::myconfig{$value} . "/$conf" if ($conf); + $str .= $::form->escape($value, 1); + } + + $str .= '"'; + + if ($other) { + foreach my $key (keys(%{$other})) { + $str .= qq| ${key}="| . $::form->quote($other->{$key}) . qq|"|; + } + } + + $str .= ">"; + + $main::lxdebug->leave_sub(); + + return $str; +} + +1; diff --git a/SL/Layout/Dispatcher.pm b/SL/Layout/Dispatcher.pm new file mode 100644 index 000000000..ea14319d8 --- /dev/null +++ b/SL/Layout/Dispatcher.pm @@ -0,0 +1,27 @@ +package SL::Layout::Dispatcher; + +use strict; + +use SL::Menu; +use SL::Layout::Admin; +use SL::Layout::Login; +use SL::Layout::Classic; +use SL::Layout::V3; +use SL::Layout::V4; +use SL::Layout::Javascript; + +my %menu_cache; + +sub new { + my ($class, %params) = @_; + + return SL::Layout::Classic->new if $params{style} eq 'old'; + return SL::Layout::V3->new if $params{style} eq 'v3'; + return SL::Layout::V4->new if $params{style} eq 'v4'; + return SL::Layout::Javascript->new if $params{style} eq 'neu'; + return SL::Layout::Admin->new if $params{style} eq 'admin'; + return SL::Layout::Login->new if $params{style} eq 'login'; + return SL::Layout::None->new; +} + +1; diff --git a/SL/Layout/Javascript.pm b/SL/Layout/Javascript.pm new file mode 100644 index 000000000..1785a198b --- /dev/null +++ b/SL/Layout/Javascript.pm @@ -0,0 +1,141 @@ +package SL::Layout::Javascript; + +use strict; +use parent qw(SL::Layout::Base); + +use List::Util qw(max); +use URI; + +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); + + $self->add_sub_layouts([ + SL::Layout::None->new, + ]); + + $self; +} + +sub pre_content { + &display +} + +sub start_content { + "
    \n"; +} + +sub end_content { + "
    \n"; +} + +sub display { + my ($self) = @_; + my $form = $main::form; + + my $callback = $form->unescape($form->{callback}); + $callback = URI->new($callback)->rel($callback) if $callback; + $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/; + + $form->parse_html_template("menu/menunew", { +# $self->render("menu/menunew", { no_menu => 1, no_output => 1 }, # buggy, no idea why + force_ul_width => 1, + date => $self->clock_line, + menu_items => $self->acc_menu, + callback => $callback, + }); +} + +sub clock_line { + my $form = $main::form; + + my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, + $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) + = localtime(time); + $Monat += 1; + $Jahrestag += 1; + $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat; + $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag; + $Jahr += 1900; + my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch", + "Donnerstag", "Freitag", "Samstag"); + my @Monatsnamen = ("", "Januar", "Februar", "März", + "April", "Mai", "Juni", "Juli", + "August", "September", "Oktober", "November", + "Dezember"); + return + $Wochentage[$Wochentag] . ", der " + . $Monatstag . "." + . $Monat . "." + . $Jahr . " - "; +} + +sub acc_menu { + my ($self) = @_; + + my $menu = $self->menu; + + my $all_items = []; + $self->create_menu($menu, $all_items); + + my $item = { 'subitems' => $all_items }; + calculate_width($item); + + return $all_items; +} + +sub calculate_width { + my $item = shift; + + $item->{max_width} = max map { length $_->{title} } @{ $item->{subitems} }; + + foreach my $subitem (@{ $item->{subitems} }) { + calculate_width($subitem) if ($subitem->{subitems}); + } +} + +sub create_menu { + my ($self, $menu, $all_items, $parent, $depth) = @_; + my $html; + + my $form = $main::form; + my %myconfig = %main::myconfig; + + die if ($depth * 1 > 5); + + my @menuorder = $menu->access_control(\%myconfig, $parent); + $parent .= "--" if ($parent); + + foreach my $name (@menuorder) { + substr($name, 0, length($parent), ""); + next if (($name eq "") || ($name =~ /--/)); + + my $menu_item = $menu->{"${parent}${name}"}; + my $item = { 'title' => $::locale->text($name) }; + push @{ $all_items }, $item; + + if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) { + $item->{subitems} = []; + $item->{image} = _icon_path("$name.png"); + $self->create_menu($menu, $item->{subitems}, "${parent}${name}", $depth * 1 + 1); + + } else { + $item->{image} = _icon_path("${parent}${name}.png"); + $menu->menuitem_new("${parent}${name}", $item); + } + } +} + +sub _icon_path { + my ($label, $size) = @_; + + $size ||= 16; + + my $img = "image/icons/${size}x${size}/$label"; + + return unless -f $img; + return $img; +} + +1; diff --git a/SL/Layout/Login.pm b/SL/Layout/Login.pm new file mode 100644 index 000000000..ed649d052 --- /dev/null +++ b/SL/Layout/Login.pm @@ -0,0 +1,26 @@ +package SL::Layout::Login; + +use strict; +use parent qw(SL::Layout::Base); + +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); + + $self->add_sub_layouts([ + SL::Layout::None->new, + ]); + + $self; +} + +sub start_content { + "\n"; +} + +1; diff --git a/SL/Layout/MenuLeft.pm b/SL/Layout/MenuLeft.pm new file mode 100644 index 000000000..a171ed184 --- /dev/null +++ b/SL/Layout/MenuLeft.pm @@ -0,0 +1,105 @@ +package SL::Layout::MenuLeft; + +use strict; +use parent qw(SL::Layout::Base); + +use URI; + +use List::MoreUtils qw(apply); + +sub stylesheets { + qw(css/icons16.css css/icons24.css) +} + +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 { + $::lxdebug->enter_sub(2); + my ($menu, $level, $id_prefix) = @_; + my @menuorder = $menu->access_control(\%::myconfig, $level); + my @items; + + my $id = 0; + + for my $item (@menuorder) { + my $menuitem = $menu->{$item}; + my $olabel = apply { s/.*--// } $item; + my $ml = apply { s/--.*// } $item; + my $icon_class = apply { y/ /-/ } $item; + my $spacer = "s" . (0 + $item =~ s/--/--/g); + + next if $level && $item ne "$level--$olabel"; + + my $label = $::locale->text($olabel); + + $menuitem->{module} ||= $::form->{script}; + $menuitem->{action} ||= "section_menu"; + $menuitem->{href} ||= "$menuitem->{module}?action=$menuitem->{action}"; + + # add other params + foreach my $key (keys %$menuitem) { + next if $key =~ /target|module|action|href/; + $menuitem->{href} .= "&" . $::form->escape($key, 1) . "="; + my ($value, $conf) = split(/=/, $menuitem->{$key}, 2); + $value = $::myconfig{$value} . "/$conf" if ($conf); + $menuitem->{href} .= $::form->escape($value, 1); + } + + my $anchor = $menuitem->{href}; + + my @common_args = ($label, $spacer, "$id_prefix\_$id"); + + if (!$level) { # toplevel + push @items, [ @common_args, "icon24 $icon_class", 'm' ]; + # make_image(size => 24, label => $item), + push @items, section_menu($menu, $item, "$id_prefix\_$id"); + } elsif ($menuitem->{submenu}) { + push @items, [ @common_args, "icon16 submenu", 'sm' ]; + #make_image(label => 'submenu'), + push @items, section_menu($menu, $item, "$id_prefix\_$id"); + } elsif ($menuitem->{module}) { + push @items, [ @common_args, "icon16 $icon_class", 'i', $anchor ]; + #make_image(size => 16, label => $item), + } + } continue { + $id++; + } + + $::lxdebug->leave_sub(2); + return @items; +} + +sub _calc_framesize { + my $is_lynx_browser = $ENV{HTTP_USER_AGENT} =~ /links/i; + my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i; + my $is_mobile_style = $::form->{stylesheet} =~ /mobile/i; + + return $is_mobile_browser && $is_mobile_style ? 130 + : $is_lynx_browser ? 240 + : 200; +} + +sub _show_images { + # don't show images in links + _calc_framesize() != 240; +} + +1; diff --git a/SL/Layout/None.pm b/SL/Layout/None.pm new file mode 100644 index 000000000..57b996669 --- /dev/null +++ b/SL/Layout/None.pm @@ -0,0 +1,27 @@ +package SL::Layout::None; + +use strict; +use parent qw(SL::Layout::Base); + +sub javascripts_inline { + _setup_formats(), + _setup_focus(), +} + + +sub _setup_formats { + $::form->parse_html_template('generic/javascript_setup') +} + +sub _setup_focus { + if ($::request->{layout}->focus || $::form->{fokus}) { + return $::form->parse_html_template('generic/focus_setup', { + focus => $::request->{layout}->focus, + fokus => $::form->{fokus}, + }) + } else { + return (); + } +} + +1; diff --git a/SL/Layout/Top.pm b/SL/Layout/Top.pm new file mode 100644 index 000000000..533977450 --- /dev/null +++ b/SL/Layout/Top.pm @@ -0,0 +1,19 @@ +package SL::Layout::Top; + +use strict; +use parent qw(SL::Layout::Base); + +sub pre_content { + my ($self) = @_; + + $self->SUPER::render('menu/header', { partial => 1, no_output => 1 }, + now => DateTime->now_local, + is_fastcgi => scalar($::dispatcher->interface_type =~ /fastcgi/i), + is_links => scalar($ENV{HTTP_USER_AGENT} =~ /links/i)); +} + +sub stylesheets { +# 'frame_header/header.css'; +} + +1; diff --git a/SL/Layout/V3.pm b/SL/Layout/V3.pm new file mode 100644 index 000000000..78b498e97 --- /dev/null +++ b/SL/Layout/V3.pm @@ -0,0 +1,48 @@ +package SL::Layout::V3; + +use strict; +use parent qw(SL::Layout::Base); +use SL::Layout::Css; + +use URI; + +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); + + $self->add_sub_layouts([ + SL::Layout::None->new, + ]); + + $self; +} + +sub pre_content { + &render; +} + +sub start_content { + "
    \n"; +} + +sub end_content { + "
    \n"; +} + +sub render { + my ($self) = @_; + + my $callback = $::form->unescape($::form->{callback}); + $callback = URI->new($callback)->rel($callback) if $callback; + $callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/; + + $self->SUPER::render('menu/menuv3', { no_menu => 1, no_output => 1 }, + force_ul_width => 1, + date => $self->clock_line, + menu => $self->print_menu, + callback => $callback, + ); +} + +1; diff --git a/SL/Layout/V4.pm b/SL/Layout/V4.pm new file mode 100644 index 000000000..fff1dfe0e --- /dev/null +++ b/SL/Layout/V4.pm @@ -0,0 +1,48 @@ +package SL::Layout::V4; + +use strict; +use parent qw(SL::Layout::Base); +use SL::Layout::Css; +use SL::Layout::Top; + +use URI; + +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); + $self->add_sub_layouts( + SL::Layout::Top->new, + SL::Layout::None->new, + ); + $self; +} + +sub start_content { + "
    \n"; +} + +sub end_content { + "
    \n"; +} + +sub pre_content { + my ($self) = @_; + + $self->{sub_class} = 1; + + my $callback = $::form->unescape($::form->{callback}); + $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, + menu => $self->print_menu, + callback => $callback, + ); +} + +1;