[BUGFIX] Ensure correct page is selected in page tree 91/54491/3
authorHelmut Hummel <typo3@helhum.io>
Sat, 28 Oct 2017 10:35:24 +0000 (12:35 +0200)
committerHelmut Hummel <typo3@helhum.io>
Mon, 30 Oct 2017 14:41:31 +0000 (15:41 +0100)
There are several actions in the backend that should
trigger a certain page to be selected in the tree.

Among others these are: open documents toolbar, live search,
favorites.

Fix every scenario in which these actions are triggered
(e.g. page tree was already initialized or not), make
sure the desired page will always be selected and
properly store the selection in the various states
so that the selection persists tree refreshes.

In addition we ensure that the content frame will
be called with the correct id, if the module uses
the page tree as navigation component.

Releases: master, 8.7
Resolves: #82877
Change-Id: I1904c02b2246f01202c6607a9b718aebe0e33341
Reviewed-on: https://review.typo3.org/54491
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Tested-by: Helmut Hummel <typo3@helhum.io>
typo3/sysext/backend/Resources/Public/JavaScript/ModuleMenu.js
typo3/sysext/backend/Resources/Public/JavaScript/Viewport.js
typo3/sysext/backend/Resources/Public/JavaScript/backend.js
typo3/sysext/backend/Resources/Public/JavaScript/extjs/components/pagetree/javascript/actions.js
typo3/sysext/backend/Resources/Public/JavaScript/extjs/components/pagetree/javascript/app.js
typo3/sysext/backend/Resources/Public/JavaScript/extjs/components/pagetree/javascript/tree.js

index 1984267..545a449 100644 (file)
@@ -194,7 +194,6 @@ require(
                         */
                        showModule: function (name, params, event) {
                                params = params || '';
-                               params = this.includeId(name, params);
                                var moduleData = this.getRecordFromName(name);
                                return this.loadModuleComponents(
                                        moduleData,
@@ -203,6 +202,14 @@ require(
                                );
                        },
 
+                       ensurePageInTreeSelected: function () {
+                               if (this.loadedNavigationComponentId === 'typo3-pagetree'
+                                       && this.availableNavigationComponents['typo3-pagetree'].isInitialized()
+                               ) {
+                                       this.availableNavigationComponents['typo3-pagetree'].selectRequestedPageId();
+                               }
+                       },
+
                        /**
                         * Shows requested module (e.g. list/page)
                         *
@@ -237,6 +244,7 @@ require(
 
                                                this.highlightModuleMenuItem(moduleName);
                                                this.loadedModule = moduleName;
+                                               params = this.includeId(moduleData, params);
                                                this.openInContentFrame(
                                                        moduleData.link,
                                                        params,
@@ -251,6 +259,7 @@ require(
                                                top.currentModuleLoaded = moduleName;
 
                                                TYPO3.Backend.doLayout();
+                                               this.ensurePageInTreeSelected();
                                        }, this
                                ));
 
@@ -260,16 +269,21 @@ require(
                        /**
                         * Prepends previously saved record id to the url params
                         *
-                        * @param {string} moduleName module name e.g. web_list
+                        * @param {Object} moduleData
                         * @param {string} params query string parameters for module url
                         * @return {string}
                         */
-                       includeId: function (moduleName, params) {
-                               if (typeof moduleName === 'undefined') {
+                       includeId: function (moduleData, params) {
+                               if (!moduleData.navigationComponentId && !moduleData.navigationFrameScript) {
                                        return params;
                                }
                                //get id
-                               var section = moduleName.split('_')[0];
+                               var section = '';
+                               if (moduleData.navigationComponentId === 'typo3-pagetree') {
+                                       section = 'web';
+                               } else {
+                                       section = moduleData.name.split('_')[0];
+                               }
                                if (top.fsMod.recentIds[section]) {
                                        params = 'id=' + top.fsMod.recentIds[section] + '&' + params;
                                }
index 27af0e3..33a2180 100644 (file)
@@ -74,7 +74,7 @@ define(
                                PageTree: {
                                        refreshTree: function() {
                                                if (typeof Ext.getCmp('typo3-pagetree') !== 'undefined') {
-                                                       Ext.getCmp('typo3-pagetree').activeTree.refreshTree();
+                                                       Ext.getCmp('typo3-pagetree').refreshTree();
                                                }
                                        }
                                },
index dd5778c..5bc8648 100644 (file)
@@ -24,17 +24,12 @@ function jump(url, modName, mainModName, pageId) {
        if (isNaN(pageId)) {
                pageId = -2;
        }
-               // clear information about which entry in nav. tree that might have been highlighted.
+       // clear information about which entry in nav. tree that might have been highlighted.
        top.fsMod.navFrameHighlightedID = [];
        top.fsMod.recentIds['web'] = pageId;
 
-       if (top.TYPO3.Backend.NavigationContainer.PageTree) {
-               top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
-       }
-
        top.nextLoadModuleUrl = url;
        top.TYPO3.ModuleMenu.App.showModule(modName);
-
 }
 
 /**
index 0cece6f..f3a9714 100644 (file)
@@ -723,13 +723,7 @@ require(['TYPO3/CMS/Backend/Utility'], function(Utility) {
                        TYPO3.Backend.ContentContainer.setUrl(
                                currentSubScript + separator + 'id=' + node.attributes.nodeData.id
                        ).then(function () {
-                               node.select();
-                               tree.currentSelectedNode = node;
-                               if (tree.stateHash) {
-                                       tree.stateHash.lastSelectedNode = node.id;
-                               }
-                               fsMod.recentIds['web'] = node.attributes.nodeData.id;
-                               fsMod.recentIds['system'] = node.attributes.nodeData.id;
+                               tree.selectNode(selectNode);
                        });
                },
 
index e8e60b9..8bc06bf 100644 (file)
@@ -179,6 +179,7 @@ TYPO3.Components.PageTree.App = Ext.extend(Ext.Panel, {
                        }
 
                        this.doLayout();
+                       this.selectRequestedPageId();
 
                }, this);
 
@@ -186,6 +187,15 @@ TYPO3.Components.PageTree.App = Ext.extend(Ext.Panel, {
        },
 
        /**
+        * Is true once initComponent has been called for rendering
+        *
+        * @returns {boolean}
+        */
+       isInitialized: function() {
+               return this.mainTree !== null;
+       },
+
+       /**
         * Adds the temporary mount point indicator item
         *
         * @return {void}
@@ -306,15 +316,25 @@ TYPO3.Components.PageTree.App = Ext.extend(Ext.Panel, {
        },
 
        /**
-        * Refreshes the tree and selects the node defined by fsMod.recentIds['web']
+        * Refreshes the tree and then selects the node defined by fsMod.recentIds['web']
         *
         * @return {void}
         */
        refreshTree: function() {
+               this.activeTree.refreshTree(function() {
+                       this.selectRequestedPageId();
+               }, this);
+       },
+
+       /**
+        * Selects the node defined by fsMod.recentIds['web']
+        *
+        * @return {void}
+        */
+       selectRequestedPageId: function() {
                if (!isNaN(fsMod.recentIds['web']) && fsMod.recentIds['web'] !== '') {
-                       this.select(fsMod.recentIds['web'], true);
+                       this.select(fsMod.recentIds['web']);
                }
-               this.activeTree.refreshTree();
        },
 
        /**
@@ -367,7 +387,12 @@ TYPO3.Components.PageTree.App = Ext.extend(Ext.Panel, {
                if (!allResults) {
                        nodePaths = [nodePaths[0]];
                }
-               Ext.each(nodePaths, function(nodePath) { callback('/root/' + nodePath.join('/')); });
+               var self = this;
+               Ext.each(nodePaths, function(nodePath) {
+                       callback('/root/' + nodePath.join('/'), 'id', function() {
+                               self.mainTree.selectNode(self.getSelected());
+                       });
+               });
        },
 
        /**
index 53ee07f..adfa795 100644 (file)
@@ -296,6 +296,22 @@ TYPO3.Components.PageTree.Tree = Ext.extend(Ext.tree.TreePanel, {
        },
 
        /**
+        * Selects the given node in the tree and stores this
+        * selection in various states, so that selection is kept when tree
+        * is reloaded.
+        *
+        * @param {Ext.tree.TreeNode} node
+        */
+       selectNode: function(node) {
+               node.select();
+               this.currentSelectedNode = node;
+               if (this.stateHash) {
+                       this.stateHash.lastSelectedNode = node.id;
+               }
+               fsMod.recentIds['web'] = node.attributes.nodeData.id;
+       },
+
+       /**
         * Adds a tree loader implementation that uses the directFn feature
         *
         * return {void}