From 50be11c3574706cae5e219ba910e8221e50da4e8 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Wed, 27 Jun 2007 15:19:55 +0000 Subject: Moving menu.pl to old-handler.pl and adjusting top level scripts accordingly. Including also an unfinished and inactive version of the menu system running under the new architecture. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1334 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB.pm | 5 ++++- LedgerSMB/Menu.pm | 21 ++++++++++---------- UI/menu_expand.html | 56 +++++++++++++++++++++++++---------------------------- menu.pl | 2 +- scripts/menu.pl | 39 +++++++++++++++++++++++++++++++------ 5 files changed, 74 insertions(+), 49 deletions(-) diff --git a/LedgerSMB.pm b/LedgerSMB.pm index 022caeb3..c75482f3 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -214,6 +214,9 @@ sub new { exit; } } + + $self->{stylesheet} = $self->{_user}->{stylesheet}; + $self->_db_init; $self; @@ -248,7 +251,7 @@ sub debug { my $args = shift @_; my $file; if (scalar keys %$args){ - my $file = $args->{'file'}; + $file = $args->{'file'}; } my $d = Data::Dumper->new( [$self] ); $d->Sortkeys(1); diff --git a/LedgerSMB/Menu.pm b/LedgerSMB/Menu.pm index 30aa28c6..5c017a7c 100644 --- a/LedgerSMB/Menu.pm +++ b/LedgerSMB/Menu.pm @@ -48,19 +48,18 @@ sub new { my $orig_key = $key; my $ref = $self; while ($key =~ s/^([^-]*)--//){ - if (!defined $ref->{$1}){ - $ref->{$1} = {}; - } - if (!defined $ref->{$1}->{subs}){ - $ref->{$1}->{subs} = {}; - } - $ref = $ref->{$1}->{subs}; + $ref->{subs} ||= {}; + $ref->{subs}->{$1} ||= {}; + $ref = $ref->{subs}->{$1}; } - for (keys %{$config->{$orig_key}}){ - $ref->{$_} = $config{$orig_key}->{$_}; + $ref->{subs} ||= {}; + $ref->{subs}->{key} ||= {}; + $ref = $ref->{subs}->{$key}; + for (keys %{$config{$orig_key}}){ + $ref->{$_} = ${$config{$orig_key}}{$_}; } - $ref->{$key}{id} = $index; - $ref->{$key}{label} = $key; + $ref->{id} = $index; + $ref->{label} = $key; ++$index; } } diff --git a/UI/menu_expand.html b/UI/menu_expand.html index 7a78e24c..82c82db3 100644 --- a/UI/menu_expand.html +++ b/UI/menu_expand.html @@ -34,38 +34,34 @@ -
- - - - - - + + + + + diff --git a/menu.pl b/menu.pl index 76f60115..e85252cb 100755 --- a/menu.pl +++ b/menu.pl @@ -1,3 +1,3 @@ #!/usr/bin/perl -require "lsmb-request.pl"; +require "old-handler.pl"; diff --git a/scripts/menu.pl b/scripts/menu.pl index 622c0cce..6836c1b4 100644 --- a/scripts/menu.pl +++ b/scripts/menu.pl @@ -44,15 +44,42 @@ sub expanding_menu { template => 'menu_expand', format => 'HTML', ); - $request->{menu_items} = []; - for (keys %$menu){ - push @{$request->{menu_items}}, $menu->{$_}; - } + $request->{subs} = []; + _attach_references({source => $menu, dest => $request->{subs}, path => ""}); $menu->debug({file => '/tmp/debug-menu'}); - $request->{menu_items} = {}; - $request->{menu_items}->{subs} = $menu; $request->debug({file => '/tmp/debug'}); $template->render($request); } +sub _attach_references { + no strict qw(refs); + my ($args) = @_; + my ($source, $dest, $path) + = ($args->{source}, $args->{dest}, $args->{path}); + my %hash; + if ($path and $source->{id}){ + for (sort keys %$source){ + next if $_ eq 'subs'; + $hash{$_} = $source->{$_}; + } + $hash{path} = $path; + push @{$dest}, \%hash; + foreach (sort keys %{$source->{subs}}) { + _attach_references({ + source => $source->{subs}->{$_}, + dest => $dest, + path => "$path--$_", + }); + } + } else { + foreach (sort keys %$source){ + _attach_references({ + source => $source->{$_}, + dest => $dest, + path => "$_", + }); + } + } +} + 1; -- cgit v1.2.3