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