[BUGFIX] Remember selected page in fsMod and refactor page selection 76/57076/3
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Mon, 28 May 2018 16:55:29 +0000 (18:55 +0200)
committerBenni Mack <benni@typo3.org>
Wed, 30 May 2018 20:22:03 +0000 (22:22 +0200)
Currently selected page is remembered in the fsMod js object.
The JS code responsible for handling click on the node text and node
background is refactored. Now both uses node.checked property.

Resolves: #85100
Resolves: #85106
Releases: master
Change-Id: I08768e82a62e942c247d968df707bf64426e1dab
Reviewed-on: https://review.typo3.org/57076
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Controller/PageLayoutController.php
typo3/sysext/backend/Resources/Public/JavaScript/PageTree/PageTree.js
typo3/sysext/backend/Resources/Public/JavaScript/SvgTree.js
typo3/sysext/backend/Resources/Public/JavaScript/backend.js
typo3/sysext/recordlist/Classes/Controller/RecordListController.php
typo3/sysext/sys_action/Classes/ActionTask.php

index c5495b8..ffdefd3 100644 (file)
@@ -729,7 +729,7 @@ class PageLayoutController
             $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
                 if (top.fsMod) {
                     top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
-                    top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank;
+                    top.fsMod.navFrameHighlightedID["web"] = top.fsMod.currentBank + "_" + ' . (int)$this->id . ';
                 }
                 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
                 function deleteRecord(table,id,url) {   //
index c53d3b9..fcfbac7 100644 (file)
@@ -55,6 +55,7 @@ define(['jquery',
       _this.dispatch.on('nodeRightClick.pageTree', _this.nodeRightClick);
       _this.dispatch.on('contextmenu.pageTree', _this.contextmenu);
       _this.dispatch.on('updateSvg.pageTree', _this.updateSvg);
+      _this.dispatch.on('prepareLoadedNode.pageTree', _this.prepareLoadedNode);
       _this.dragDrop = PageTreeDragDrop;
       _this.dragDrop.init(_this);
 
@@ -186,12 +187,16 @@ define(['jquery',
      * @param {Node} node
      */
     PageTree.prototype.nodeSelectedAfter = function(node) {
+      //remember the selected page in the global state
+      fsMod.recentIds.web = node.identifier;
+      fsMod.currentBank = node.stateIdentifier.split('_')[0];
+      fsMod.navFrameHighlightedID.web = node.stateIdentifier;
+
       var separator = '?';
       if (currentSubScript.indexOf('?') !== -1) {
         separator = '&';
       }
 
-      fsMod.recentIds.web = node.identifier;
       TYPO3.Backend.ContentContainer.setUrl(
         currentSubScript + separator + 'id=' + node.identifier
       );
@@ -233,6 +238,18 @@ define(['jquery',
         .attr('data-context', 'tree');
     };
 
+    /**
+     * Event listener called for each loaded node,
+     * here used to mark node remembered in fsMode as selected
+     *
+     * @param node
+     */
+    PageTree.prototype.prepareLoadedNode = function(node) {
+      if (node.stateIdentifier === fsMod.navFrameHighlightedID.web) {
+        node.checked = true;
+      }
+    };
+
     PageTree.prototype.hideChildren = function(node) {
       _super_.hideChildren(node);
       Persistent.set('BackendComponents.States.Pagetree.stateHash.' + node.stateIdentifier, 0);
@@ -275,6 +292,35 @@ define(['jquery',
     };
 
     /**
+     * Node selection logic (triggered by different events)
+     * Page tree supports only one node to be selected at a time
+     * so the default function from SvgTree needs to be overriden
+     *
+     * @param {Node} node
+     */
+    PageTree.prototype.selectNode = function (node) {
+      if (!this.isNodeSelectable(node)) {
+        return;
+      }
+
+      var _this = this;
+      var checked = node.checked;
+
+      var selectedNodes = this.getSelectedNodes();
+      selectedNodes.forEach(function (node) {
+        if (node.checked === true) {
+          node.checked = false;
+          _this.dispatch.call('nodeSelectedAfter', _this, node);
+        }
+      });
+
+      node.checked = true;
+
+      this.dispatch.call('nodeSelectedAfter', this, node);
+      this.update();
+    };
+
+    /**
      * Event handler for double click on a node's label
      * Changed text position if there is 'stop page tree' option
      *
index dff70fc..f468927 100644 (file)
@@ -568,7 +568,6 @@ define(
             _this.nodeBgEvents().mouseOut(node, this);
           })
           .on('click', function(node) {
-            _this.nodeBgEvents().click(node, this);
             _this.selectNode(node);
           })
           .on('contextmenu', function(node) {
@@ -612,25 +611,6 @@ define(
           }
         };
 
-        self.click = function(node, element) {
-          var $nodeBg = $(element).closest('svg').find('.nodes-bg .node-bg[data-state-id=' + node.stateIdentifier + ']');
-
-          _this.nodes.forEach(function(node) {
-            if (node.selected === true) {
-              node.selected = false;
-            }
-          });
-
-          node.selected = true;
-          if ($nodeBg.length) {
-            $nodeBg.addClass('node-selected')
-              .parents('svg')
-              .find('.node-selected')
-              .not($nodeBg)
-              .removeClass('node-selected');
-          }
-        };
-
         return self;
       },
 
@@ -882,7 +862,7 @@ define(
           nextNode = nodeBgClass.data()[i + 1];
         }
 
-        if (node.selected) {
+        if (node.checked) {
           bgClass += ' node-selected';
         }
 
@@ -1113,7 +1093,6 @@ define(
        */
       clickOnLabel: function(node, element) {
         this.selectNode(node);
-        this.nodeBgEvents().click(node, element);
       },
 
       /**
index db65a90..64e214d 100644 (file)
@@ -97,7 +97,7 @@ function openUrlInWindow(url, windowName) {   //
  */
 function loadEditId(id, addGetVars) {  //
   top.fsMod.recentIds.web = id;
-  top.fsMod.navFrameHighlightedID.web = "pages" + id + "_0";           // For highlighting
+  top.fsMod.navFrameHighlightedID.web = '0_' + id; // For highlighting
 
   if (top.nav_frame && top.nav_frame.refresh_nav) {
     top.nav_frame.refresh_nav();
index 42c5199..84617ae 100644 (file)
@@ -390,12 +390,12 @@ class RecordListController
             $this->moduleTemplate->addJavaScriptCode(
                 'RecordListInlineJS',
                 '
-                               function jumpExt(URL,anchor) {  //
+                               function jumpExt(URL,anchor) {
                                        var anc = anchor?anchor:"";
                                        window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
                                        return false;
                                }
-                               function jumpSelf(URL) {        //
+                               function jumpSelf(URL) {
                                        window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
                                        return false;
                                }
@@ -404,9 +404,9 @@ class RecordListController
                                        return false;
                                }
 
-                               function setHighlight(id) {     //
-                                       top.fsMod.recentIds["web"]=id;
-                                       top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank;    // For highlighting
+                               function setHighlight(id) {
+                                       top.fsMod.recentIds["web"] = id;
+                                       top.fsMod.navFrameHighlightedID["web"] = top.fsMod.currentBank + "_" + id; // For highlighting
 
                                        if (top.nav_frame && top.nav_frame.refresh_nav) {
                                                top.nav_frame.refresh_nav();
@@ -414,10 +414,10 @@ class RecordListController
                                }
                                ' . $this->moduleTemplate->redirectUrls($listUrl) . '
                                ' . $dblist->CBfunctions() . '
-                               function editRecords(table,idList,addParams,CBflag) {   //
+                               function editRecords(table,idList,addParams,CBflag) {
                                        window.location.href="' . (string)$uriBuilder->buildUriFromRoute('record_edit', ['returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]) . '&edit["+table+"]["+idList+"]=edit"+addParams;
                                }
-                               function editList(table,idList) {       //
+                               function editList(table,idList) {
                                        var list="";
 
                                                // Checking how many is checked, how many is not
index 3d6ffee..883b158 100644 (file)
@@ -940,8 +940,8 @@ class ActionTask implements \TYPO3\CMS\Taskcenter\TaskInterface
                                }
 
                                function setHighlight(id) {
-                                       top.fsMod.recentIds["web"]=id;
-                                       top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank;    // For highlighting
+                                       top.fsMod.recentIds["web"] = id;
+                                       top.fsMod.navFrameHighlightedID["web"] = top.fsMod.currentBank + "_" + id; // For highlighting
 
                                        if (top.nav_frame && top.nav_frame.refresh_nav) {
                                                top.nav_frame.refresh_nav();