[TASK] Move FieldControl/TableWizard handling to module 50/58650/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 18 Oct 2018 13:32:23 +0000 (15:32 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 29 Oct 2018 21:48:14 +0000 (22:48 +0100)
The FieldControl `TableWizard` now uses a dedicated module for its
handling and no longer uses inline `onclick` handlers nor inline
FormEngine calls.

Resolves: #86649
Releases: master
Change-Id: I1cb71ad317f737afb0d943a4278583888737bcab
Reviewed-on: https://review.typo3.org/58650
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Form/FieldControl/TableWizard.php
typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/FieldControl/TableWizard.ts [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/FieldControl/TableWizard.js [new file with mode: 0644]

index e593b2e..e42a1ec 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Backend\Form\FieldControl;
 use TYPO3\CMS\Backend\Form\AbstractNode;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * Renders the icon with link parameters to the table wizard,
@@ -66,18 +67,20 @@ class TableWizard 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);
         return [
             'iconIdentifier' => 'content-table',
             'title' => $title,
             'linkAttributes' => [
-                'onClick' => implode('', $onClick),
+                'id' => htmlspecialchars($id),
                 'href' => (string)$uriBuilder->buildUriFromRoute('wizard_table', $urlParameters),
             ],
+            'requireJsModules' => [
+                ['TYPO3/CMS/Backend/FormEngine/FieldControl/TableWizard' => 'function(FieldControl) {new FieldControl(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
+            ],
         ];
     }
 }
diff --git a/typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/FieldControl/TableWizard.ts b/typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/FieldControl/TableWizard.ts
new file mode 100644 (file)
index 0000000..3e99c5c
--- /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');
+
+/**
+ * Handles the "Table wizard" field control
+ */
+class TableWizard {
+  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 = TableWizard;
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/FieldControl/TableWizard.js b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/FieldControl/TableWizard.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