From 7b2db40ff179a041e0a987d792b979fdd3d5beae Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 22 May 2018 00:33:10 +0100 Subject: [PATCH] Add more convenient handling of page menus As the page menu appears basically everywhere, this allows it to be generated in one place - the page container generator - rather than all over the shop --- blocks/ORB/List.pm | 13 +++++++------ modules/ORB.pm | 10 ++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/blocks/ORB/List.pm b/blocks/ORB/List.pm index d291d1d..9e93853 100644 --- a/blocks/ORB/List.pm +++ b/blocks/ORB/List.pm @@ -104,12 +104,12 @@ sub _generate_list { # And build the template fragments from that list return ($self -> {"template"} -> replace_langvar("LIST_TITLE", { "%(page)s" => uc($mode // "All") }), $self -> {"template"} -> load_template("list/content.tem", - { "%(pagemenu)s" => $self -> pagemenu($mode), - "%(page)s" => uc($mode // "All"), + { "%(page)s" => uc($mode // "All"), "%(recipes)s" => join("", map { $self -> _build_recipe($_) } @{$recipes}), }), $self -> {"template"} -> load_template("list/extrahead.tem"), $self -> {"template"} -> load_template("list/extrajs.tem"), + uc($mode // "All") ); } @@ -127,22 +127,22 @@ sub _dispatch_ui { my $self = shift; # We need to determine what the page title should be, and the content to shove in it... - my ($title, $body, $extrahead, $extrajs) = ("", "", "", ""); + my ($title, $body, $extrahead, $extrajs, $page) = ("", "", "", "", "all"); if($self -> check_permission("recipe.view")) { my @pathinfo = $self -> {"cgi"} -> multi_param("pathinfo"); # If the pathinfo contains a recognised page character, use that if(defined($pathinfo[0]) && $pathinfo[0] =~ /^[0a-zA-Z\$]$/) { - ($title, $body, $extrahead, $extrajs) = $self -> _generate_list($pathinfo[0]); + ($title, $body, $extrahead, $extrajs, $page) = $self -> _generate_list($pathinfo[0]); # If th euser has requested all recipes, do no filtering } elsif($pathinfo[0] && lc($pathinfo[0]) eq "all") { - ($title, $body, $extrahead, $extrajs) = $self -> _generate_list(); + ($title, $body, $extrahead, $extrajs, $page) = $self -> _generate_list(); # Otherwise fall back on the default of 'A' recipes } else { - ($title, $body, $extrahead, $extrajs) = $self -> _generate_list('A'); + ($title, $body, $extrahead, $extrajs, $page) = $self -> _generate_list('A'); } } else { @@ -154,6 +154,7 @@ sub _dispatch_ui { content => $body, extrahead => $extrahead, extrajs => $extrajs, + active => $page, doclink => 'list'); } diff --git a/modules/ORB.pm b/modules/ORB.pm index 69676bb..1d7698c 100755 --- a/modules/ORB.pm +++ b/modules/ORB.pm @@ -129,6 +129,7 @@ sub generate_orb_page { return $self -> {"template"} -> load_template("page.tem", {"%(extrahead)s" => $args -> {"extrahead"} // "", "%(extrajs)s" => $args -> {"extrajs"} // "", "%(title)s" => $args -> {"title"} // "", + "%(pagemenu)s" => $self -> pagemenu($args -> {"active"}), "%(leftmenu)s" => $leftbar, "%(userbar)s" => $topbar, "%(content)s" => $args -> {"content"}}); @@ -226,11 +227,16 @@ sub message_box { ## @method $ pagemenu($active) # Create a page menu to include at the top of pages that need menu listing pages # -# @param active The active page letter, or undef if none are active. +# @param active The active page letter, and empty string or "all" for all, or +# undef if none are active. # @return A string containing the page menu sub pagemenu { my $self = shift; - my $active = shift // "all"; + my $active = shift; + + return "" if(!defined($active)); + + $active ||= "all"; my $pages = ""; foreach my $page ("0", "A" ... "Z", "All") {