stylesheet/javascript handling verbessert
[kivitendo-erp.git] / SL / Controller / Layout / MenuLeft.pm
1 package SL::Controller::Layout::MenuLeft;
2
3 use strict;
4 use parent qw(SL::Controller::Layout::Base);
5
6 use URI;
7
8 use List::MoreUtils qw(apply);
9
10 sub new {
11   my ($class, @slurp) = @_;
12
13   my $self = $class->SUPER::new(@slurp);
14
15   $self->use_stylesheet(qw(css/icons16.css css/icons24.css));
16
17   $self;
18 }
19
20 sub render {
21   my ($self) = @_;
22   my $sections = [ section_menu($self->menu) ];
23
24   $self->SUPER::render('menu/menu', { no_menu => 1, no_output => 1 },
25     sections  => $sections,
26   );
27 }
28
29 sub section_menu {
30   $::lxdebug->enter_sub(2);
31   my ($menu, $level, $id_prefix) = @_;
32   my @menuorder = $menu->access_control(\%::myconfig, $level);
33   my @items;
34
35   my $id = 0;
36
37   for my $item (@menuorder) {
38     my $menuitem   = $menu->{$item};
39     my $olabel     = apply { s/.*--// } $item;
40     my $ml         = apply { s/--.*// } $item;
41     my $icon_class = apply { y/ /-/   } $item;
42     my $spacer     = "s" . (0 + $item =~ s/--/--/g);
43
44     next if $level && $item ne "$level--$olabel";
45
46     my $label         = $::locale->text($olabel);
47
48     $menuitem->{module} ||= $::form->{script};
49     $menuitem->{action} ||= "section_menu";
50     $menuitem->{href}   ||= "$menuitem->{module}?action=$menuitem->{action}";
51
52     # add other params
53     foreach my $key (keys %$menuitem) {
54       next if $key =~ /target|module|action|href/;
55       $menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
56       my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
57       $value = $::myconfig{$value} . "/$conf" if ($conf);
58       $menuitem->{href} .= $::form->escape($value, 1);
59     }
60
61     my $anchor = $menuitem->{href};
62
63     my %common_args = (
64         l   => $label,
65         s  => $spacer,
66         id => "$id_prefix\_$id",
67     );
68
69     if (!$level) { # toplevel
70       push @items, { %common_args,
71         i      => "icon24 $icon_class",   #  make_image(size => 24, label => $item),
72         c    => 'm',
73       };
74       push @items, section_menu($menu, $item, "$id_prefix\_$id");
75     } elsif ($menuitem->{submenu}) {
76       push @items, { %common_args,
77         i      => "icon16 submenu",   #make_image(label => 'submenu'),
78         c    => 'sm',
79       };
80       push @items, section_menu($menu, $item, "$id_prefix\_$id");
81     } elsif ($menuitem->{module}) {
82       push @items, { %common_args,
83         i     => "icon16 $icon_class",  #make_image(size => 16, label => $item),
84         h    => $anchor,
85         c   => 'i',
86       };
87     }
88   } continue {
89     $id++;
90   }
91
92   $::lxdebug->leave_sub(2);
93   return @items;
94 }
95
96 sub _calc_framesize {
97   my $is_lynx_browser   = $ENV{HTTP_USER_AGENT} =~ /links/i;
98   my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
99   my $is_mobile_style   = $::form->{stylesheet} =~ /mobile/i;
100
101   return  $is_mobile_browser && $is_mobile_style ?  130
102         : $is_lynx_browser                       ?  240
103         :                                           200;
104 }
105
106 sub _show_images {
107   # don't show images in links
108   _calc_framesize() != 240;
109 }
110
111 1;