From 1e4c1ccadfa5b15409eeb73219ba6dd5ab867a6c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 29 Nov 2020 19:57:59 +0100 Subject: [PATCH] Convert `Acp/Ui/Option/RewriteGenerator` to TypeScript --- .../Core/Acp/Ui/Option/RewriteGenerator.js | 99 ++++++++++--------- .../Core/Acp/Ui/Option/RewriteGenerator.js | 86 ---------------- .../Core/Acp/Ui/Option/RewriteGenerator.ts | 93 +++++++++++++++++ 3 files changed, 145 insertions(+), 133 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js index 1ce38a5994..c813833a5c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js @@ -1,74 +1,79 @@ /** * Automatic URL rewrite rule generation. * - * @author Florian Gail - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Acp/Ui/Option/RewriteTest + * @author Florian Gail + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator */ -define(['Ajax', 'Language', 'Ui/Dialog'], function (Ajax, Language, UiDialog) { +define(["require", "exports", "tslib", "../../../Ajax", "../../../Language", "../../../Ui/Dialog"], function (require, exports, tslib_1, Ajax, Language, Dialog_1) { "use strict"; - var _buttonGenerate = null; - var _container = null; - /** - * @exports WoltLabSuite/Core/Acp/Ui/Option/RewriteTest - */ - return { + Object.defineProperty(exports, "__esModule", { value: true }); + exports.init = void 0; + Ajax = tslib_1.__importStar(Ajax); + Language = tslib_1.__importStar(Language); + Dialog_1 = tslib_1.__importDefault(Dialog_1); + class RewriteGenerator { /** * Initializes the generator for rewrite rules */ - init: function () { - var urlOmitIndexPhp = elById('url_omit_index_php'); + constructor() { + const urlOmitIndexPhp = document.getElementById("url_omit_index_php"); // This configuration part is unavailable when running in enterprise mode. if (urlOmitIndexPhp === null) { return; } - _container = elCreate('dl'); - var dt = elCreate('dt'); - dt.classList.add('jsOnly'); - var dd = elCreate('dd'); - _buttonGenerate = elCreate('a'); - _buttonGenerate.className = 'button'; - _buttonGenerate.href = '#'; - _buttonGenerate.textContent = Language.get('wcf.acp.rewrite.generate'); - _buttonGenerate.addEventListener('click', this._onClick.bind(this)); - dd.appendChild(_buttonGenerate); - var description = elCreate('small'); - description.textContent = Language.get('wcf.acp.rewrite.description'); + this.container = document.createElement("dl"); + const dt = document.createElement("dt"); + dt.classList.add("jsOnly"); + const dd = document.createElement("dd"); + this.buttonGenerate = document.createElement("a"); + this.buttonGenerate.className = "button"; + this.buttonGenerate.href = "#"; + this.buttonGenerate.textContent = Language.get("wcf.acp.rewrite.generate"); + this.buttonGenerate.addEventListener("click", (ev) => this._onClick(ev)); + dd.appendChild(this.buttonGenerate); + const description = document.createElement("small"); + description.textContent = Language.get("wcf.acp.rewrite.description"); dd.appendChild(description); - _container.appendChild(dt); - _container.appendChild(dd); - var insertAfter = urlOmitIndexPhp.closest('dl'); - insertAfter.parentNode.insertBefore(_container, insertAfter.nextSibling); - }, + this.container.appendChild(dt); + this.container.appendChild(dd); + const insertAfter = urlOmitIndexPhp.closest("dl"); + insertAfter.insertAdjacentElement("afterend", this.container); + } /** * Fires an AJAX request and opens the dialog - * - * @param {Event} event */ - _onClick: function (event) { + _onClick(event) { event.preventDefault(); Ajax.api(this); - }, - _dialogSetup: function () { + } + _dialogSetup() { return { - id: 'dialogRewriteRules', + id: "dialogRewriteRules", source: null, options: { - title: Language.get('wcf.acp.rewrite') - } + title: Language.get("wcf.acp.rewrite"), + }, }; - }, - _ajaxSetup: function () { + } + _ajaxSetup() { return { data: { - actionName: 'generateRewriteRules', - className: 'wcf\\data\\option\\OptionAction' - } + actionName: "generateRewriteRules", + className: "wcf\\data\\option\\OptionAction", + }, }; - }, - _ajaxSuccess: function (data) { - UiDialog.open(this, data.returnValues); } - }; + _ajaxSuccess(data) { + Dialog_1.default.open(this, data.returnValues); + } + } + let rewriteGenerator; + function init() { + if (!rewriteGenerator) { + rewriteGenerator = new RewriteGenerator(); + } + } + exports.init = init; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js deleted file mode 100644 index e04166051d..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Automatic URL rewrite rule generation. - * - * @author Florian Gail - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Acp/Ui/Option/RewriteTest - */ -define(['Ajax', 'Language', 'Ui/Dialog'], function (Ajax, Language, UiDialog) { - "use strict"; - - var _buttonGenerate = null; - var _container = null; - - /** - * @exports WoltLabSuite/Core/Acp/Ui/Option/RewriteTest - */ - return { - /** - * Initializes the generator for rewrite rules - */ - init: function () { - var urlOmitIndexPhp = elById('url_omit_index_php'); - - // This configuration part is unavailable when running in enterprise mode. - if (urlOmitIndexPhp === null) { - return; - } - - _container = elCreate('dl'); - var dt = elCreate('dt'); - dt.classList.add('jsOnly'); - var dd = elCreate('dd'); - - _buttonGenerate = elCreate('a'); - _buttonGenerate.className = 'button'; - _buttonGenerate.href = '#'; - _buttonGenerate.textContent = Language.get('wcf.acp.rewrite.generate'); - _buttonGenerate.addEventListener('click', this._onClick.bind(this)); - dd.appendChild(_buttonGenerate); - var description = elCreate('small'); - description.textContent = Language.get('wcf.acp.rewrite.description'); - dd.appendChild(description); - - _container.appendChild(dt); - _container.appendChild(dd); - - var insertAfter = urlOmitIndexPhp.closest('dl'); - insertAfter.parentNode.insertBefore(_container, insertAfter.nextSibling); - }, - - /** - * Fires an AJAX request and opens the dialog - * - * @param {Event} event - */ - _onClick: function (event) { - event.preventDefault(); - - Ajax.api(this); - }, - - _dialogSetup: function () { - return { - id: 'dialogRewriteRules', - source: null, - options: { - title: Language.get('wcf.acp.rewrite') - } - }; - }, - - _ajaxSetup: function () { - return { - data: { - actionName: 'generateRewriteRules', - className: 'wcf\\data\\option\\OptionAction' - } - }; - }, - - _ajaxSuccess: function (data) { - UiDialog.open(this, data.returnValues); - } - }; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.ts new file mode 100644 index 0000000000..7e28c0ebe2 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator.ts @@ -0,0 +1,93 @@ +/** + * Automatic URL rewrite rule generation. + * + * @author Florian Gail + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/Option/RewriteGenerator + */ + +import * as Ajax from "../../../Ajax"; +import { AjaxCallbackObject, AjaxCallbackSetup, ResponseData } from "../../../Ajax/Data"; +import { DialogCallbackObject, DialogCallbackSetup } from "../../../Ui/Dialog/Data"; +import * as Language from "../../../Language"; +import UiDialog from "../../../Ui/Dialog"; + +class RewriteGenerator implements AjaxCallbackObject, DialogCallbackObject { + private readonly buttonGenerate: HTMLAnchorElement; + private readonly container: HTMLDListElement; + + /** + * Initializes the generator for rewrite rules + */ + constructor() { + const urlOmitIndexPhp = document.getElementById("url_omit_index_php"); + + // This configuration part is unavailable when running in enterprise mode. + if (urlOmitIndexPhp === null) { + return; + } + + this.container = document.createElement("dl"); + const dt = document.createElement("dt"); + dt.classList.add("jsOnly"); + const dd = document.createElement("dd"); + + this.buttonGenerate = document.createElement("a"); + this.buttonGenerate.className = "button"; + this.buttonGenerate.href = "#"; + this.buttonGenerate.textContent = Language.get("wcf.acp.rewrite.generate"); + this.buttonGenerate.addEventListener("click", (ev) => this._onClick(ev)); + dd.appendChild(this.buttonGenerate); + + const description = document.createElement("small"); + description.textContent = Language.get("wcf.acp.rewrite.description"); + dd.appendChild(description); + + this.container.appendChild(dt); + this.container.appendChild(dd); + + const insertAfter = urlOmitIndexPhp.closest("dl")!; + insertAfter.insertAdjacentElement("afterend", this.container); + } + + /** + * Fires an AJAX request and opens the dialog + */ + _onClick(event: MouseEvent): void { + event.preventDefault(); + + Ajax.api(this); + } + + _dialogSetup(): ReturnType { + return { + id: "dialogRewriteRules", + source: null, + options: { + title: Language.get("wcf.acp.rewrite"), + }, + }; + } + + _ajaxSetup(): ReturnType { + return { + data: { + actionName: "generateRewriteRules", + className: "wcf\\data\\option\\OptionAction", + }, + }; + } + + _ajaxSuccess(data: ResponseData): void { + UiDialog.open(this, data.returnValues); + } +} + +let rewriteGenerator: RewriteGenerator; + +export function init(): void { + if (!rewriteGenerator) { + rewriteGenerator = new RewriteGenerator(); + } +} -- 2.20.1