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 {
+sub static_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 {
+sub static_javascripts {
qw(
js/jquery.cookie.js
- js/switchmenuframe.js
+ js/kivi.LeftMenu.js
);
}
"<div id='html-menu'></div>\n";
}
-sub start_content {
- "<div id='content' class='html-menu'>\n";
-}
-
-sub end_content {
- "</div>\n";
-}
-
sub section_menu {
my ($menu) = @_;
- my @menuorder = @{ $menu->{ORDER} };
my @items;
my @id_stack = (-1);
- 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 } $menuitem->{ICON};
- my $level = (0 + $item =~ s/--/--/g);
- my $spacer = "s" . $level;
+ for my $node ($menu->tree_walk) {
+ my $level = $node->{level};
# 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);
-
- $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|ICON/;
- $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, join '_', @id_stack);
+ my @common_args = ($label, "s" . $level, join '_', @id_stack);
- if ($spacer eq 's0') { # toplevel
- push @items, [ @common_args, "icon24 $icon_class", 'm' ];
- } 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' ];
- } elsif ($menuitem->{module}) {
- push @items, [ @common_args, "icon16 $icon_class", 'i', $menuitem->{href}, $menuitem->{target} ];
+ } else {
+ push @items, [ @common_args, "icon16 $node->{icon}", 'i', $href, $node->{target} ];
}
}