[TASK] Migrate AdminPanel modules to TypeScript 89/59689/4
authorFrank Naegler <frank.naegler@typo3.org>
Wed, 13 Feb 2019 08:54:40 +0000 (09:54 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 17 Feb 2019 09:46:57 +0000 (10:46 +0100)
Resolves: #87702
Releases: master
Change-Id: I5e90dd30a006304005693a629270c1d787655974
Reviewed-on: https://review.typo3.org/c/59689
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/adminpanel/Classes/Modules/TsDebugModule.php
typo3/sysext/adminpanel/Resources/Private/TypeScript/Modules/Cache.ts [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/TypeScript/Modules/Preview.ts [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Public/JavaScript/Modules/Cache.js
typo3/sysext/adminpanel/Resources/Public/JavaScript/Modules/Preview.js
typo3/sysext/adminpanel/Resources/Public/JavaScript/Modules/TsDebug.js [deleted file]

index 949615b..af1a7ca 100644 (file)
@@ -17,7 +17,6 @@ namespace TYPO3\CMS\Adminpanel\Modules;
  */
 
 use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
-use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
 use TYPO3\CMS\Adminpanel\ModuleApi\ShortInfoProviderInterface;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -25,7 +24,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 /**
  * Admin Panel TypoScript Debug Module
  */
-class TsDebugModule extends AbstractModule implements ShortInfoProviderInterface, ResourceProviderInterface
+class TsDebugModule extends AbstractModule implements ShortInfoProviderInterface
 {
     /**
      * @inheritdoc
@@ -77,20 +76,4 @@ class TsDebugModule extends AbstractModule implements ShortInfoProviderInterface
     {
         return GeneralUtility::makeInstance(TimeTracker::class);
     }
-
-    /**
-     * @inheritdoc
-     */
-    public function getJavaScriptFiles(): array
-    {
-        return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/TsDebug.js'];
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function getCssFiles(): array
-    {
-        return [];
-    }
 }
diff --git a/typo3/sysext/adminpanel/Resources/Private/TypeScript/Modules/Cache.ts b/typo3/sysext/adminpanel/Resources/Private/TypeScript/Modules/Cache.ts
new file mode 100644 (file)
index 0000000..efdfabe
--- /dev/null
@@ -0,0 +1,29 @@
+namespace TYPO3 {
+  export class Cache {
+    private buttons: Array<Element>;
+
+    constructor() {
+      this.buttons = Array.from(document.querySelectorAll('[data-typo3-role="clearCacheButton"]'));
+
+      this.buttons.forEach((element: HTMLElement): void => {
+        element.addEventListener('click', (): void => {
+          let url = element.dataset.typo3AjaxUrl;
+          let request = new XMLHttpRequest();
+          request.open('GET', url);
+          request.send();
+          request.onload = (): void => {
+            location.reload();
+          };
+        });
+      });
+    }
+  }
+}
+
+((): void => {
+  window.addEventListener(
+    'load',
+    () => new TYPO3.Cache(),
+    false
+  );
+})();
diff --git a/typo3/sysext/adminpanel/Resources/Private/TypeScript/Modules/Preview.ts b/typo3/sysext/adminpanel/Resources/Private/TypeScript/Modules/Preview.ts
new file mode 100644 (file)
index 0000000..4334639
--- /dev/null
@@ -0,0 +1,55 @@
+namespace TYPO3 {
+  export class Preview {
+    private readonly dateField: HTMLInputElement = null;
+    private readonly timeField: HTMLInputElement = null;
+    private readonly targetField: HTMLInputElement = null;
+
+    constructor() {
+      this.dateField = <HTMLInputElement>document.getElementById('preview_simulateDate-date-hr');
+      this.timeField = <HTMLInputElement>document.getElementById('preview_simulateDate-time-hr');
+      this.targetField = <HTMLInputElement>document.getElementById(this.dateField.dataset.target);
+
+      if (this.targetField.value) {
+        const cd = new Date(this.targetField.value);
+        this.dateField.value =
+          cd.getFullYear() + '-' + ((cd.getMonth() + 1) < 10 ? '0' : '')
+          + (cd.getMonth() + 1) + '-' + (cd.getDate() < 10 ? '0' : '') + cd.getDate();
+        this.timeField.value =
+          (cd.getHours() < 10 ? '0' : '') + cd.getHours() + ':'
+          + (cd.getMinutes() < 10 ? '0' : '') + cd.getMinutes();
+      }
+
+      this.dateField.addEventListener('change', this.updateDateField);
+      this.timeField.addEventListener('change', this.updateDateField);
+    }
+
+    private updateDateField = (): void => {
+      let dateVal = this.dateField.value;
+      let timeVal = this.timeField.value;
+      if (!dateVal && timeVal) {
+        let tempDate = new Date();
+        dateVal = tempDate.getFullYear() + '-' + (tempDate.getMonth() + 1) + '-' + tempDate.getDate();
+      }
+      if (dateVal && !timeVal) {
+        timeVal =  '00:00';
+      }
+
+      if (!dateVal && !timeVal) {
+        this.targetField.value = '';
+      } else {
+        const stringDate = dateVal + ' ' + timeVal;
+        const date = new Date(stringDate);
+
+        this.targetField.value = date.toISOString();
+      }
+    }
+  }
+}
+
+((): void => {
+  window.addEventListener(
+    'load',
+    () => new TYPO3.Preview(),
+    false
+  );
+})();
index 28a00b6..21945ac 100644 (file)
@@ -1,19 +1,13 @@
-function initializeCacheModule() {
-       var buttons = Array.from(document.querySelectorAll('[data-typo3-role=clearCacheButton]'));
-
-       buttons.forEach(function (elem) {
-               elem.addEventListener('click', clearCache);
-       });
-}
-
-function clearCache() {
-       var url = this.dataset.typo3AjaxUrl;
-       var request = new XMLHttpRequest();
-       request.open("GET", url);
-       request.send();
-       request.onload = function () {
-               location.reload();
-       };
-}
-
-window.addEventListener('load', initializeCacheModule, false);
+/*
+ * 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!
+ */
+"use strict";var TYPO3;!function(t){var n=function(){this.buttons=Array.from(document.querySelectorAll('[data-typo3-role="clearCacheButton"]')),this.buttons.forEach(function(t){t.addEventListener("click",function(){var n=t.dataset.typo3AjaxUrl,e=new XMLHttpRequest;e.open("GET",n),e.send(),e.onload=function(){location.reload()}})})};(TYPO3||(TYPO3={})).Cache=n}(),window.addEventListener("load",function(){return new TYPO3.Cache},!1);
\ No newline at end of file
index 4960176..4e58e3b 100644 (file)
@@ -1,35 +1,13 @@
-
-function initializePreviewModule() {
-       var dateField = document.getElementById('preview_simulateDate-date-hr');
-       var timeField = document.getElementById('preview_simulateDate-time-hr');
-       var targetField = document.getElementById(dateField.dataset.target);
-       if (targetField.value) {
-               var cd = new Date(targetField.value);
-               document.getElementById('preview_simulateDate-date-hr').value = cd.getFullYear() + "-" + ((cd.getMonth()+1) < 10 ? '0' : '') + (cd.getMonth()+1) + "-" + (cd.getDate() < 10 ? '0' : '') + cd.getDate();
-               document.getElementById('preview_simulateDate-time-hr').value = (cd.getHours() < 10 ? '0' : '') + cd.getHours() + ":" + (cd.getMinutes() < 10 ? '0' : '') + cd.getMinutes();
-       }
-
-       var updateDateField = function () {
-               var dateVal = document.getElementById('preview_simulateDate-date-hr').value;
-               var timeVal = document.getElementById('preview_simulateDate-time-hr').value;
-               if (!dateVal && timeVal) {
-                       var tempDate = new Date();
-                       dateVal = tempDate.getFullYear() + "-" + (tempDate.getMonth() + 1) + "-" + tempDate.getDate();
-               }
-               if (dateVal && !timeVal) {
-                       timeVal =  "00:00";
-               }
-
-               if(!dateVal && !timeVal) {
-                       targetField.value = "";
-               } else {
-                       var stringDate = dateVal + " " + timeVal;
-                       var date = new Date(stringDate);
-                       targetField.value = date.toISOString();
-               }
-       };
-       dateField.addEventListener('change', updateDateField);
-       timeField.addEventListener('change', updateDateField);
-}
-
-window.addEventListener('load', initializePreviewModule, false);
+/*
+ * 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!
+ */
+"use strict";var TYPO3;!function(e){var t=function(){var e=this;if(this.dateField=null,this.timeField=null,this.targetField=null,this.updateDateField=function(){var t=e.dateField.value,i=e.timeField.value;if(!t&&i){var a=new Date;t=a.getFullYear()+"-"+(a.getMonth()+1)+"-"+a.getDate()}if(t&&!i&&(i="00:00"),t||i){var d=new Date(t+" "+i);e.targetField.value=d.toISOString()}else e.targetField.value=""},this.dateField=document.getElementById("preview_simulateDate-date-hr"),this.timeField=document.getElementById("preview_simulateDate-time-hr"),this.targetField=document.getElementById(this.dateField.dataset.target),this.targetField.value){var t=new Date(this.targetField.value);this.dateField.value=t.getFullYear()+"-"+(t.getMonth()+1<10?"0":"")+(t.getMonth()+1)+"-"+(t.getDate()<10?"0":"")+t.getDate(),this.timeField.value=(t.getHours()<10?"0":"")+t.getHours()+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()}this.dateField.addEventListener("change",this.updateDateField),this.timeField.addEventListener("change",this.updateDateField)};(TYPO3||(TYPO3={})).Preview=t}(),window.addEventListener("load",function(){return new TYPO3.Preview},!1);
\ No newline at end of file
diff --git a/typo3/sysext/adminpanel/Resources/Public/JavaScript/Modules/TsDebug.js b/typo3/sysext/adminpanel/Resources/Public/JavaScript/Modules/TsDebug.js
deleted file mode 100644 (file)
index e69de29..0000000