← Back to team overview

launchpad-dev team mailing list archive

RFC NavigationMenu primer

 

Given that we will be working with navigation menus more than we first
planned, and that we are using them in new ways, I think we may want to
update our UI 3.0 page.

    https://dev.launchpad.net/VersionThreeDotO/UI/Conversion

Is the following helpful?

=======================
Adding a NavigationMenu
-----------------------

Launchpad uses NavigationMenus to associate outbound links to a view.
The menu and view are bound together by a marker interface. Links that
are used in more than one menu should be defined in a mixin class to
ensure that there is a single canonical definition of them.

The menu can be rendered as an action menu in the side portlets or as a
list of related pages in the main content.


Working with two menus
----------------------

There are a few cases where a page may need two menus. One for actions
that change an object that are not possible to move into the main content,
the other for pages related to the content of the page. NavigationMenus
can be created for content objects and views.


A browser module example
------------------------

{{{

from zope.interface import implements, Interface

from canonical.launchpad.webapp.menu import NavigationMenu
from canonical.launchpad.webapp.publisher import LaunchpadView

from lp.myapp.interfaces.myobject import IObject


class ObjectLinksMixin:
    """A mixin class that provides links used by more than on menu."""


# Classes to create menus on more than one view
class IObjectEditMenu(Interface):
    """A marker interface for the edit navigation menu."""


class ObjectEditMenu(NavigationMenu, ObjectLinksMixin):
    """A menu for different aspects of editing a oject."""

    usedfor = IObjectEditMenu
    facet = 'overview'
    title = 'Change object'
    links = ('edit', 'images', 'reassign', 'review', 'administer')


class ObjectEditView(LauncpadView):
    """A view to set branding."""
    implements(IObjectEditMenu)


class ObjectImagesView(LauncpadView):
    """A view to set images."""
    implements(IObjectEditMenu)


# Class to create a menu for the object, irrespective of the view.
class ObjectActionMenu(NavigationMenu, ObjectLinksMixin):
    """An action menu to modify the object."""

    usedfor = IObject
    facet = 'overview'
    title = 'Action object'
    links = ('review', 'administer')


# Menus are normally registered using the menu ZCML directive. They can
# be registered in Python. To register the 
provideAdapter(
    ObjectEditMenu, [IObjectEditMenu], INavigationMenu, name="overview")
provideAdapter(
    ObjectActionMenu, [IObject], INavigationMenu, name="overview")

}}}


A ZCML example to regster a menu
--------------------------------

{{{

    <browser:menus
        classes="
            ObjectEditMenu
            ObjectActionMenu"
        module="lp.myapp.browser.myobject"/>

}}}


Rendering a NavigationMenu
--------------------------

To render an action menu use this TALES view:

    <tal:menu replace="structure context/@@+global-actions" />

To render a related pages:

    <tal:menu replace="structure view/@@+related-pages" />

Note that view and context can be interchanged in the examples since
context objects and their views may both have NavigationMenus.

-- 
__Curtis C. Hovey_________
http://launchpad.net/

Attachment: signature.asc
Description: This is a digitally signed message part


Follow ups