[BUGFIX] Collapsing state for ModuleMenu should be user-specific 27/34027/5
authorBenjamin Mack <benni@typo3.org>
Wed, 24 Dec 2014 01:33:21 +0000 (02:33 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 18 Jan 2015 21:31:37 +0000 (22:31 +0100)
Using SwitchUser Mode keeps the module menu
configuration (e.g. also closing help menu) the
same even if the user has switched (or does not
have the module available). This leads to unexpected
behaviour.

The change uses the new Storage API for JS
and uses the Persistent Storage instead of the
ClientStorage (localStorage) now.

Resolves: #62894
Releases: master
Change-Id: I10bb0ae5e8bc18e11646e9571a9314e5d3266ff6
Reviewed-on: http://review.typo3.org/34027
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Resources/Public/JavaScript/modulemenu.js

index 7b6c0aa..dd696a8 100644 (file)
@@ -39,19 +39,21 @@ TYPO3.ModuleMenu.App = {
                        me.showModule(TYPO3.jQuery('.typo3-module-menu-item:first').attr('id'));
                }
 
-               // check if there are collapsed items in the local storage
-               var collapsedMainMenuItems = this.getCollapsedMainMenuItems();
-               TYPO3.jQuery.each(collapsedMainMenuItems, function(key, itm) {
-                       var $group = TYPO3.jQuery('#' + key);
-                       if ($group.length > 0) {
-                               var $groupContainer = $group.find('.typo3-module-menu-group-container');
-                               $group.addClass('collapsed').removeClass('expanded');
-                               $groupContainer.hide().promise().done(function() {
-                                       TYPO3.Backend.doLayout();
-                               });
-                       }
+               // check if there are collapsed items in the users' configuration
+               require(['TYPO3/CMS/Backend/Storage'], function() {
+                       var collapsedMainMenuItems = me.getCollapsedMainMenuItems();
+                       TYPO3.jQuery.each(collapsedMainMenuItems, function(key, itm) {
+                               var $group = TYPO3.jQuery('#' + key);
+                               if ($group.length > 0) {
+                                       var $groupContainer = $group.find('.typo3-module-menu-group-container');
+                                       $group.addClass('collapsed').removeClass('expanded');
+                                       $groupContainer.hide().promise().done(function() {
+                                               TYPO3.Backend.doLayout();
+                                       });
+                               }
+                       });
+                       me.initializeEvents();
                });
-               me.initializeEvents();
        },
 
        initializeEvents: function() {
@@ -221,8 +223,8 @@ TYPO3.ModuleMenu.App = {
         * @returns {*}
         */
        getCollapsedMainMenuItems: function() {
-               if (typeof localStorage.getItem('t3-modulemenu') !== "undefined" && typeof localStorage.getItem('t3-modulemenu') !== "null" && localStorage.getItem('t3-modulemenu') != 'undefined' && localStorage.getItem('t3-modulemenu')) {
-                       return JSON.parse(localStorage.getItem('t3-modulemenu'));
+               if (TYPO3.Storage.Persistent.isset('modulemenu')) {
+                       return JSON.parse(TYPO3.Storage.Persistent.get('modulemenu'));
                } else {
                        return {};
                }
@@ -235,7 +237,7 @@ TYPO3.ModuleMenu.App = {
        addCollapsedMainMenuItem: function(item) {
                var existingItems = this.getCollapsedMainMenuItems();
                existingItems[item] = true;
-               localStorage.setItem('t3-modulemenu', JSON.stringify(existingItems));
+               TYPO3.Storage.Persistent.set('modulemenu', JSON.stringify(existingItems));
        },
 
        /**
@@ -245,7 +247,7 @@ TYPO3.ModuleMenu.App = {
        removeCollapseMainMenuItem: function(item) {
                var existingItems = this.getCollapsedMainMenuItems();
                existingItems[item] = null;
-               localStorage.setItem('t3-modulemenu', JSON.stringify(TYPO3.jQuery.existingItems));
+               TYPO3.Storage.Persistent.set('modulemenu', JSON.stringify(existingItems));
        }
 
 };