fixed bugs #7251 , #6524: Make the folding/unfolding of the menu items use AJAX,...
authorIngo Renner <ingo.renner@typo3.org>
Wed, 23 Jan 2008 17:24:32 +0000 (17:24 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Wed, 23 Jan 2008 17:24:32 +0000 (17:24 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2952 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/config_default.php
typo3/classes/class.modulemenu.php
typo3/js/backend.js

index 4ca0961..bae5165 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-01-23  Ingo Renner  <ingo@typo3.org>
+
+       * fixed bugs #7251 , #6524: Make the folding/unfolding of the menu items use AJAX, credits Steffen Kamper
+
 2008-01-23     Thomas Hempel  <thomas@typo3-unleashed.net>
 
        * Installer: added new option BE/RTE_imageStorageDir. related to issue #7185
index df5142f..9dc1a3c 100755 (executable)
@@ -174,13 +174,14 @@ $TYPO3_CONF_VARS = Array(
                'AJAX' => array(                                // array of key-value pairs for a unified use of AJAX calls in the TYPO3 backend. Keys are the unique ajaxIDs where the value will be resolved to call a method in an object. See ajax.php and the classes/class.typo3ajax.php for more information.
                        'SC_alt_db_navframe::expandCollapse'   => 'typo3/alt_db_navframe.php:SC_alt_db_navframe->ajaxExpandCollapse',
                        'SC_alt_file_navframe::expandCollapse' => 'typo3/alt_file_navframe.php:SC_alt_file_navframe->ajaxExpandCollapse',
-                       't3lib_TCEforms_inline::createNewRecord'                => 't3lib/class.t3lib_tceforms_inline.php:t3lib_TCEforms_inline->processAjaxRequest',
+                       't3lib_TCEforms_inline::createNewRecord'                    => 't3lib/class.t3lib_tceforms_inline.php:t3lib_TCEforms_inline->processAjaxRequest',
                        't3lib_TCEforms_inline::setExpandedCollapsedState'      => 't3lib/class.t3lib_tceforms_inline.php:t3lib_TCEforms_inline->processAjaxRequest',
                        'ShortcutMenu::getGroups'              => 'typo3/classes/class.shortcutmenu.php:ShortcutMenu->getAjaxShortcutGroups',
                        'ShortcutMenu::saveShortcut'           => 'typo3/classes/class.shortcutmenu.php:ShortcutMenu->setAjaxShortcut',
                        'ShortcutMenu::render'                 => 'typo3/classes/class.shortcutmenu.php:ShortcutMenu->renderAjax',
                        'ShortcutMenu::delete'                 => 'typo3/classes/class.shortcutmenu.php:ShortcutMenu->deleteAjaxShortcut',
-                       'ShortcutMenu::create'                 => 'typo3/classes/class.shortcutmenu.php:ShortcutMenu->createAjaxShortcut'
+                       'ShortcutMenu::create'                 => 'typo3/classes/class.shortcutmenu.php:ShortcutMenu->createAjaxShortcut',
+                       'ModuleMenu::saveMenuState'            => 'typo3/classes/class.modulemenu.php:ModuleMenu->saveMenuState'
                ),
        ),
        'FE' => Array(                  // Configuration for the TypoScript frontend (FE). Nothing here relates to the administration backend!
index 0fd8143..f5041c9 100644 (file)
@@ -105,6 +105,21 @@ class ModuleMenu {
        }
 
        /**
+        * saves the menu's toggle state in the backend user's uc
+        *
+        * @param       array           array of parameters from the AJAX interface, currently unused
+        * @param       TYPO3AJAX       object of type TYPO3AJAX
+        * @return      void
+        */
+       public function saveMenuState($params, &$ajaxObj) {
+               $menuItem = t3lib_div::_POST('menuid');
+               $state    = t3lib_div::_POST('state') === 'true' ? 1 : 0;
+
+               $GLOBALS['BE_USER']->uc['moduleData']['menuState'][$menuItem] = $state;
+               $GLOBALS['BE_USER']->writeUC();
+       }
+
+       /**
         * renders the backend menu as unordered list
         *
         * @return      string          menu html code to use in the backend
@@ -116,18 +131,19 @@ class ModuleMenu {
                $rawModuleData = $this->getRawModuleData();
 
                foreach($rawModuleData as $moduleKey => $moduleData) {
-
+                       $menuState   = $GLOBALS['BE_USER']->uc['moduleData']['menuState'][$moduleKey];
                        $moduleLabel = $moduleData['title'];
+
                        if($moduleData['link'] && $this->linkModules) {
                                $moduleLabel = '<a href="#" onclick="top.goToModule(\''.$moduleData['name'].'\');'.$onBlur.'return false;">'.$moduleLabel.'</a>';
                        }
 
                                //TODO make icon a background image using css
-                       $menu .= '<li><div>'.$moduleData['icon']['html'].' '.$moduleLabel.'</div>';
+                       $menu .= '<li id="'.$moduleKey.'" class="menuSection"><div>'.$moduleData['icon']['html'].' '.$moduleLabel.'</div>';
 
                                // traverse submodules
                        if(is_array($moduleData['subitems'])) {
-                               $menu .= $this->renderSubModules($moduleData['subitems']);
+                               $menu .= $this->renderSubModules($moduleData['subitems'], $menuState);
                        }
 
                        $menu .= '</li>'."\n";
@@ -140,9 +156,10 @@ class ModuleMenu {
         * renders submodules
         *
         * @param       array           array of (sub)module data
+        * @param       boolean         collapse state of menu item, defaults to false
         * @return      string          (sub)module html code
         */
-       public function renderSubModules($modules) {
+       public function renderSubModules($modules, $menuState=false) {
                $moduleMenu = '';
                $onBlur     = $GLOBALS['CLIENT']['FORMSTYLE'] ? 'this.blur();' : '';
 
@@ -167,7 +184,7 @@ class ModuleMenu {
                        $moduleMenu .= '<li>'.$submoduleLink.'</li>'."\n";
                }
 
-               return '<ul>'."\n".$moduleMenu.'</ul>'."\n";
+               return '<ul'.($menuState ? ' style="display:none;"' : '').'>'."\n".$moduleMenu.'</ul>'."\n";
        }
 
        /**
index f2d8cbb..e0e0dda 100644 (file)
@@ -68,6 +68,31 @@ var ShortcutManager = {
 
 
 
+/**
+ * observes clicks on menuHeader and toggles child ul
+ */
+var ModuleMenuToggle = {
+
+       toggleMenu: function() {
+               $$('#typo3-menu li.menuSection div').each(function(element) {
+                       element.observe('click', function(){
+                               var li    = element.up();
+                               var ul    = li.down(2);
+                               var state = ul.visible();
+
+                                       // save state
+                               new Ajax.Request('ajax.php', {
+                                       method: 'post',
+                                       parameters: 'ajaxID=ModuleMenu::saveMenuState&menuid=' + li.id + '&state=' + state,
+                               });
+
+                               ul.toggle();
+                       });
+               });
+       }
+}
+
+Event.observe(document, 'dom:loaded', ModuleMenuToggle.toggleMenu.bindAsEventListener(ModuleMenuToggle), true);