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