[BUGFIX] Ensure correct page is selected in page tree 92/54492/2
authorHelmut Hummel <typo3@helhum.io>
Sat, 28 Oct 2017 10:35:24 +0000 (12:35 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Mon, 30 Oct 2017 16:36:11 +0000 (17:36 +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/54492
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
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 b299fde..8efb1df 100644 (file)
@@ -165,9 +165,17 @@ require(
 
                        showModule: function (mod, params) {
                                params = params || '';
-                               params = this.includeId(mod, params);
                                var record = this.getRecordFromName(mod);
                                this.loadModuleComponents(record, params);
+                               this.ensurePageInTreeSelected();
+                       },
+
+                       ensurePageInTreeSelected: function () {
+                               if (this.loadedNavigationComponentId === 'typo3-pagetree'
+                                       && this.availableNavigationComponents['typo3-pagetree'].isInitialized()
+                               ) {
+                                       this.availableNavigationComponents['typo3-pagetree'].selectRequestedPageId();
+                               }
                        },
 
                        loadModuleComponents: function (record, params) {
@@ -183,6 +191,7 @@ require(
 
                                this.highlightModuleMenuItem(mod);
                                this.loadedModule = mod;
+                               params = this.includeId(record, params);
                                this.openInContentFrame(record.link, params);
 
                                // compatibility
@@ -192,12 +201,17 @@ require(
                                TYPO3.Backend.doLayout();
                        },
 
-                       includeId: function (mod, params) {
-                               if (typeof mod === 'undefined') {
+                       includeId: function (moduleData, params) {
+                               if (!moduleData.navigationComponentId && !moduleData.navigationFrameScript) {
                                        return params;
                                }
                                //get id
-                               var section = mod.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 adeeda1..8b68224 100644 (file)
@@ -58,7 +58,7 @@ define(
                                PageTree: {
                                        refreshTree: function() {
                                                if (typeof Ext.getCmp('typo3-pagetree') !== 'undefined') {
-                                                       Ext.getCmp('typo3-pagetree').activeTree.refreshTree();
+                                                       Ext.getCmp('typo3-pagetree').refreshTree();
                                                }
                                        }
                                },
index 5dd4097..8ed2e7c 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 b74bb2c..5553866 100644 (file)
@@ -709,20 +709,12 @@ TYPO3.Components.PageTree.Actions = {
         * @return {void}
         */
        singleClick: function(node, tree) {
-               tree.currentSelectedNode = node;
+               tree.selectNode(node);
 
                var separator = '?';
                if (currentSubScript.indexOf('?') !== -1) {
                        separator = '&';
                }
-
-               node.select();
-               if (tree.stateHash) {
-                       tree.stateHash.lastSelectedNode = node.id;
-               }
-
-               fsMod.recentIds['web'] = node.attributes.nodeData.id;
-
                TYPO3.Backend.ContentContainer.setUrl(
                        currentSubScript + separator + 'id=' + node.attributes.nodeData.id
                );
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}