From e61046ea9f0efc021d568bbda0f7759ad51881d3 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 10 Nov 2016 13:58:23 -0800 Subject: make menu into a reusable widget --- httemplate/elements/dropdown-menu.html | 241 +++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 httemplate/elements/dropdown-menu.html (limited to 'httemplate/elements/dropdown-menu.html') diff --git a/httemplate/elements/dropdown-menu.html b/httemplate/elements/dropdown-menu.html new file mode 100644 index 000000000..1ba4c00cc --- /dev/null +++ b/httemplate/elements/dropdown-menu.html @@ -0,0 +1,241 @@ + + + + + + +<%init> +my %opt = @_; + +#my $cust_main = $opt{'cust_main'}; +#my $custnum = $cust_main->custnum; +#my $curuser = $FS::CurrentUser::CurrentUser; +#my $conf = FS::Conf->new; +# +#my %payby = map { $_ => 1 } $conf->config('payby'); +# +## cached for conditions, to avoid looking it up twice +#my $invoicing_list_emailonly = $cust_main->invoicing_list_emailonly; + +my @processed_menu; +foreach my $submenu (@{ $opt{menu} }) { + + my @links; + my $first = 1; + foreach my $entry ( @$submenu ) { + # if the menu head was skipped, skip the whole menu + last if (!$first and !@links); + $first = 0; + + my $a = entry2link($entry, \%opt); + push @links, $a if length($a); + + } # foreach $entry + + if (@links) { + push @processed_menu, \@links; + } + +} + +sub entry2link { + my( $entry, $opt ) = @_; + + # check conditions + if ( $entry->{acl} ) { + return '' + unless $FS::CurrentUser::CurrentUser->access_right( $entry->{acl} ); + } + if ( $entry->{confexists} ) { + if ( $entry->{confexists} =~ /^!(.*)/ ) { + # confexists => !foo, a negative condition + return '' if FS::Conf->new->exists( $1 ); + } else { + return '' unless FS::Conf->new->exists( $entry->{confexists} ); + } + } + if ( $entry->{condition} ) { + return '' unless &{ $entry->{condition} }($opt->{cust_main}); + } + + my $label = emt($entry->{label}); + + if ( $entry->{submenu} ) { + + my $a = ''. $label. + ''. + ''; + + } + + my $target = $entry->{content} + || $entry->{popup} + || $entry->{url}; + + if ( ref($target) eq 'CODE' ) { + $target = &$target($opt->{cust_main}); + } + + return $target if $entry->{content}; #the coderef specified the whole thing + + if ( $entry->{show} ) { + + $target = $opt->{self_url}. $entry->{show}; + + my $a = qq[ {show} eq $entry->{show}; + return $a. qq[>$label ]; + + } elsif ( $entry->{popup} ) { + + #$target =~ s/\$custnum/$custnum/g; + $target = $p.$target; + + return include('/elements/popup_link.html', + action => $target, + width => 616, + height => 410, + %$entry, + label => $label, + ); + + } elsif ( $entry->{url} ) { + + #$target =~ s/\$custnum/$custnum/g; + $target = $p.$target; + + return qq[ $label ]; + + } else { + die "bad entry ". join(',',%$entry). " in menu: no url, popup or content"; + } + +} + + -- cgit v1.2.1