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