[BUGFIX] Initialize selectTree in inline relations 84/49684/5
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 2 Sep 2016 15:51:55 +0000 (17:51 +0200)
committerBenni Mack <benni@typo3.org>
Sat, 3 Sep 2016 22:43:24 +0000 (00:43 +0200)
Adds a callback function when requiring the SelectTreeElement module,
so initialization is triggered every time it's required.

Adds check whether component was initialized to prevent
double initialization.

Fix variable name typo $overlayIcon to $overlayIconMarkup

Resolves: #76374
Releases: master
Change-Id: Idbffdc09bc7b4d8dfadd523e1c1ff41fd943ca25
Reviewed-on: https://review.typo3.org/49684
Tested-by: Lukas Raschke <lukas.raschke@web.de>
Reviewed-by: Markus Gehrig <markus.gehrig96@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Tested-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php
typo3/sysext/backend/Classes/Tree/Renderer/ExtJsJsonTreeRenderer.php
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Element/SelectTree.js
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Element/SelectTreeElement.js
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Element/SvgTree.js

index 6c10053..b23d40b 100644 (file)
@@ -107,7 +107,9 @@ class SelectTreeElement extends AbstractFormElement
         if ($showHeader) {
             $resultArray['additionalInlineLanguageLabelFiles'][] = 'EXT:lang/locallang_csh_corebe.xlf';
         }
-        $resultArray['requireJsModules']['selectTreeElement'] = 'TYPO3/CMS/Backend/FormEngine/Element/SelectTreeElement';
+        $resultArray['requireJsModules']['selectTreeElement'] = [
+            'TYPO3/CMS/Backend/FormEngine/Element/SelectTreeElement' => 'function (SelectTreeElement) { SelectTreeElement.initialize(); }'
+        ];
 
         return $resultArray;
     }
index 88606b7..4ff6365 100644 (file)
@@ -58,7 +58,7 @@ class ExtJsJsonTreeRenderer extends \TYPO3\CMS\Backend\Tree\Renderer\AbstractTre
         if (is_object($node->getIcon())) {
             $iconMarkup = $node->getIcon()->getMarkup(SvgIconProvider::MARKUP_IDENTIFIER_INLINE);
             if (is_object($node->getIcon()->getOverlayIcon())) {
-                $overlayIcon = $node->getIcon()->getOverlayIcon()->getMarkup(SvgIconProvider::MARKUP_IDENTIFIER_INLINE);
+                $overlayIconMarkup = $node->getIcon()->getOverlayIcon()->getMarkup(SvgIconProvider::MARKUP_IDENTIFIER_INLINE);
             }
         } else {
             $iconMarkup = $node->getIcon();
index 117ca3f..4c59809 100644 (file)
@@ -37,13 +37,15 @@ define(['d3', 'TYPO3/CMS/Backend/FormEngine/Element/SvgTree'], function (d3, Svg
      * @param {Object} settings
      */
     SelectTree.prototype.initialize = function (selector, settings) {
-        _super_.initialize.call(this, selector, settings);
-
+        if (!_super_.initialize.call(this, selector, settings)) {
+            return false;
+        }
         this.addIcons();
         this.dispatch.on('updateNodes.selectTree', this.updateNodes);
         this.dispatch.on('loadDataAfter.selectTree', this.loadDataAfter);
         this.dispatch.on('updateSvg.selectTree', this.renderCheckbox);
         this.dispatch.on('nodeSelectedAfter.selectTree', this.nodeSelectedAfter);
+        return true;
     };
 
     /**
index e1fe1c4..a596eae 100644 (file)
  */
 define(['jquery', 'TYPO3/CMS/Backend/FormEngine/Element/SelectTree'], function ($, SelectTree) {
     'use strict';
-    $(document).ready(function () {
+
+    var SelectTreeElement = {
+    };
+    SelectTreeElement.initialize = function () {
         $('.typo3-tceforms-tree .treeRecord').each(function (i, element) {
 
             /**
@@ -36,7 +39,7 @@ define(['jquery', 'TYPO3/CMS/Backend/FormEngine/Element/SelectTree'], function (
             var $wrapper = treeInput.parent().siblings('.svg-tree-wrapper');
             var dataUrl = TYPO3.settings.ajaxUrls['record_tree_data'] + '&' + TYPO3.jQuery.param(dataParams);
             var tree = new SelectTree();
-            tree.initialize($wrapper, {
+            var initialized = tree.initialize($wrapper, {
                 'dataUrl': dataUrl,
                 'showIcons': true,
                 'showCheckboxes': true,
@@ -46,6 +49,9 @@ define(['jquery', 'TYPO3/CMS/Backend/FormEngine/Element/SelectTree'], function (
                 'validation': treeInput.data('formengine-validation-rules')[0],
                 'expandUpToLevel': treeInput.data('tree-expand-up-to-level')
             });
+            if (!initialized) {
+                return;
+            }
             tree.dispatch.on('nodeSelectedAfter.requestUpdate', window[$wrapper.attr('id')]);
 
             if (treeInput.data('tree-show-toolbar')) {
@@ -55,5 +61,6 @@ define(['jquery', 'TYPO3/CMS/Backend/FormEngine/Element/SelectTree'], function (
                 });
             }
         });
-    });
+    };
+    return SelectTreeElement;
 });
\ No newline at end of file
index 0786ecc..804223e 100644 (file)
@@ -135,7 +135,7 @@ define(['jquery', 'd3'], function ($, d3) {
             var $wrapper = $(selector);
             // Do nothing if already initialized
             if ($wrapper.data('svgtree-initialized')) {
-                return;
+                return false;
             }
 
             $.extend(this.settings, settings);
@@ -168,6 +168,7 @@ define(['jquery', 'd3'], function ($, d3) {
             this.wrapper.data('svgtree', this);
             this.wrapper.data('svgtree-initialized', true);
             this.wrapper.trigger('svgTree.initialized');
+            return true;
         },
 
         /**