9a47d292dfa6dc2409857781fe0b40c6b417e1a3
[kivitendo-erp.git] / SL / Layout / MenuLeft.pm
1 package SL::Layout::MenuLeft;
2
3 use strict;
4 use parent qw(SL::Layout::Base);
5
6 use URI;
7
8 use List::MoreUtils qw(apply);
9
10 sub stylesheets {
11   qw(icons16.css icons24.css menu.css)
12 }
13
14 sub javascripts_inline {
15   my $self = shift;
16   $self->SUPER::javascripts_inline;
17   my $sections = [ section_menu($self->menu) ];
18   $self->presenter->render('menu/menu',
19     sections  => $sections,
20   )
21 }
22
23 sub javascripts {
24   qw(
25     js/jquery.cookie.js
26     js/switchmenuframe.js
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 @common_args = ($label, $spacer, "$id_prefix\_$id");
75
76     if (!$level) { # toplevel
77       push @items, [ @common_args, "icon24 $icon_class", 'm' ];
78       #  make_image(size => 24, label => $item),
79       push @items, section_menu($menu, $item, "$id_prefix\_$id");
80     } elsif ($menuitem->{submenu}) {
81       push @items, [ @common_args, "icon16 submenu", 'sm' ];
82       #make_image(label => 'submenu'),
83       push @items, section_menu($menu, $item, "$id_prefix\_$id");
84     } elsif ($menuitem->{module}) {
85       push @items, [ @common_args, "icon16 $icon_class", 'i', $menuitem->{href}, $menuitem->{target} ];
86       #make_image(size => 16, label => $item),
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;
112
113 __END__
114
115 =encoding utf-8
116
117 =head1 NAME
118
119 SL::Layout::MenuLeft - ex html meanu, now only left menu
120
121 =head1 DOM MODEL
122
123 Data will be embedded into the page as a json array of entries.
124 Each entry is another array with the following fields:
125
126   0: title
127   1: indentation classes
128   2: unique id
129   3: icon classes
130   4: role classes
131   5: href
132   6: target
133
134 From each entry the following dom will be generated, with [0] being entry 0 of
135 the data array:
136
137   <div id="mi[2]" class="mi [4] [1]">
138     <a class="ml">
139       <span class="mii ms">
140         <div class="[3]"></div>
141       </span>
142       <span class="mic">[0]</span>
143     </a>
144   </div>
145
146 The classes are minified to keep the json somewhat in check, their meaning is as follows:
147
148 =over 4
149
150 =item Indentation Classes
151
152   s0: No indentation
153   s1: One level of indentation
154   s2: Two levels of indentation
155
156 =item Icon Classes
157
158 Each icon consists of two classes, one for the icon, and one for the size.
159 The icon classes are taken from the file names, for example C<Master-Data> is
160 the icon for master data, and refers to Master-Icon.png.
161
162   icon16: 16x16 icon
163   icon24: 24x24 icon
164   icon32: 32x32 icon
165
166 =item Role Classes
167
168 Role classes may be used to style types of links differently. Currently used:
169
170   ml:  menu link, any <a> tag will have this
171   mi:  menu item, the enclosing div for each entry has this
172   mii: menu item icon, the enclosing div for the icons has this
173   ms:  menu spacer, the first <span> in the link will have this
174   m:   menu, only top level entries have this
175   i:   item, only leaf entries have this
176   sm:  sub menu, eveything that is not top nor leaf has this
177   mic: menu item content, the span with the human readable description has this
178
179 =back
180
181 =head1 BUGS
182
183 none yet
184
185 =head1 AUTHOR
186
187 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
188
189 =cut