Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[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   my $sections = [ section_menu($self->menu) ];
17   $self->render('menu/menu', { partial => 1, no_output => 1 },
18     sections  => $sections,
19   )
20 }
21
22 sub javascripts {
23  'js/jquery.cookie.js';
24 }
25
26 sub pre_content {
27   "<div id='html-menu'></div>\n";
28 }
29
30 sub start_content {
31   "<div id='content' class='html-menu'>\n";
32 }
33
34 sub end_content {
35   "</div>\n";
36 }
37
38 sub section_menu {
39   $::lxdebug->enter_sub(2);
40   my ($menu, $level, $id_prefix) = @_;
41   my @menuorder = $menu->access_control(\%::myconfig, $level);
42   my @items;
43
44   my $id = 0;
45
46   for my $item (@menuorder) {
47     my $menuitem   = $menu->{$item};
48     my $olabel     = apply { s/.*--// } $item;
49     my $ml         = apply { s/--.*// } $item;
50     my $icon_class = apply { y/ /-/   } $item;
51     my $spacer     = "s" . (0 + $item =~ s/--/--/g);
52
53     next if $level && $item ne "$level--$olabel";
54
55     my $label         = $::locale->text($olabel);
56
57     $menuitem->{module} ||= $::form->{script};
58     $menuitem->{action} ||= "section_menu";
59     $menuitem->{href}   ||= "$menuitem->{module}?action=$menuitem->{action}";
60
61     # add other params
62     foreach my $key (keys %$menuitem) {
63       next if $key =~ /target|module|action|href/;
64       $menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
65       my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
66       $value = $::myconfig{$value} . "/$conf" if ($conf);
67       $menuitem->{href} .= $::form->escape($value, 1);
68     }
69
70     my $anchor = $menuitem->{href};
71
72     my @common_args = ($label, $spacer, "$id_prefix\_$id");
73
74     if (!$level) { # toplevel
75       push @items, [ @common_args, "icon24 $icon_class", 'm' ];
76       #  make_image(size => 24, label => $item),
77       push @items, section_menu($menu, $item, "$id_prefix\_$id");
78     } elsif ($menuitem->{submenu}) {
79       push @items, [ @common_args, "icon16 submenu", 'sm' ];
80       #make_image(label => 'submenu'),
81       push @items, section_menu($menu, $item, "$id_prefix\_$id");
82     } elsif ($menuitem->{module}) {
83       push @items, [ @common_args, "icon16 $icon_class", 'i', $anchor ];
84       #make_image(size => 16, label => $item),
85     }
86   } continue {
87     $id++;
88   }
89
90   $::lxdebug->leave_sub(2);
91   return @items;
92 }
93
94 sub _calc_framesize {
95   my $is_lynx_browser   = $ENV{HTTP_USER_AGENT} =~ /links/i;
96   my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
97   my $is_mobile_style   = $::form->{stylesheet} =~ /mobile/i;
98
99   return  $is_mobile_browser && $is_mobile_style ?  130
100         : $is_lynx_browser                       ?  240
101         :                                           200;
102 }
103
104 sub _show_images {
105   # don't show images in links
106   _calc_framesize() != 240;
107 }
108
109 1;
110
111 __END__
112
113 =encoding utf-8
114
115 =head1 NAME
116
117 SL::Layout::MenuLeft - ex html meanu, now only left menu
118
119 =head1 DOM MODEL
120
121 Data will be embedded into the page as a json array of entries.
122 Each entry is another array with the following fields:
123
124   0: title
125   1: indentation classes
126   2: unique id
127   3: icon classes
128   4: role classes
129
130 From each entry the following dom will be generated, with [0] being entry 0 of
131 the data array:
132
133   <div id="mi[2]" class="mi [4] [1]">
134     <a class="ml">
135       <span class="mii ms">
136         <div class="[3]"></div>
137       </span>
138       <span class="mic">[0]</span>
139     </a>
140   </div>
141
142 The classes are minified to keep the json somewhat in check, their meaning is as follows:
143
144 =over 4
145
146 =item Indentation Classes
147
148   s0: No indentation
149   s1: One level of indentation
150   s2: Two levels of indentation
151
152 =item Icon Classes
153
154 Each icon consists of two classes, one for the icon, and one for the size.
155 The icon classes are taken from the file names, for example C<Master-Data> is
156 the icon for master data, and refers to Master-Icon.png.
157
158   icon16: 16x16 icon
159   icon24: 24x24 icon
160   icon32: 32x32 icon
161
162 =item Role Classes
163
164 Role classes may be used to style types of links differently. Currently used:
165
166   ml:  menu link, any <a> tag will have this
167   mi:  menu item, the enclosing div for each entry has this
168   mii: menu item icon, the enclosing div for the icons has this
169   ms:  menu spacer, the first <span> in the link will have this
170   m:   menu, only top level entries have this
171   i:   item, only leaf entries have this
172   sm:  sub menu, eveything that is not top nor leaf has this
173   mic: menu item content, the span with the human readable description has this
174
175 =back
176
177 =head1 BUGS
178
179 none yet
180
181 =head1 AUTHOR
182
183 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
184
185 =cut