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