[TASK] Move FieldControl/ListModule handling to module 49/58649/5
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 18 Oct 2018 13:27:42 +0000 (15:27 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 29 Oct 2018 22:26:42 +0000 (23:26 +0100)
The FieldControl `ListModule` now uses a dedicated module for its
handling and no longer uses inline `onclick` handlers nor inline
FormEngine calls.

Resolves: #86647
Releases: master
Change-Id: Ibf47ee8ebaea584f88ccb9615681bd579e4cd305
Reviewed-on: https://review.typo3.org/58649
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Form/FieldControl/ListModule.php
typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/FieldControl/ListModule.ts [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/FieldControl/ListModule.js [new file with mode: 0644]

index d1b5fad..a8f1c7b 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Form\FieldControl;
 
 use TYPO3\CMS\Backend\Form\AbstractNode;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 use TYPO3\CMS\Backend\Form\AbstractNode;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * Renders the icon with link parameters to jump to the list module
 
 /**
  * Renders the icon with link parameters to jump to the list module
@@ -82,9 +83,8 @@ class ListModule extends AbstractNode
             ],
         ];
 
             ],
         ];
 
-        $onClick = [];
-        $onClick[] = 'this.blur();';
-        $onClick[] = 'return TYPO3.FormEngine.preventFollowLinkIfNotSaved(this.getAttribute(\'href\'));';
+        $id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
+
         /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
         $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
 
         /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
         $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
 
@@ -92,9 +92,12 @@ class ListModule extends AbstractNode
             'iconIdentifier' => 'actions-system-list-open',
             'title' => $title,
             'linkAttributes' => [
             'iconIdentifier' => 'actions-system-list-open',
             'title' => $title,
             'linkAttributes' => [
-                'onClick' => implode('', $onClick),
+                'id' => htmlspecialchars($id),
                 'href' => (string)$uriBuilder->buildUriFromRoute('wizard_list', $urlParameters),
             ],
                 'href' => (string)$uriBuilder->buildUriFromRoute('wizard_list', $urlParameters),
             ],
+            'requireJsModules' => [
+                ['TYPO3/CMS/Backend/FormEngine/FieldControl/ListModule' => 'function(FieldControl) {new FieldControl(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
+            ],
         ];
     }
 }
         ];
     }
 }
diff --git a/typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/FieldControl/ListModule.ts b/typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/FieldControl/ListModule.ts
new file mode 100644 (file)
index 0000000..f3dfbe2
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+import * as $ from 'jquery';
+import FormEngine = require('TYPO3/CMS/Backend/FormEngine');
+
+/**
+ * This module is used for the field control "List module" used for "group" fields
+ */
+class ListModule {
+  private controlElement: HTMLElement = null;
+
+  constructor(controlElementId: string) {
+    $((): void => {
+      this.controlElement = <HTMLElement>document.querySelector(controlElementId);
+      this.controlElement.addEventListener('click', this.registerClickHandler);
+    });
+  }
+
+  /**
+   * @param {Event} e
+   */
+  private registerClickHandler = (e: Event): void => {
+    e.preventDefault();
+
+    FormEngine.preventFollowLinkIfNotSaved(this.controlElement.getAttribute('href'));
+  }
+}
+
+export = ListModule;
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/FieldControl/ListModule.js b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/FieldControl/ListModule.js
new file mode 100644 (file)
index 0000000..1b3c548
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+define(["require","exports","jquery","TYPO3/CMS/Backend/FormEngine"],function(e,t,n,r){"use strict";return function(e){var t=this;this.controlElement=null,this.registerClickHandler=function(e){e.preventDefault(),r.preventFollowLinkIfNotSaved(t.controlElement.getAttribute("href"))},n(function(){t.controlElement=document.querySelector(e),t.controlElement.addEventListener("click",t.registerClickHandler)})}});
\ No newline at end of file