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