X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLayout%2FMenuLeft.pm;h=d365210c9332cd61a03cbca2b6dae2daa93aafe8;hb=770cfea95d02adbaa8e6ebfddd39ef9e52252b97;hp=6764e2fe94a006e766ce1c734f4c227560c1789d;hpb=dc4b933b9b8b6cc61cb00ab3505ed775afed52b6;p=kivitendo-erp.git diff --git a/SL/Layout/MenuLeft.pm b/SL/Layout/MenuLeft.pm index 6764e2fe9..d365210c9 100644 --- a/SL/Layout/MenuLeft.pm +++ b/SL/Layout/MenuLeft.pm @@ -3,91 +3,56 @@ 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->render('menu/menu', { partial => 1, no_output => 1 }, - sections => $sections, - ) + "\$(function(){kivi.LeftMenu.init(@{[ to_json([ section_menu($_[0]->menu) ]) ]})});" } sub javascripts { - 'js/jquery.cookie.js'; + qw( + js/jquery.cookie.js + js/kivi.LeftMenu.js + ); } sub pre_content { "
\n"; } -sub start_content { - "
\n"; -} - -sub end_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 { y/ /-/ } $item; - my $spacer = "s" . (0 + $item =~ s/--/--/g); + for my $node ($menu->tree_walk) { + my $level = $node->{level}; - next if $level && $item ne "$level--$olabel"; + # do id stack + push @id_stack, -1 if $level > $#id_stack; + pop @id_stack while $level < $#id_stack; + $id_stack[-1]++; - my $label = $::locale->text($olabel); + my $label = $::locale->text($node->{name}); + my $href = $menu->href_for_node($node); - $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 @common_args = ($label, "s" . $level, join '_', @id_stack); - my $anchor = $menuitem->{href}; - - my @common_args = ($label, $spacer, "$id_prefix\_$id"); - - 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', $anchor ]; - #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; } @@ -107,3 +72,81 @@ sub _show_images { } 1; + +__END__ + +=encoding utf-8 + +=head1 NAME + +SL::Layout::MenuLeft - ex html meanu, now only left menu + +=head1 DOM MODEL + +Data will be embedded into the page as a json array of entries. +Each entry is another array with the following fields: + + 0: title + 1: indentation classes + 2: unique id + 3: icon classes + 4: role classes + 5: href + 6: target + +From each entry the following dom will be generated, with [0] being entry 0 of +the data array: + +
+ + +
+
+ [0] +
+
+ +The classes are minified to keep the json somewhat in check, their meaning is as follows: + +=over 4 + +=item Indentation Classes + + s0: No indentation + s1: One level of indentation + s2: Two levels of indentation + +=item Icon Classes + +Each icon consists of two classes, one for the icon, and one for the size. +The icon classes are taken from the file names, for example C is +the icon for master data, and refers to Master-Icon.png. + + icon16: 16x16 icon + icon24: 24x24 icon + icon32: 32x32 icon + +=item Role Classes + +Role classes may be used to style types of links differently. Currently used: + + ml: menu link, any tag will have this + mi: menu item, the enclosing div for each entry has this + mii: menu item icon, the enclosing div for the icons has this + ms: menu spacer, the first in the link will have this + m: menu, only top level entries have this + i: item, only leaf entries have this + sm: sub menu, eveything that is not top nor leaf has this + mic: menu item content, the span with the human readable description has this + +=back + +=head1 BUGS + +none yet + +=head1 AUTHOR + +Sven Schoeling Es.schoeling@linet-services.deE + +=cut