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