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