[TASK] Migrate NewMultiplePages to TypeScript 10/55910/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Mon, 26 Feb 2018 20:12:59 +0000 (21:12 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Tue, 27 Feb 2018 08:39:59 +0000 (09:39 +0100)
Change-Id: I3fb32010cbbf319ddc35a9c0e13a771625e9c5be
Resolves: #82598
Releases: master
Reviewed-on: https://review.typo3.org/55910
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Resources/Private/TypeScript/NewMultiplePages.ts [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/NewMultiplePages.js

diff --git a/typo3/sysext/backend/Resources/Private/TypeScript/NewMultiplePages.ts b/typo3/sysext/backend/Resources/Private/TypeScript/NewMultiplePages.ts
new file mode 100644 (file)
index 0000000..903aade
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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';
+
+enum Identifiers {
+  containerSelector = '.t3js-newmultiplepages-container',
+  addMoreFieldsButtonSelector = '.t3js-newmultiplepages-createnewfields',
+  doktypeSelector = '.t3js-newmultiplepages-select-doktype',
+  templateRow = '.t3js-newmultiplepages-newlinetemplate'
+}
+
+/**
+ * Module: TYPO3/CMS/Backend/NewMultiplePages
+ * JavaScript functions for creating multiple pages
+ */
+class NewMultiplePages {
+  private lineCounter: number = 5;
+
+  constructor() {
+    $((): void => {
+      this.initializeEvents();
+    });
+  }
+
+  /**
+   * Register listeners
+   */
+  private initializeEvents(): void {
+    $(Identifiers.addMoreFieldsButtonSelector).on('click', (): void => {
+      this.createNewFormFields();
+    });
+
+    $(document).on('change', Identifiers.doktypeSelector, (e: JQueryEventObject): void => {
+      this.actOnTypeSelectChange($(e.currentTarget));
+    });
+  }
+
+  /**
+   * Add further input rows
+   */
+  private createNewFormFields(): void {
+    for (let i = 0; i < 5; i++) {
+      const label = this.lineCounter + i + 1;
+      const line = $(Identifiers.templateRow).html()
+        .replace(/\[0\]/g, (this.lineCounter + i).toString())
+        .replace(/\[1\]/g, label.toString());
+      $(line).appendTo(Identifiers.containerSelector);
+    }
+    this.lineCounter += 5;
+  }
+
+  /**
+   * @param {JQuery} $selectElement
+   */
+  private actOnTypeSelectChange($selectElement: JQuery): void {
+    const $optionElement = $selectElement.find(':selected');
+    const $target = $($selectElement.data('target'));
+    $target.html($optionElement.data('icon'));
+  }
+}
+
+export = new NewMultiplePages();
index 5af8fb1..ca5775d 100644 (file)
  *
  * The TYPO3 project - inspiring people to share!
  */
  *
  * The TYPO3 project - inspiring people to share!
  */
-
-/**
- * Module: TYPO3/CMS/Backend/NewMultiplePages
- * JavaScript functions for creating multiple pages
- */
-define(['jquery'], function($) {
-  'use strict';
-
-  /**
-   * @type {{lineCounter: number, containerSelector: string, addMoreFieldsButtonSelector: string, doktypeSelector: string}}
-   * @exports TYPO3/CMS/Backend/NewMultiplePages
-   */
-  var NewMultiplePages = {
-    lineCounter: 5,
-    containerSelector: '.t3js-newmultiplepages-container',
-    addMoreFieldsButtonSelector: '.t3js-newmultiplepages-createnewfields',
-    doktypeSelector: '.t3js-newmultiplepages-select-doktype',
-    templateRow: '.t3js-newmultiplepages-newlinetemplate'
-  };
-
-  /**
-   * Add further input rows
-   */
-  NewMultiplePages.createNewFormFields = function() {
-    for (var i = 0; i < 5; i++) {
-      var label = NewMultiplePages.lineCounter + i + 1;
-      var line = $(NewMultiplePages.templateRow).html()
-        .replace(/\[0\]/g, (NewMultiplePages.lineCounter + i))
-        .replace(/\[1\]/g, label);
-      $(line).appendTo(NewMultiplePages.containerSelector);
-    }
-    NewMultiplePages.lineCounter += 5;
-  };
-
-  /**
-   * @param {Object} $selectElement
-   */
-  NewMultiplePages.actOnTypeSelectChange = function($selectElement) {
-    var $optionElement = $selectElement.find(':selected');
-    var $target = $($selectElement.data('target'));
-    $target.html($optionElement.data('icon'));
-  };
-
-  /**
-   * Register listeners
-   */
-  NewMultiplePages.initializeEvents = function() {
-    $(NewMultiplePages.addMoreFieldsButtonSelector).on('click', function() {
-      NewMultiplePages.createNewFormFields();
-    });
-
-    $(document).on('change', NewMultiplePages.doktypeSelector, function() {
-      NewMultiplePages.actOnTypeSelectChange($(this));
-    });
-  };
-
-  $(NewMultiplePages.initializeEvents);
-
-  return NewMultiplePages;
-});
+define(["require","exports","jquery"],function(a,b,c){"use strict";var d;!function(a){a.containerSelector=".t3js-newmultiplepages-container",a.addMoreFieldsButtonSelector=".t3js-newmultiplepages-createnewfields",a.doktypeSelector=".t3js-newmultiplepages-select-doktype",a.templateRow=".t3js-newmultiplepages-newlinetemplate"}(d||(d={}));var e=function(){function a(){var a=this;this.lineCounter=5,c(function(){a.initializeEvents()})}return a.prototype.initializeEvents=function(){var a=this;c(d.addMoreFieldsButtonSelector).on("click",function(){a.createNewFormFields()}),c(document).on("change",d.doktypeSelector,function(b){a.actOnTypeSelectChange(c(b.currentTarget))})},a.prototype.createNewFormFields=function(){for(var a=0;a<5;a++){var b=this.lineCounter+a+1,e=c(d.templateRow).html().replace(/\[0\]/g,(this.lineCounter+a).toString()).replace(/\[1\]/g,b.toString());c(e).appendTo(d.containerSelector)}this.lineCounter+=5},a.prototype.actOnTypeSelectChange=function(a){var b=a.find(":selected"),d=c(a.data("target"));d.html(b.data("icon"))},a}();return new e});
\ No newline at end of file