Revision 5d73281e
Von Sven Schöling vor etwa 12 Jahren hinzugefügt
bin/mozilla/menu.pl | ||
---|---|---|
44 | 44 |
|
45 | 45 |
use List::MoreUtils qw(apply); |
46 | 46 |
|
47 |
my $nbsp = ' '; |
|
48 |
|
|
49 | 47 |
# end of main |
50 | 48 |
|
51 | 49 |
sub display { |
... | ... | |
83 | 81 |
$::form->{title} = $::locale->text('kivitendo'); |
84 | 82 |
$::form->header; |
85 | 83 |
|
86 |
my $sections = section_menu($menu);
|
|
84 |
my $sections = [ section_menu($menu) ];
|
|
87 | 85 |
|
88 | 86 |
print $::form->parse_html_template('menu/menu', { |
89 | 87 |
framesize => $framesize, |
... | ... | |
95 | 93 |
|
96 | 94 |
sub section_menu { |
97 | 95 |
$::lxdebug->enter_sub; |
98 |
my ($menu, $level) = @_; |
|
96 |
my ($menu, $level, $id_prefix) = @_;
|
|
99 | 97 |
my @menuorder = $menu->access_control(\%::myconfig, $level); |
100 | 98 |
my @items; |
101 | 99 |
|
100 |
my $id = 0; |
|
101 |
|
|
102 | 102 |
for my $item (@menuorder) { |
103 | 103 |
my $menuitem = $menu->{$item}; |
104 | 104 |
my $label = apply { s/.*--// } $item; |
105 | 105 |
my $ml = apply { s/--.*// } $item; |
106 |
my $spacer = "spacer" . (0 + $item =~ s/--/--/g);
|
|
106 |
my $spacer = "s" . (0 + $item =~ s/--/--/g); |
|
107 | 107 |
my $label_icon = $level . "--" . $label . ".png"; |
108 | 108 |
|
109 | 109 |
next if $level && $item ne "$level--$label"; |
... | ... | |
126 | 126 |
|
127 | 127 |
my $anchor = $menuitem->{href}; |
128 | 128 |
|
129 |
my %common_args = ( |
|
130 |
label => $label, |
|
131 |
spacer => $spacer, |
|
132 |
target => $menuitem->{target}, |
|
133 |
item_id => "$id_prefix\_$id", |
|
134 |
height => 16, |
|
135 |
); |
|
136 |
|
|
129 | 137 |
if (!$level) { # toplevel |
130 |
push @items, make_item(
|
|
138 |
push @items, { %common_args,
|
|
131 | 139 |
img => make_image(icon => $item . '.png', size => 24, label => $label), |
132 |
label => $label, |
|
133 | 140 |
height => 24, |
134 |
class => 'menu', |
|
135 |
spacer => $spacer, |
|
136 |
subitems => section_menu($menu, $item) |
|
137 |
); |
|
141 |
class => 'm', |
|
142 |
}; |
|
143 |
push @items, section_menu($menu, $item, "$id_prefix\_$id"); |
|
138 | 144 |
} elsif ($menuitem->{submenu}) { |
139 |
push @items, make_item( |
|
140 |
target => $menuitem->{target}, |
|
141 |
spacer => $spacer, |
|
145 |
push @items, { %common_args, |
|
142 | 146 |
img => make_image(submenu => 1), |
143 |
label => $label, |
|
144 |
class => 'submenu', |
|
145 |
subitems => section_menu($menu, $item), |
|
146 |
); |
|
147 |
class => 'sm', |
|
148 |
}; |
|
149 |
push @items, section_menu($menu, $item, "$id_prefix\_$id"); |
|
147 | 150 |
} elsif ($menuitem->{module}) { |
148 |
push @items, make_item( |
|
149 |
target => $menuitem->{target}, |
|
150 |
img => make_image(label => $label, icon => $label_icon), |
|
151 |
href => $anchor, |
|
152 |
spacer => $spacer, |
|
153 |
label => $label, |
|
154 |
class => 'item', |
|
155 |
); |
|
151 |
push @items, { %common_args, |
|
152 |
img => make_image(label => $label, icon => $label_icon), |
|
153 |
href => $anchor, |
|
154 |
class => 'i', |
|
155 |
}; |
|
156 | 156 |
} |
157 |
} continue { |
|
158 |
$id++; |
|
157 | 159 |
} |
158 |
$::lxdebug->leave_sub; |
|
159 |
return \@items; |
|
160 |
} |
|
161 |
|
|
162 |
sub make_item { |
|
163 |
my %params = @_; |
|
164 |
$params{spacer} ||= ''; |
|
165 |
$params{height} ||= 16; |
|
166 | 160 |
|
167 |
return { |
|
168 |
%params, |
|
169 |
# chunks => [ multiline($params{label}) ], |
|
170 |
}; |
|
171 |
} |
|
172 |
|
|
173 |
# multi line hack, sschoeling jul06 |
|
174 |
# if a label is too long, try to split it at whitespaces, then join it to chunks of less |
|
175 |
# than 20 chars and store it in an array. |
|
176 |
# use this array later instead of the -ed label |
|
177 |
sub multiline { |
|
178 |
my ($label) = @_; |
|
179 |
my @chunks; |
|
180 |
my $l = 20; |
|
181 |
for (split / /, $label) { |
|
182 |
$l += length $_; |
|
183 |
if ($l < 20) { |
|
184 |
$chunks[-1] .= " $_"; |
|
185 |
} else { |
|
186 |
$l = length $_; |
|
187 |
push @chunks, $_; |
|
188 |
} |
|
189 |
} |
|
190 |
return @chunks; |
|
161 |
$::lxdebug->leave_sub; |
|
162 |
return @items; |
|
191 | 163 |
} |
192 | 164 |
|
193 | 165 |
sub make_image { |
... | ... | |
199 | 171 |
return unless _show_images(); |
200 | 172 |
|
201 | 173 |
my $icon_found = $icon && -f _icon_path($icon, $size); |
202 |
my $padding = $size == 16 && $icon_found ? $nbsp x 2 |
|
203 |
: $size == 24 ? $nbsp |
|
204 |
: ''; |
|
205 | 174 |
|
206 | 175 |
return { |
207 | 176 |
src => $icon_found ? _icon_path($icon, $size) : "image/unterpunkt.png", |
Auch abrufbar als: Unified diff
menu.pl aufgeräumt
request ist jetzt auf netto 20ms zum herstellen des menüs und nochmal ein 30ms
zum rendern. bei letzterem hoffe ich dass das beim einbinden in ein template
beschleunigt wird.