From: <gem...@li...> - 2012-06-13 15:23:39
|
Revision: 759 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=759&view=rev Author: matijsdejong Date: 2012-06-13 15:23:29 +0000 (Wed, 13 Jun 2012) Log Message: ----------- Menu can now be rendered using HtmlElements. This allows images and other structure in menu labels New projects should use the new method, while older will remain working unchanged Modified Paths: -------------- trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/Menu.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Html/HtmlElement.php trunk/library/classes/MUtil/Html/HtmlInterface.php trunk/library/layouts/scripts/gems.phtml Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-06-12 15:25:05 UTC (rev 758) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-06-13 15:23:29 UTC (rev 759) @@ -572,7 +572,12 @@ abstract public function isVisible(); - + /** + * Make sure only the active branch is visible + * + * @param array $activeBranch Of Gems_Menu_Menu Abstract items + * @return Gems_Menu_MenuAbstract (continuation pattern) + */ protected function setBranchVisible(array $activeBranch) { $current = array_pop($activeBranch); @@ -581,6 +586,7 @@ foreach ($this->_subItems as $item) { if ($item->isVisible()) { if ($item === $current) { + $item->set('active', true); $item->setBranchVisible($activeBranch); } else { $item->setForChildren('visible', false); Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2012-06-12 15:25:05 UTC (rev 758) +++ trunk/library/classes/Gems/Menu.php 2012-06-13 15:23:29 UTC (rev 759) @@ -52,7 +52,7 @@ * @license New BSD License * @since Class available since version 1.0 */ -class Gems_Menu extends Gems_Menu_MenuAbstract +class Gems_Menu extends Gems_Menu_MenuAbstract implements MUtil_Html_HtmlInterface { /** * @@ -559,7 +559,7 @@ // EXPORT TO HTML $this->addContainer($this->_('Export respondent'), 'pr.export-html', array('controller' => 'respondent-export', 'action'=>'index')); - + // OTHER ITEMS $this->addLogonOffToken(); @@ -591,6 +591,91 @@ { } + /** + * Renders the element into a html string + * + * The $view is used to correctly encode and escape the output + * + * @param Zend_View_Abstract $view + * @return string Correctly encoded and escaped html output + */ + public function render(Zend_View_Abstract $view) + { + $activePath = $this->_findPath($this->escort->request); + + if ($this->_onlyActiveBranchVisible) { + // MUtil_Echo::r($activePath); + $this->setBranchVisible($activePath); + } + + $parameterSources[] = $this->escort->request; + + if ($this->_menuParameters) { + $parameterSources[] = $this->_menuParameters; + } + + $source = new Gems_Menu_ParameterCollector($parameterSources); + // self::$verbose = true; + + $nav = $this->_toNavigationArray($source); + + // MUtil_Echo::track($nav); + + $ul = $this->renderFirst(); + + $this->renderItems($ul, $nav); + + return $ul->render($view); + } + + /** + * Helper function to create main menu html element. + * + * Allows overloading by sub classes. + * + * @return MUtil_Html_ListElement + */ + protected function renderFirst() + { + return MUtil_Html::create()->ul(array('class' => 'navigation')); + } + + /** + * Helper function to load the menu items to the html element. + * + * Allows overloading by sub classes. + * + * @param MUtil_Html_ListElement $ul + * @param array $items + */ + protected function renderItems(MUtil_Html_ListElement $ul, array $items) + { + foreach ($items as $item) { + if ($item['visible'] && $item['label']) { + $url = $item['params']; + $url['controller'] = $item['controller']; + $url['action'] = $item['action']; + $url['RouteReset'] = true; + $li = $ul->li(); + if (isset($item['active']) && $item['active']) { + $li->class = 'active'; + } + + $a = $li->a($url, $item['label']); + if (isset($item['class'])) { + $a->class = $item['class']; + } + if (isset($item['target'])) { + $a->target = $item['target']; + } + + if (isset($item['pages'])) { + $this->renderItems($li->ul(), $item['pages']); + } + } + } + } + protected function request2find($request) { if (is_array($request)) { @@ -654,7 +739,7 @@ $nav = new Zend_Navigation($this->_toNavigationArray($source)); - // MUtil_Echo::r($this->_toNavigationArray($parameterSources)); + // MUtil_Echo::track($this->_toNavigationArray($source), $nav); return $nav; } Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-06-12 15:25:05 UTC (rev 758) +++ trunk/library/classes/GemsEscort.php 2012-06-13 15:23:29 UTC (rev 759) @@ -734,6 +734,26 @@ } /** + * Function called if specified in the Project.ini layoutPrepare section before + * the layout is drawn, but after the rest of the program has run it's course. + * + * @return mixed If null nothing is set, otherwise the name of + * the function is used as Zend_View variable name. + */ + protected function _layoutMenuHtml() + { + // ACL && Menu + if ($this->menu && $this->menu->isVisible()) { + + // Make sure the actual $request and $controller in use at the end + // of the dispatchloop is used and make Zend_Navigation object + return $this->menu->render($this->view); + } + + return null; + } + + /** * Display either a link to the login screen or displays the name of the current user * and a logoff link. * @@ -792,7 +812,7 @@ if ($messages) { foreach ($messages as &$message) { // Make sure html is preserved - if (strlen($message) && ((strpos($message, '<') !== false) || (strpos($message, '&') !== false))) { + if (is_string($message) && strlen($message) && ((strpos($message, '<') !== false) || (strpos($message, '&') !== false))) { $message = MUtil_Html::raw($message); } } Modified: trunk/library/classes/MUtil/Html/HtmlElement.php =================================================================== --- trunk/library/classes/MUtil/Html/HtmlElement.php 2012-06-12 15:25:05 UTC (rev 758) +++ trunk/library/classes/MUtil/Html/HtmlElement.php 2012-06-13 15:23:29 UTC (rev 759) @@ -799,7 +799,13 @@ return in_array($tagName, $guards); } - public function append($value) + /** + * Add stuff to this element + * + * @param mixed $value The value to append + * @return MUtil_Html_HtmlElement + */ + public function append($value = null) { $this->offsetSet(null, $value); Modified: trunk/library/classes/MUtil/Html/HtmlInterface.php =================================================================== --- trunk/library/classes/MUtil/Html/HtmlInterface.php 2012-06-12 15:25:05 UTC (rev 758) +++ trunk/library/classes/MUtil/Html/HtmlInterface.php 2012-06-13 15:23:29 UTC (rev 759) @@ -1,69 +1,70 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - + /** - * - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package MUtil + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package MUtil * @subpackage Html + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ /** - * Classes implementing the HtmlInterface are translateable into correctly - * encoded and escaped html or even xml depending on the view passed as a + * Classes implementing the HtmlInterface are translateable into correctly + * encoded and escaped html or even xml depending on the view passed as a * parameter to the one function in this interface. - * - * Most library classes implementing this interface either implement the - * AttributeInterface or the ElementInterface but good examples of straight + * + * Most library classes implementing this interface either implement the + * AttributeInterface or the ElementInterface but good examples of straight * implementation are Raw and (Html) MultiWrapper classes. - * + * * As this is the simplest method to ourput html with some control over * it's rendering it is often used for quick implementations in * non-library code. - * - * @see MUtil_Html_AttributeInterface + * + * @see MUtil_Html_AttributeInterface * @see MUtil_Html_ElementInterface * @see MUtil_Html_MultiWrapper * @see MUtil_Html_Raw - * - * @author Matijs de Jong - * @package MUtil + * + * @package MUtil * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ interface MUtil_Html_HtmlInterface { /** * Renders the element into a html string - * + * * The $view is used to correctly encode and escape the output * * @param Zend_View_Abstract $view Modified: trunk/library/layouts/scripts/gems.phtml =================================================================== --- trunk/library/layouts/scripts/gems.phtml 2012-06-12 15:25:05 UTC (rev 758) +++ trunk/library/layouts/scripts/gems.phtml 2012-06-13 15:23:29 UTC (rev 759) @@ -25,7 +25,7 @@ <div id="header"><?php if ($this->header) { echo $this->header->render($this); }?></div> <div id="header_bar"><?php if ($this->header_bar) { echo $this->header_bar->render($this); } ?></div> <?php - if ($this->navigation): + if ($this->navigation || $this->menuHtml): ?> <div id="main"><?php if ($this->main) { @@ -35,6 +35,7 @@ ?></div> <div id="menu"><?php echo $this->navigation()->menu(); + echo $this->menuHtml; ?></div><?php else: ?><div id="main_full_width"><?php @@ -52,7 +53,7 @@ ?></div> </div><?php echo MUtil_Echo::out(); - + // Scripts here for load optimization echo $this->headScript(); echo $this->inlineScript(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |