Convert `Acp/Ui/Devtools/Project/Installation/Confirmation` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Sun, 3 Jan 2021 14:41:10 +0000 (15:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 3 Jan 2021 14:41:10 +0000 (15:41 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation.ts [new file with mode: 0644]

index ed469abaf9e2f20db3b890f3f2e4388b1a1df6cd..6df3e25fb90079a4c7cfcd3a11b7e861f027e7aa 100644 (file)
@@ -1,56 +1,58 @@
 /**
  * Handles installing a project as a package.
  *
- * @author     Matthias Schmidt
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation
+ * @author  Matthias Schmidt
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation
  */
-define(['Ajax', 'Language', 'Ui/Confirmation'], function (Ajax, Language, UiConfirmation) {
+define(["require", "exports", "tslib", "../../../../../Ajax", "../../../../../Language", "../../../../../Ui/Confirmation"], function (require, exports, tslib_1, Ajax, Language, UiConfirmation) {
     "use strict";
-    var _projectId;
-    var _projectName;
-    return {
-        /**
-         * Initializes the confirmation to install a project as a package.
-         *
-         * @param      {int}           projectId       id of the installed project
-         * @param      {string}        projectName     name of the installed project
-         */
-        init: function (projectId, projectName) {
-            _projectId = projectId;
-            _projectName = projectName;
-            [].forEach.call(elByClass('jsDevtoolsInstallPackage'), function (element) {
-                element.addEventListener('click', this._showConfirmation.bind(this));
-            }.bind(this));
-        },
-        /**
-         * Starts the package installation.
-         */
-        _installPackage: function () {
-            Ajax.apiOnce({
-                data: {
-                    actionName: 'installPackage',
-                    className: 'wcf\\data\\devtools\\project\\DevtoolsProjectAction',
-                    objectIDs: [_projectId]
-                },
-                success: function (data) {
-                    var packageInstallation = new WCF.ACP.Package.Installation(data.returnValues.queueID, 'DevtoolsInstallPackage', data.returnValues.isApplication, false, { projectID: _projectId });
-                    packageInstallation.prepareInstallation();
-                }
-            });
-        },
-        /**
-         * Shows the confirmation to start package installation.
-         */
-        _showConfirmation: function () {
-            UiConfirmation.show({
-                confirm: this._installPackage.bind(this),
-                message: Language.get('wcf.acp.devtools.project.installPackage.confirmMessage', {
-                    packageIdentifier: _projectName
-                }),
-                messageIsHtml: true
-            });
-        }
-    };
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.init = void 0;
+    Ajax = tslib_1.__importStar(Ajax);
+    Language = tslib_1.__importStar(Language);
+    UiConfirmation = tslib_1.__importStar(UiConfirmation);
+    let _projectId;
+    let _projectName;
+    /**
+     * Starts the package installation.
+     */
+    function installPackage() {
+        Ajax.apiOnce({
+            data: {
+                actionName: "installPackage",
+                className: "wcf\\data\\devtools\\project\\DevtoolsProjectAction",
+                objectIDs: [_projectId],
+            },
+            success: (data) => {
+                const packageInstallation = new window.WCF.ACP.Package.Installation(data.returnValues.queueID, "DevtoolsInstallPackage", data.returnValues.isApplication, false, { projectID: _projectId });
+                packageInstallation.prepareInstallation();
+            },
+        });
+    }
+    /**
+     * Shows the confirmation to start package installation.
+     */
+    function showConfirmation(event) {
+        event.preventDefault();
+        UiConfirmation.show({
+            confirm: () => installPackage(),
+            message: Language.get("wcf.acp.devtools.project.installPackage.confirmMessage", {
+                packageIdentifier: _projectName,
+            }),
+            messageIsHtml: true,
+        });
+    }
+    /**
+     * Initializes the confirmation to install a project as a package.
+     */
+    function init(projectId, projectName) {
+        _projectId = projectId;
+        _projectName = projectName;
+        document.querySelectorAll(".jsDevtoolsInstallPackage").forEach((element) => {
+            element.addEventListener("click", (ev) => showConfirmation(ev));
+        });
+    }
+    exports.init = init;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation.js
deleted file mode 100644 (file)
index 0e463c8..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Handles installing a project as a package.
- *
- * @author     Matthias Schmidt
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation
- */
-define(['Ajax', 'Language', 'Ui/Confirmation'], function(Ajax, Language, UiConfirmation) {
-       "use strict";
-       
-       var _projectId;
-       var _projectName;
-       
-       return {
-               /**
-                * Initializes the confirmation to install a project as a package.
-                * 
-                * @param       {int}           projectId       id of the installed project
-                * @param       {string}        projectName     name of the installed project
-                */
-               init: function(projectId, projectName) {
-                       _projectId = projectId;
-                       _projectName = projectName;
-                       
-                       [].forEach.call(elByClass('jsDevtoolsInstallPackage'), function(element) {
-                               element.addEventListener('click', this._showConfirmation.bind(this));
-                       }.bind(this));
-               },
-               
-               /**
-                * Starts the package installation.
-                */
-               _installPackage: function() {
-                       Ajax.apiOnce({
-                               data: {
-                                       actionName: 'installPackage',
-                                       className: 'wcf\\data\\devtools\\project\\DevtoolsProjectAction',
-                                       objectIDs: [ _projectId ]
-                               },
-                               success: function(data) {
-                                       var packageInstallation = new WCF.ACP.Package.Installation(
-                                               data.returnValues.queueID,
-                                               'DevtoolsInstallPackage',
-                                               data.returnValues.isApplication,
-                                               false,
-                                               {projectID: _projectId}
-                                       );
-                                       
-                                       packageInstallation.prepareInstallation();
-                               }
-                       });
-               },
-               
-               /**
-                * Shows the confirmation to start package installation.
-                */
-               _showConfirmation: function() {
-                       UiConfirmation.show({
-                               confirm: this._installPackage.bind(this),
-                               message: Language.get('wcf.acp.devtools.project.installPackage.confirmMessage', {
-                                       packageIdentifier: _projectName
-                               }),
-                               messageIsHtml: true
-                       });
-               }
-       };
-});
\ No newline at end of file
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation.ts
new file mode 100644 (file)
index 0000000..eb6d245
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * Handles installing a project as a package.
+ *
+ * @author  Matthias Schmidt
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Acp/Ui/Devtools/Project/Installation/Confirmation
+ */
+
+import * as Ajax from "../../../../../Ajax";
+import * as Language from "../../../../../Language";
+import * as UiConfirmation from "../../../../../Ui/Confirmation";
+
+let _projectId: number;
+let _projectName: string;
+
+/**
+ * Starts the package installation.
+ */
+function installPackage(): void {
+  Ajax.apiOnce({
+    data: {
+      actionName: "installPackage",
+      className: "wcf\\data\\devtools\\project\\DevtoolsProjectAction",
+      objectIDs: [_projectId],
+    },
+    success: (data) => {
+      const packageInstallation = new window.WCF.ACP.Package.Installation(
+        data.returnValues.queueID,
+        "DevtoolsInstallPackage",
+        data.returnValues.isApplication,
+        false,
+        { projectID: _projectId },
+      );
+
+      packageInstallation.prepareInstallation();
+    },
+  });
+}
+
+/**
+ * Shows the confirmation to start package installation.
+ */
+function showConfirmation(event: Event): void {
+  event.preventDefault();
+
+  UiConfirmation.show({
+    confirm: () => installPackage(),
+    message: Language.get("wcf.acp.devtools.project.installPackage.confirmMessage", {
+      packageIdentifier: _projectName,
+    }),
+    messageIsHtml: true,
+  });
+}
+
+/**
+ * Initializes the confirmation to install a project as a package.
+ */
+export function init(projectId: number, projectName: string): void {
+  _projectId = projectId;
+  _projectName = projectName;
+
+  document.querySelectorAll(".jsDevtoolsInstallPackage").forEach((element: HTMLElement) => {
+    element.addEventListener("click", (ev) => showConfirmation(ev));
+  });
+}