Perforce Chronicle 2012.2/486814
API Documentation

Ui_View_Helper_Toolbar Class Reference

View helper that renders the managment toolbar. More...

Inheritance diagram for Ui_View_Helper_Toolbar:
Menu_View_Helper_Menu

List of all members.

Public Member Functions

 htmlify ($page)
 Replaces parent htmlify so that we can use the pageDijit dojoType for constructing the menus.
 renderMenu (Zend_Navigation_Container $container=null, array $options=array())
 Extends the parent helper renderer to use the toolbarDijit dojoType for constructing the toolbar.
 toolbar ($container=null, array $options=array())
 This is the toolbar helper entry point.

Protected Member Functions

 _normalizeOptions (array $options=array())
 Normalizes given render options.

Protected Attributes

 $_displayContext

Static Protected Attributes

static $_dropDownDijit = 'p4cms.ui.toolbar.DropDownMenuButton'
static $_pageDijit = 'p4cms.ui.toolbar.MenuButton'
static $_toolbarDijit = 'p4cms.ui.toolbar.Toolbar'

Detailed Description

View helper that renders the managment toolbar.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Ui_View_Helper_Toolbar::_normalizeOptions ( array $  options = array()) [protected]

Normalizes given render options.

Parameters:
array$options[optional] options to normalize
Returns:
array normalized options
    {
        if (!isset($options['displayContext'])) {
            $options['displayContext'] = '';
        }
        if (!isset($options['dockConfig'])) {
            $options['dockConfig'] = null;
        }

        return parent::_normalizeOptions($options);
    }
Ui_View_Helper_Toolbar::htmlify ( page)

Replaces parent htmlify so that we can use the pageDijit dojoType for constructing the menus.

Parameters:
Zend_Navigation_Page$pagepage to generate HTML for
Returns:
string HTML string for the given page

Reimplemented from Menu_View_Helper_Menu.

    {
        // only dijitize top level menu items
        if ($page->getParent() instanceof Zend_Navigation_Page) {
            return parent::htmlify($page);
        }

        // always provide a type class for styling purposes.
        $typeClass = 'type-' . strtolower(end(explode('_', get_class($page))));

        // grab any popups for rendering
        $popupMenu = '';
        if ($page->useDropDown && $page->hasPages()) {
            $dijitMenu = $this->view->navigation()->findHelper('dijitMenu');
            $popupMenu = $dijitMenu->renderMenu(
                $page,
                array(
                    'attribs' => array(
                        'leftClickToOpen'   => 'true',
                        'style'             => 'display:none;',
                        'wrapperClass'      => 'toolbar-popup-menu'
                    )
                )
            );

            // remove the pages so they won't be rendered
            $page->removePages();
        }

        // if we have a popup, use the dropdown menu, otherwise the normal menu
        $dojoType = $popupMenu ? static::$_dropDownDijit : static::$_pageDijit;

        // get attribs for element
        $attribs = array(
            'id'                    => $page->getId(),
            'dojoType'              => $dojoType,
            'iconClass'             => $page->getClass(),
            'menuAlign'             => $page->align,
            'class'                 => trim($typeClass),
            'displayContext'        => $page->context,
            'onClick'               => $page->onClick,
            'closeOnBlur'           => $page->closeOnBlur,
            'title'                 => $page->title,
            'onActivate'            => $page->onActivate,
            'onDeactivate'          => $page->onDeactivate,
            'onDrawerLoad'          => $page->onDrawerLoad,
        );

        // provide different elements for links vs other menu items
        $element = 'span';
        if ($page->getHref()) {
            $element            = 'a';
            $attribs['href']    = $this->view->escape($page->getHref());
            $attribs['target']  = $page->getTarget();
        }

        return '<' . $element . ' '
             . $this->_htmlAttribs($attribs) . '>'
             . $this->view->escape($page->getLabel())
             . '</' . $element . '>'
             . $popupMenu;
    }
Ui_View_Helper_Toolbar::renderMenu ( Zend_Navigation_Container $  container = null,
array $  options = array() 
)

Extends the parent helper renderer to use the toolbarDijit dojoType for constructing the toolbar.

Parameters:
Zend_Navigation_Container$container[optional] container to create menu from. Default is to use the container retrieved from getContainer().
array$options[optional] options for controlling rendering
Returns:
string rendered menu

Reimplemented from Menu_View_Helper_Menu.

    {
        $this->_options = $options = $this->_normalizeOptions($options);

        $dijitAttribs = array(
            'dojoType'          => static::$_toolbarDijit,
            'displayContext'    => $options['displayContext'],
            'dockConfig'        => Zend_Json::encode($options['dockConfig']),
            'class'             => 'p4cms-ui manage-toolbar toolbar-disabled'
        );

        return '<div ' . $this->_htmlAttribs($dijitAttribs) . '>'
            . parent::renderMenu($container, $options)
            . '</div>';
    }
Ui_View_Helper_Toolbar::toolbar ( container = null,
array $  options = array() 
)

This is the toolbar helper entry point.

It has been extended to check ACL for the 'access-toolbar' permission and to default the menu container to the 'manage-toolbar' menu.

Parameters:
mixed$containeroptional - menu or container to operate on defaults to 'manage-toolbar' menu
array$optionsoptions to apply when rendering this menu, includes optional displayContext string to filter items that should only appear in certain contexts eg. only show 'Back to Website' in 'manage' context.
Returns:
Ui_View_Helper_Toolbar fluent interface, returns self
    {
        if (!P4Cms_User::fetchActive()->isAllowed('site', 'access-toolbar')) {
            return null;
        }

        if (!$container) {
            $container = 'manage-toolbar';
        }

        return parent::menu($container, $options);
    }

Member Data Documentation

Ui_View_Helper_Toolbar::$_displayContext [protected]
Ui_View_Helper_Toolbar::$_dropDownDijit = 'p4cms.ui.toolbar.DropDownMenuButton' [static, protected]
Ui_View_Helper_Toolbar::$_pageDijit = 'p4cms.ui.toolbar.MenuButton' [static, protected]
Ui_View_Helper_Toolbar::$_toolbarDijit = 'p4cms.ui.toolbar.Toolbar' [static, protected]

The documentation for this class was generated from the following file: