Name
Web::Components::Navigation - Context sensitive menu builder
Synopsis
use Web::Components::Navigation;
Description
Context sensitive menu builder
JavaScript
Files wcom-*.js are included in the share/js directory of the source tree. These will be installed to the File::ShareDir distribution level shared data files. Nothing further is done with these files. They should be concatenated in sort order by filename and the result placed under the webservers document root. Link to this from the web applications pages. Doing this is outside the scope of this distribution
Configuration and Environment
Defines the following attributes;
confirm_message- 
Immutable string. The default "Are you sure ?" message
 container_class- 
Lazy string combining
container_nameandcontainer_layout. This can be applied as a class name to the HTML container element by the application's page layout template container_layout- 
A mutable string which defaults to
centred. Used as a class name in the HTML it is also shared with the JS code container_name- 
An immutable string which defaults to
standard. Used as a class name in the HTML it is also shared with the JS code container_tag- 
An immutable string which default to
div. The HTML element to render content_class- 
A lazy immutable string which defaults to
content_name content_name- 
An immutable string which defaults to
panel. Used as an id and a class name in the HTML it is also shared with the JS code context- 
An immutable required weak reference to the
contextobject control_icon- 
An immutable string which defaults to
user-settings. The name of the symbol in the SVG icons file for the user settings menu global- 
An immutable array reference with an empty default. Contains a list of action paths used to create the top level of the navigation menus. It is expected that this will be populated at object construction time
 icons- 
A lazy string representation of a partial URI. This should point to an SVG file containing named symbols. Defaults to
img/icons.svg json_view- 
An immutable string which defaults to
json. Stashed byfinaliseas the view which will serialise the response as JSON link_display- 
A lazy string which defaults to either the value is the
sessionif it exists or the stringboth. An enumerated type with values;both,icon, ortext. Controls how theglobalmenu display links logo- 
A optional lazy string representation of a partial URI with a null default. This should point to an image file containing the logo if one is required
 media_break- 
An immutable positive integer with a default of
680pixels. When the display window's <innerWidth> drop below this (due to a resize event)link_displayis set toiconwhich reduces the display width requirement - 
A lazy string which defaults to
header. Can be set tosidebar. Effects where the navigation menus are rendered message_action- 
An immutable string which defaults to
api/navigation_messages. This is the action path for the API call that the message object in the JS will make to collect messages messages- 
An immutable hash reference with an empty default. The attributes are used to configure the JS message collection and display code. Attributes are;
 model- 
An immutable required object reference to the model component that is handling the current request
 title- 
An immutable string which defaults to null. If set will be displayed as the application title along with the logo in the page header
 title_abbrev- 
An immutable string which defaults to
Nav. Used to set the pagestitleattribute in the HTML head. This is used in turn is used by the browser to create history links (the back button). Would set this from configuration to the abbreviation for the application title_entry- 
A lazy string. The default constructor sets it to the current pages navigation label. This is appended to
title_abbrevto form the labels in the browser history 
Subroutines/Methods
Defines the following methods;
BUILDARGS- 
Wraps around the constructor call. If the
contextobject has a reference to theconfigobject which has a reference to anavigationattribute, then that hash reference is merged into the attributes passed to the constructor crud- 
$self = $self->crud($moniker, $existing_id, $create_id);A convenience method which calls
itemup to four times. Ifcreate_idis passeditemis called with an action path ofmoniker/create. Theexisting_idis required anditemis called three times with the action paths;moniker/delete,moniker/editandmoniker/view finalise- 
Populates the stash with the data that represents the menu which will be serialised to JSON
 finalise_script_request- 
If
is_script_requestis true then stash an OK HTTP return code. When using JS navigation all HTTP responses must be OK or the browser (which sniffs the fetch responses) will automatically navigate is_script_request- 
Returns true if the request has come from the JS in the browser
 item- 
$self = $self->item('action path', $args, $params); $self = $self->item(formpost, 'action path', $args, $params);The first example will add a single link to the current
list. The display text is set by theNavsubroutine attribute of the endpoint, thehrefis supplied bycontexturi_for_actionIn the second example
formpostis imported from Web::Components::Util and causes the rendered menu item to be a form with a button on it (it is expected that this will be styled like a link). This is used for delete operations since we don't do deletes with a GET list- 
$self = $self->list('list name', 'optional title');Sets the current list to the name provided. If this list does not exist it is created. Once a list has been created
itemis called to add entries to it - 
$self = $self->menu('list name');If the named list exists add it to the current list. This is how you created nested lists
 render- 
Returns the HTML for inclusion on the web page
 
Diagnostics
None
Dependencies
Incompatibilities
There are no known incompatibilities in this module
Bugs and Limitations
There are no known bugs in this module. Please report problems to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Web-Components. Patches are welcome
Acknowledgements
Larry Wall - For the Perl programming language
Author
Peter Flanigan, <pjfl@cpan.org>
License and Copyright
Copyright (c) 2024 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE