Overhaul message box handling

This commit is contained in:
Chris 2016-12-30 12:42:25 +00:00
parent 1c7df6b102
commit e8b06a386c

View File

@ -133,76 +133,88 @@ sub generate_orb_page {
} }
## @method $ generate_errorbox($message, $title) ## @method $ generate_errorbox(%args)
# Generate the HTML to show in the page when a fatal error has been encountered. # Generate the HTML to show in the page when a fatal error has been encountered.
# The following options can be specified in the arguments:
# #
# @param message The message to show in the page. # - `message`: The message to show in the page.
# @param title The title to use for the error. If not set "{L_FATAL_ERROR}" is used. # - `title`: The title to use for the error. If not set "{L_FATAL_ERROR}" is used.
#
# @param args A hash, or reference to a hash, of options.
# @return A string containing the page # @return A string containing the page
sub generate_errorbox { sub generate_errorbox {
my $self = shift; my $self = shift;
my $message = shift; my $args = hash_or_hashref(@_);
my $title = shift || "{L_FATAL_ERROR}";
$self -> log("error:fatal", $message); $self -> log("error:fatal", $args -> {"message"});
$message = $self -> message_boc($title, return $self -> message_box(title => $args -> {"title"} // "{L_FATAL_ERROR}",
"error", type => "error",
"{L_FATAL_ERROR_SUMMARY}", summary => "{L_FATAL_ERROR_SUMMARY}",
$message, message => $args -> {"message"},
undef, buttons => [ { "message" => $self -> {"template"} -> replace_langvar("SITE_CONTINUE"),
"errorcore", "colour" => "standard",
[ {"message" => $self -> {"template"} -> replace_langvar("SITE_CONTINUE"), "href" => "{V_[scriptpath]}"
"colour" => "blue", }
"action" => "location.href='{V_[scriptpath]}'"} ]); ]);
my $userbar = $self -> {"module"} -> load_module("ORB::Userbar");
# Build the error page...
return $self -> {"template"} -> load_template("page.tem",
{"%(title)s" => $title,
"%(content)s" => $message,
"%(extrahead)s" => "",
"%(extrajs)s" => "",
"%(userbar)s" => ($userbar ? $userbar -> block_display($title) : "<!-- Userbar load failed: ".$self -> {"module"} -> errstr()." -->"),
});
} }
## @method $ generate_multiselect($name, $class, $idbase, $options, $selected) ## @method $ message_box(%args)
# Generate a MultiSelect dropdown list (essentially a list of checkboxes that gets # Create a message box block to include in a page. This generates a templated
# converted to a dropdown using the MultiSelect javascript module). # message box to include in a page. It assumes the presence of messagebox.tem
# in the template directory, containing markers for a title, type, summary,
# long description and additional data. The type argument should correspond
# to an image in the {template}/images/messages/ directory without an extension.
# Supported arguments are:
# #
# @param name The name of the multiselect option list. # - `title`: The title of the message box.
# @param class A class to add to the class attribute for the checkboxes in the list. # - `type`: The message type.
# @param idbase A unique base name for the ID of checkboxes in the list. # - `class`: Optional additional classes to set on the box.
# @param options A reference to an array of option hashes. Each hash should contain # - `summary`: A summary version of the message.
# `name` a short name used in the class, `id` a numeric ID used in the # - `message`: The full message body
# id and value attributes, and `desc` used in the label. # - `additional`: Any additional content to include in the message box.
# @param selected A reference to a list of selected option IDs. # - `buttons`: Optional reference to an array of hashes containing button
# @return A string containing the multiselect list checkboxes. # data. Each hash in the array should contain three keys:
sub generate_multiselect { # - `colour`: specifies the button colour
my $self = shift; # - `href`: the href to set in the button
my $name = shift; # - `message`: the message to show in the button.
my $class = shift; #
my $idbase = shift; # @param args A hash, or reference to a hash, of arguments.
my $options = shift; # @return A string containing the message box.
my $selected = shift; sub message_box {
my $self = shift;
my $args = hash_or_hashref(@_);
# Convert the selected list to a hash for faster lookup my $buttonbar = "";
my %active = map { $_ => 1} @{$selected};
my $result = ""; # Has the caller specified any buttons?
foreach my $option (@{$options}) { if($args -> {"buttons"}) {
$result .= $self -> {"template"} -> load_template("multisel-item.tem", {"%(class)s" => $class,
"%(idbase)s" => $idbase, # Build the list of buttons...
"%(selname)s" => $name, my $buttonlist = "";
"%(name)s" => $option -> {"name"}, foreach my $button (@{$args -> {"buttons"}}) {
"%(id)s" => $option -> {"id"}, $buttonlist .= $self -> load_template("messagebox/button.tem",
"%(desc)s" => $option -> {"desc"}, { "%(colour)s" => $button -> {"colour"},
"%(checked)s" => $active{$option -> {"id"}} ? 'checked="checked"' : ''}); "%(href)s" => $button -> {"href"},
"%(message)s" => $button -> {"message"}
});
}
# Shove into the bar
$buttonbar = $self -> load_template("messagebox/buttonbar.tem",
{ "%(buttons)s" => $buttonlist });
} }
return $result; return $self -> load_template("messagebox/box.tem",
{ "%(title)s" => $args -> {"title"},
"%(icon)s" => $args -> {"type"},
"%(summary)s" => $args -> {"summary"},
"%(longdesc)s" => $args -> {"message"},
"%(additional)s" => $args -> {"additional"},
"%(buttons)s" => $args -> {"buttonbar"},
"%(class)s" => $args -> {"class"},
});
} }