From b714b62c1b717ac01b738fef17b91844396c1b07 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 5 Nov 2010 11:38:47 -0600 Subject: [PATCH] Bug #9368: Refactor menu handling in dimp Remove support for 'action' menu config parameter. Use Horde_Menu (and the new IMP_Menu_Dimp class) to generate the menu code. --- imp/config/menu.php.dist | 25 ++++---- imp/docs/UPGRADING | 7 +++ imp/index-dimp.php | 32 +++------- imp/js/dimpbase.js | 22 +++++-- imp/lib/Dimp.php | 14 ----- imp/lib/Menu/Dimp.php | 92 +++++++++++++++++++++++++++++ imp/templates/dimp/index.inc | 63 ++++---------------- imp/templates/dimp/javascript_defs_dimp.php | 29 ++++----- 8 files changed, 162 insertions(+), 122 deletions(-) create mode 100644 imp/lib/Menu/Dimp.php diff --git a/imp/config/menu.php.dist b/imp/config/menu.php.dist index f8b2f0306..5d3d82b65 100644 --- a/imp/config/menu.php.dist +++ b/imp/config/menu.php.dist @@ -3,19 +3,20 @@ * This file lets you extend IMP's menu with your own items. * * To add a new menu item, simply add a new entry to the $_menu array. - * Valid attributes for a new menu item are: * - * 'url' The URL value for the menu item. - * 'text' The text to accompany the menu item. + * REQUIRED attributes for a menu item are: * - * These attributes are optional: + * 'url' The URL value for the menu item. + * 'text' The text to accompany the menu item. * - * 'action' The javascript code for the menu item (dimp only). - * 'icon' The filename of an icon to use for the menu item. - * 'icon_path' The path to the icon if it doesn't exist in the graphics/ - * directory. - * 'target' The "target" of the link (e.g. '_top', '_blank'). - * 'onclick' Any JavaScript to execute on the "onclick" event. + * These attributes are OPTIONAL: + * + * 'icon' The filename of an icon to use for the menu item. + * 'icon_path' The path to the icon if it doesn't exist in the graphics/ + * directory. + * 'onclick' Javascript to execute on the "onclick" event (standard view + only). + * 'target' The "target" of the link (e.g. '_top', '_blank'). * * Here's an example entry: * @@ -24,9 +25,7 @@ * 'text' => 'Example, Inc.', * 'icon' => 'example.png', * 'icon_path' => 'http://www.example.com/images/', - * 'target' => '_blank', - * 'onclick' => '', - * 'action' => '' + * 'target' => '_blank' * ); * * You can also add a "separator" (a spacer) between menu items. To add a diff --git a/imp/docs/UPGRADING b/imp/docs/UPGRADING index 9e4bf2292..c29823ab6 100644 --- a/imp/docs/UPGRADING +++ b/imp/docs/UPGRADING @@ -140,6 +140,13 @@ CSS TODO +Menu +---- + +The dynamic view (DIMP) no longer supports the 'action' parameter located +in config/menu.php. + + Upgrading IMP From 4.1.x To 4.2.x ================================= diff --git a/imp/index-dimp.php b/imp/index-dimp.php index 81ca4bc9b..b53af3f62 100644 --- a/imp/index-dimp.php +++ b/imp/index-dimp.php @@ -17,7 +17,14 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('imp', array('impmode' => 'dimp')); -$scripts = array( +/* Get site specific menu items. */ +$dimp_menu = new IMP_Menu_Dimp(Horde_Menu::MASK_BASE); +$render_sidebar = $dimp_menu->render('sidebar'); +$render_tabs = $dimp_menu->render('tabs'); +$dimp_menu->addJs(); + +Horde::noDnsPrefetch(); +IMP_Dimp::header('', array( array('dimpbase.js', 'imp'), array('viewport.js', 'imp'), array('dialog.js', 'imp'), @@ -28,28 +35,7 @@ $scripts = array( array('popup.js', 'horde'), array('redbox.js', 'horde'), array('slider2.js', 'horde') -); - -/* Get site specific menu items. */ -$js_code = $site_menu = array(); -if (is_readable(IMP_BASE . '/config/menu.php')) { - include IMP_BASE . '/config/menu.php'; -} - -/* Add the site specific javascript now. */ -if (!empty($site_menu)) { - foreach ($site_menu as $key => $menu_item) { - if ($menu_item != 'separator') { - foreach (array('menu', 'tab') as $val) { - $js_code[] = 'DimpCore.clickObserveHandler({ d: $(\'' . $val . $key . '\'), f: function() { ' . $menu_item['action'] . ' } })'; - } - } - } -} - -Horde::addInlineScript($js_code, 'load'); -Horde::noDnsPrefetch(); -IMP_Dimp::header('', $scripts); +)); echo "\n"; require IMP_TEMPLATES . '/dimp/index.inc'; diff --git a/imp/js/dimpbase.js b/imp/js/dimpbase.js index 3dac3f3ca..94af48eea 100644 --- a/imp/js/dimpbase.js +++ b/imp/js/dimpbase.js @@ -212,12 +212,22 @@ var DimpBase = { this.go('folder:INBOX'); return; } - this.highlightSidebar('app' + app); + this.highlightSidebar(); this.setHash(loc); if (data) { this.iframeContent(loc, data); - } else if (DIMP.conf.app_urls[app]) { - this.iframeContent(loc, DIMP.conf.app_urls[app]); + } else if (DIMP.conf.portal_urls[app]) { + this.iframeContent(loc, DIMP.conf.portal_urls[app]); + } + return; + } + + if (loc.startsWith('menu:')) { + app = loc.substr(5); + this.highlightSidebar(); + this.setHash(loc); + if (DIMP.conf.menu_urls[app]) { + this.iframeContent(loc, DIMP.conf.menu_urls[app]); } return; } @@ -2138,7 +2148,8 @@ var DimpBase = { tmp = tmp.up('LI.custom'); } if (tmp) { - this.go('app:' + tmp.down('A').identify().substring(3)); + // Prefix is 'sidebarapp_' + this.go('menu:' + tmp.down('A').identify().substring(11)); e.stop(); return; } @@ -2146,7 +2157,8 @@ var DimpBase = { case 'tabbar': if (e.element().hasClassName('applicationtab')) { - this.go('app:' + e.element().identify().substring(6)); + // Prefix is 'apptab_' + this.go('menu:' + e.element().identify().substring(7)); e.stop(); return; } diff --git a/imp/lib/Dimp.php b/imp/lib/Dimp.php index e3899083d..e5e05f87f 100644 --- a/imp/lib/Dimp.php +++ b/imp/lib/Dimp.php @@ -126,20 +126,6 @@ class IMP_Dimp } /** - * Return a list of DIMP specific menu items. - * - * @return array The array of menu items. - */ - static public function menuList() - { - return (isset($GLOBALS['conf']['menu']['apps']) && - is_array($GLOBALS['conf']['menu']['apps']) && - count($GLOBALS['conf']['menu']['apps'])) - ? $GLOBALS['conf']['menu']['apps'] - : array(); - } - - /** * Build data structure needed by DimpCore javascript to display message * log information. * diff --git a/imp/lib/Menu/Dimp.php b/imp/lib/Menu/Dimp.php new file mode 100644 index 000000000..8600de591 --- /dev/null +++ b/imp/lib/Menu/Dimp.php @@ -0,0 +1,92 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package IMP + */ +class IMP_Menu_Dimp extends Horde_Menu +{ + /** + * Has render() been called yet? + * + * @var boolean + */ + protected $_renderCalled = false; + + /** + * @param string $type Either 'sidebar' or 'tabs'. + */ + public function render($type) + { + if (!$this->_renderCalled) { + parent::render(); + + foreach ($this->_menu as $k => $v) { + if ($v == 'separator') { + unset($this->_menu[$k]); + } + } + + $this->_renderCalled = true; + } + + $out = ''; + + foreach ($this->_menu as $k => $m) { + switch ($type) { + case 'sidebar': + $out .= '
  • ' . + Horde::img($m['icon'], Horde::stripAccessKey($m['text']), '', $m['icon_path']) . + '' . htmlspecialchars($m['text']) . + '
  • '; + break; + + case 'tabs': + $out .= '
  • ' . + '' . + Horde::img($m['icon'], Horde::stripAccessKey($m['text']), '', $m['icon_path']) . + htmlspecialchars($m['text']) . + '
  • '; + break; + } + } + + return $out; + } + + /** + */ + protected function _render() + { + } + + /** + * Adds the necessary JS to the output string (list of keys -> URLs used + * by DimpBase). + */ + public function addJs() + { + $out = array(); + + foreach ($this->_menu as $k => $v) { + $url = new Horde_Url($v['url']); + $out[$k] = strval($url->setRaw(true)->add('ajaxui', 1)); + } + + if (!empty($out)) { + Horde::addInlineJsVars(array( + 'DIMP.conf.menu_urls' => $out + )); + } + } + +} diff --git a/imp/templates/dimp/index.inc b/imp/templates/dimp/index.inc index 7c24a0bf9..67a2e6fd9 100644 --- a/imp/templates/dimp/index.inc +++ b/imp/templates/dimp/index.inc @@ -15,20 +15,10 @@ $has_blacklist = $registry->hasMethod('mail/blacklistFrom'); $has_whitelist = $registry->hasMethod('mail/whitelistFrom'); // Quota information -$show_quota = $session->get('imp', 'imap_quota'); - -// Get application folders list. -$application_folders = array(); -foreach (IMP_Dimp::menuList() as $app) { - if (($registry->get('status', $app) != 'inactive') && - $registry->hasPermission($app, Horde_Perms::SHOW)) { - $application_folders[] = array( - 'app' => rawurlencode($app), - 'icon' => $registry->get('icon', $app), - 'name' => htmlspecialchars($registry->get('name', $app)) - ); - } -} +$show_quota = $session->get('imp', 'imap_quota') + ? '' . Horde::img('quotauncover.gif') . '' + : ''; + function _simpleButton($id, $text, $image, $nodisplay = false) { @@ -80,36 +70,12 @@ function _simpleButton($id, $text, $image, $nodisplay = false)