Refactoring: Parameterredesign SL::Controller::Base::render und SL::Presenter::render
[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', { output => 0 },
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 @common_args = ($label, $spacer, "$id_prefix\_$id");
74
75     if (!$level) { # toplevel
76       push @items, [ @common_args, "icon24 $icon_class", 'm' ];
77       #  make_image(size => 24, label => $item),
78       push @items, section_menu($menu, $item, "$id_prefix\_$id");
79     } elsif ($menuitem->{submenu}) {
80       push @items, [ @common_args, "icon16 submenu", 'sm' ];
81       #make_image(label => 'submenu'),
82       push @items, section_menu($menu, $item, "$id_prefix\_$id");
83     } elsif ($menuitem->{module}) {
84       push @items, [ @common_args, "icon16 $icon_class", 'i', $menuitem->{href}, $menuitem->{target} ];
85       #make_image(size => 16, label => $item),
86     }
87   } continue {
88     $id++;
89   }
90
91   $::lxdebug->leave_sub(2);
92   return @items;
93 }
94
95 sub _calc_framesize {
96   my $is_lynx_browser   = $ENV{HTTP_USER_AGENT} =~ /links/i;
97   my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
98   my $is_mobile_style   = $::form->{stylesheet} =~ /mobile/i;
99
100   return  $is_mobile_browser && $is_mobile_style ?  130
101         : $is_lynx_browser                       ?  240
102         :                                           200;
103 }
104
105 sub _show_images {
106   # don't show images in links
107   _calc_framesize() != 240;
108 }
109
110 1;
111
112 __END__
113
114 =encoding utf-8
115
116 =head1 NAME
117
118 SL::Layout::MenuLeft - ex html meanu, now only left menu
119
120 =head1 DOM MODEL
121
122 Data will be embedded into the page as a json array of entries.
123 Each entry is another array with the following fields:
124
125   0: title
126   1: indentation classes
127   2: unique id
128   3: icon classes
129   4: role classes
130   5: href
131   6: target
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