Perforce Chronicle 2012.2/486814
API Documentation

Ui_Module Class Reference

Integrate the UI module with the rest of the system. More...

Inheritance diagram for Ui_Module:
P4Cms_Module_Integration

List of all members.

Static Public Member Functions

static init ()
 Subscribe to the relevant topics.
static load ()
 Perform integration operations when the site is loaded.

Detailed Description

Integrate the UI module with the rest of the system.

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

static Ui_Module::init ( ) [static]

Subscribe to the relevant topics.

Reimplemented from P4Cms_Module_Integration.

    {
        // provide dynamic menu items
        P4Cms_PubSub::subscribe('p4cms.navigation.dynamicHandlers',
            function()
            {
                // expand the help link to use the current help URL
                $handler = new P4Cms_Navigation_DynamicHandler;
                $handler->setId('ui.help-link')
                        ->setLabel('Help Link')
                        ->setExpansionCallback(
                            function($item, $options)
                            {
                                $helper = Zend_Controller_Action_HelperBroker::getStaticHelper('helpUrl');
                                $uri    = $helper ? $helper->getUrl() : null;

                                if ($uri) {
                                    return array(
                                        array(
                                            'label' => 'Help',
                                            'uri'   => $uri,
                                            'target' => '_blank'
                                        )
                                    );
                                }

                                return array();
                            }
                        );

                return array($handler);
            }
        );

        // provide 'baseUrl' macro.
        P4Cms_PubSub::subscribe('p4cms.macro.baseUrl',
            function($params, $body, $context)
            {
                $baseUrl = '';
                $request = Zend_Controller_front::getInstance()->getRequest();
                if ($request instanceof Zend_Controller_Request_Http) {
                    $baseUrl = $request->getBaseUrl();
                }

                return $baseUrl;
            }
        );

        // provide 'version' macro.
        P4Cms_PubSub::subscribe('p4cms.macro.version',
            function($params, $body, $context)
            {
                $field = isset($params[0]) ? $params[0] : '';

                switch ($field) {
                    case '':
                        return P4CMS_VERSION;
                        break;
                    case 'release':
                        return P4CMS_VERSION_RELEASE;
                        break;
                    case 'patch':
                        return P4CMS_VERSION_PATCHLEVEL;
                        break;
                    case 'date':
                        return P4CMS_VERSION_SUPPDATE;
                        break;
                    default:
                        return null;
                }
            }
        );
    }
static Ui_Module::load ( ) [static]

Perform integration operations when the site is loaded.

Reimplemented from P4Cms_Module_Integration.

    {
        // register routes with js router.
        $view     = Zend_Layout::getMvcInstance()->getView();
        $routes   = Zend_Controller_Front::getInstance()->getRouter()->getRoutes();
        $jsRoutes = array();
        foreach ($routes as $name => $route) {
            if ($route instanceof Zend_Controller_Router_Route_Regex) {
                $properties = P4Cms_Controller_Router_Route_Regex::toArray($route);
                $jsRoutes[$name] = array(
                    'type'      => 'p4cms.ui.router.route.Regex',
                    'defaults'  => $properties['defaults'],
                    'reverse'   => $properties['reverse'],
                    'map'       => $properties['map']
                );
            }

            if ($route instanceof Zend_Controller_Router_Route_Module) {
                $jsRoutes[$name] = array(
                    'type'      => 'p4cms.ui.router.route.Module',
                    'defaults'  => $route->getDefaults()
                );
            }
        }

        // expose route and server time details to client side javascript
        $request    = Zend_Controller_Front::getInstance()->getRequest();
        $baseUrl    = $request ? $request->getBaseUrl() : '';
        $script     = "p4cms.ui.Router.addRoutes(" . Zend_Json::encode($jsRoutes) . ");\n "
                    . "dojo.setObject('p4cms.ui.serverTimeOffset', (new Date().getTime()/1000) - " . time() . ");\n ";

        // include the CSRF token if one is in use
        $token = P4Cms_Form::getCsrfToken();
        if ($token) {
            $script .= "dojo.setObject('p4cms.ui.csrfToken', '" . $token . "');\n ";
        }

        $view->headScript()->appendScript($script);

        // append default meta tags to the view
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');

        // ensure that the Dojo stylesheets we depend on come first, so we can override
        // them as required. Note that these stylesheets are prepended, so the array
        // is specified in reverse order.
        $baseUrl = P4Cms_Module::fetch('dojo')->getBaseUrl();
        $dojoCss = array(
            'dojox/grid/enhanced/resources/claro/EnhancedGrid.css',
            'dijit/themes/claro/claro.css',
            'dijit/themes/claro/document.css'
        );
        foreach ($dojoCss as $css) {
            $view->headLink()->prependStylesheet(
                "$baseUrl/$css",
                'all',
                false,
                array('buildGroup' => 'packages')
            );
        }
    }

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