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
This commit is contained in:
Chris 2018-05-22 00:33:10 +01:00
parent 095f45db3b
commit 7b2db40ff1
2 changed files with 15 additions and 8 deletions

View File

@ -104,12 +104,12 @@ sub _generate_list {
# And build the template fragments from that list # And build the template fragments from that list
return ($self -> {"template"} -> replace_langvar("LIST_TITLE", { "%(page)s" => uc($mode // "All") }), return ($self -> {"template"} -> replace_langvar("LIST_TITLE", { "%(page)s" => uc($mode // "All") }),
$self -> {"template"} -> load_template("list/content.tem", $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}), "%(recipes)s" => join("", map { $self -> _build_recipe($_) } @{$recipes}),
}), }),
$self -> {"template"} -> load_template("list/extrahead.tem"), $self -> {"template"} -> load_template("list/extrahead.tem"),
$self -> {"template"} -> load_template("list/extrajs.tem"), $self -> {"template"} -> load_template("list/extrajs.tem"),
uc($mode // "All")
); );
} }
@ -127,22 +127,22 @@ sub _dispatch_ui {
my $self = shift; my $self = shift;
# We need to determine what the page title should be, and the content to shove in it... # 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")) { if($self -> check_permission("recipe.view")) {
my @pathinfo = $self -> {"cgi"} -> multi_param("pathinfo"); my @pathinfo = $self -> {"cgi"} -> multi_param("pathinfo");
# If the pathinfo contains a recognised page character, use that # If the pathinfo contains a recognised page character, use that
if(defined($pathinfo[0]) && $pathinfo[0] =~ /^[0a-zA-Z\$]$/) { 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 # If th euser has requested all recipes, do no filtering
} elsif($pathinfo[0] && lc($pathinfo[0]) eq "all") { } 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 # Otherwise fall back on the default of 'A' recipes
} else { } else {
($title, $body, $extrahead, $extrajs) = $self -> _generate_list('A'); ($title, $body, $extrahead, $extrajs, $page) = $self -> _generate_list('A');
} }
} else { } else {
@ -154,6 +154,7 @@ sub _dispatch_ui {
content => $body, content => $body,
extrahead => $extrahead, extrahead => $extrahead,
extrajs => $extrajs, extrajs => $extrajs,
active => $page,
doclink => 'list'); doclink => 'list');
} }

View File

@ -129,6 +129,7 @@ sub generate_orb_page {
return $self -> {"template"} -> load_template("page.tem", {"%(extrahead)s" => $args -> {"extrahead"} // "", return $self -> {"template"} -> load_template("page.tem", {"%(extrahead)s" => $args -> {"extrahead"} // "",
"%(extrajs)s" => $args -> {"extrajs"} // "", "%(extrajs)s" => $args -> {"extrajs"} // "",
"%(title)s" => $args -> {"title"} // "", "%(title)s" => $args -> {"title"} // "",
"%(pagemenu)s" => $self -> pagemenu($args -> {"active"}),
"%(leftmenu)s" => $leftbar, "%(leftmenu)s" => $leftbar,
"%(userbar)s" => $topbar, "%(userbar)s" => $topbar,
"%(content)s" => $args -> {"content"}}); "%(content)s" => $args -> {"content"}});
@ -226,11 +227,16 @@ sub message_box {
## @method $ pagemenu($active) ## @method $ pagemenu($active)
# Create a page menu to include at the top of pages that need menu listing pages # 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 # @return A string containing the page menu
sub pagemenu { sub pagemenu {
my $self = shift; my $self = shift;
my $active = shift // "all"; my $active = shift;
return "" if(!defined($active));
$active ||= "all";
my $pages = ""; my $pages = "";
foreach my $page ("0", "A" ... "Z", "All") { foreach my $page ("0", "A" ... "Z", "All") {