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