X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=SL%2FLayout%2FMenuLeft.pm;h=d365210c9332cd61a03cbca2b6dae2daa93aafe8;hb=9096031d4534a25bbd0573c23af1ce24f5ca5ba4;hp=14ee2eac943febef4365ce27be0b5ba15a164c48;hpb=68dbf4a4cb26b9554a23f076438109d7fc2d861c;p=kivitendo-erp.git diff --git a/SL/Layout/MenuLeft.pm b/SL/Layout/MenuLeft.pm index 14ee2eac9..d365210c9 100644 --- a/SL/Layout/MenuLeft.pm +++ b/SL/Layout/MenuLeft.pm @@ -3,26 +3,22 @@ package SL::Layout::MenuLeft; use strict; use parent qw(SL::Layout::Base); -use URI; - use List::MoreUtils qw(apply); +use SL::JSON qw(to_json); +use URI; sub stylesheets { qw(icons16.css icons24.css menu.css) } sub javascripts_inline { - my $self = shift; - my $sections = [ section_menu($self->menu) ]; - $self->presenter->render('menu/menu', - sections => $sections, - ) + "\$(function(){kivi.LeftMenu.init(@{[ to_json([ section_menu($_[0]->menu) ]) ]})});" } sub javascripts { qw( js/jquery.cookie.js - js/switchmenuframe.js + js/kivi.LeftMenu.js ); } @@ -30,65 +26,33 @@ sub pre_content { "
\n"; } -sub start_content { - " \n"; -} - sub section_menu { - $::lxdebug->enter_sub(2); - my ($menu, $level, $id_prefix) = @_; - my @menuorder = $menu->access_control(\%::myconfig, $level); + my ($menu) = @_; my @items; + my @id_stack = (-1); - my $id = 0; - - for my $item (@menuorder) { - my $menuitem = $menu->{$item}; - my $olabel = apply { s/.*--// } $item; - my $ml = apply { s/--.*// } $item; - my $icon_class = apply { $_ =lc $_; s/[^a-z0-9_-]/-/g } $item; - my $spacer = "s" . (0 + $item =~ s/--/--/g); - - next if $level && $item ne "$level--$olabel"; + for my $node ($menu->tree_walk) { + my $level = $node->{level}; - my $label = $::locale->text($olabel); + # do id stack + push @id_stack, -1 if $level > $#id_stack; + pop @id_stack while $level < $#id_stack; + $id_stack[-1]++; - $menuitem->{module} ||= $::form->{script}; - $menuitem->{action} ||= "section_menu"; - $menuitem->{href} ||= "$menuitem->{module}?action=$menuitem->{action}"; - - # add other params - foreach my $key (keys %$menuitem) { - next if $key =~ /target|module|action|href/; - $menuitem->{href} .= "&" . $::form->escape($key, 1) . "="; - my ($value, $conf) = split(/=/, $menuitem->{$key}, 2); - $value = $::myconfig{$value} . "/$conf" if ($conf); - $menuitem->{href} .= $::form->escape($value, 1); - } + my $label = $::locale->text($node->{name}); + my $href = $menu->href_for_node($node); - my @common_args = ($label, $spacer, "$id_prefix\_$id"); + my @common_args = ($label, "s" . $level, join '_', @id_stack); - if (!$level) { # toplevel - push @items, [ @common_args, "icon24 $icon_class", 'm' ]; - # make_image(size => 24, label => $item), - push @items, section_menu($menu, $item, "$id_prefix\_$id"); - } elsif ($menuitem->{submenu}) { + if (!$node->{parent}) { # toplevel + push @items, [ @common_args, "icon24 $node->{icon}", 'm' ]; + } elsif ($node->{children}) { push @items, [ @common_args, "icon16 submenu", 'sm' ]; - #make_image(label => 'submenu'), - push @items, section_menu($menu, $item, "$id_prefix\_$id"); - } elsif ($menuitem->{module}) { - push @items, [ @common_args, "icon16 $icon_class", 'i', $menuitem->{href}, $menuitem->{target} ]; - #make_image(size => 16, label => $item), + } else { + push @items, [ @common_args, "icon16 $node->{icon}", 'i', $href, $node->{target} ]; } - } continue { - $id++; } - $::lxdebug->leave_sub(2); return @items; }