From 647460596f93725fd7291a59669f2d879180577c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 4 Dec 2020 20:32:19 +0100 Subject: [PATCH] Convert `Acp/Ui/Template/Group/Copy` to TypeScript --- .../Core/Acp/Ui/Template/Group/Copy.js | 163 +++++++++--------- .../Core/Acp/Ui/Template/Group/Copy.js | 113 ------------ .../Core/Acp/Ui/Template/Group/Copy.ts | 142 +++++++++++++++ 3 files changed, 228 insertions(+), 190 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js index c0ade40425..e30e0d7097 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js @@ -1,103 +1,112 @@ /** * Provides a dialog to copy an existing template group. * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Acp/Ui/Template/Group/Copy + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/Template/Group/Copy */ -define(['Ajax', 'Language', 'Ui/Dialog', 'Ui/Notification'], function (Ajax, Language, UiDialog, UiNotification) { +define(["require", "exports", "tslib", "../../../../Ajax", "../../../../Language", "../../../../Ui/Dialog", "../../../../Ui/Notification", "../../../../Dom/Util"], function (require, exports, tslib_1, Ajax, Language, Dialog_1, UiNotification, Util_1) { "use strict"; - var _name = null; - var _folderName = null; - var _templateGroupId = 0; - /** - * @exports WoltLabSuite/Core/Acp/Ui/Template/Group/Copy - */ - return { - /** - * Initializes the dialog handler. - * - * @param {int} templateGroupId - */ - init: function (templateGroupId) { - _templateGroupId = templateGroupId; - elBySel('.jsButtonCopy').addEventListener('click', this._click.bind(this)); - }, - /** - * Handles clicks on the 'Copy Template Group' button. - * - * @param {Event} event - * @protected - */ - _click: function (event) { + 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); + UiNotification = tslib_1.__importStar(UiNotification); + Util_1 = tslib_1.__importDefault(Util_1); + class AcpUiTemplateGroupCopy { + constructor(templateGroupId) { + this.folderName = undefined; + this.name = undefined; + this.templateGroupId = templateGroupId; + const button = document.querySelector(".jsButtonCopy"); + button.addEventListener("click", (ev) => this.click(ev)); + } + click(event) { event.preventDefault(); - UiDialog.open(this); - }, - _dialogSubmit: function () { + Dialog_1.default.open(this); + } + _dialogSubmit() { Ajax.api(this, { parameters: { - templateGroupName: _name.value, - templateGroupFolderName: _folderName.value - } + templateGroupName: this.name.value, + templateGroupFolderName: this.folderName.value, + }, }); - }, - _ajaxSuccess: function (data) { - UiDialog.close(this); - UiNotification.show(undefined, function () { - //noinspection JSUnresolvedVariable - window.location = data.returnValues.redirectURL; + } + _ajaxSuccess(data) { + Dialog_1.default.close(this); + UiNotification.show(undefined, () => { + window.location.href = data.returnValues.redirectURL; }); - }, - _dialogSetup: function () { + } + _dialogSetup() { return { - id: 'templateGroupCopy', + id: "templateGroupCopy", options: { - onSetup: (function () { - ['Name', 'FolderName'].forEach((function (type) { - var input = elById('copyTemplateGroup' + type); - input.value = elById('templateGroup' + type).value; - if (type === 'Name') - _name = input; - else - _folderName = input; - }).bind(this)); - }).bind(this), - title: Language.get('wcf.acp.template.group.copy') + onSetup: () => { + ["Name", "FolderName"].forEach((type) => { + const input = document.getElementById("copyTemplateGroup" + type); + input.value = document.getElementById("templateGroup" + type).value; + if (type === "Name") { + this.name = input; + } + else { + this.folderName = input; + } + }); + }, + title: Language.get("wcf.acp.template.group.copy"), }, - source: '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '' + - '
' + source: `
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+ +
`, }; - }, - _ajaxSetup: function () { + } + _ajaxSetup() { return { data: { - actionName: 'copy', - className: 'wcf\\data\\template\\group\\TemplateGroupAction', - objectIDs: [_templateGroupId] + actionName: "copy", + className: "wcf\\data\\template\\group\\TemplateGroupAction", + objectIDs: [this.templateGroupId], }, - /** @var {{returnValues:{fieldName: string, errorType: string}}} data */ - failure: function (data) { + failure: (data) => { if (data && data.returnValues && data.returnValues.fieldName && data.returnValues.errorType) { - if (data.returnValues.fieldName === 'templateGroupName') { - elInnerError(_name, Language.get('wcf.acp.template.group.name.error.' + data.returnValues.errorType)); + if (data.returnValues.fieldName === "templateGroupName") { + Util_1.default.innerError(this.name, Language.get(`wcf.acp.template.group.name.error.${data.returnValues.errorType}`)); } else { - elInnerError(_folderName, Language.get('wcf.acp.template.group.folderName.error.' + data.returnValues.errorType)); + Util_1.default.innerError(this.folderName, Language.get(`wcf.acp.template.group.folderName.error.${data.returnValues.errorType}`)); } return false; } - } + return true; + }, }; } - }; + } + let acpUiTemplateGroupCopy; + function init(templateGroupId) { + if (!acpUiTemplateGroupCopy) { + acpUiTemplateGroupCopy = new AcpUiTemplateGroupCopy(templateGroupId); + } + } + exports.init = init; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js deleted file mode 100644 index ef71c7e999..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.js +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Provides a dialog to copy an existing template group. - * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Acp/Ui/Template/Group/Copy - */ -define(['Ajax', 'Language', 'Ui/Dialog', 'Ui/Notification'], function(Ajax, Language, UiDialog, UiNotification) { - "use strict"; - - var _name = null; - var _folderName = null; - var _templateGroupId = 0; - - /** - * @exports WoltLabSuite/Core/Acp/Ui/Template/Group/Copy - */ - return { - /** - * Initializes the dialog handler. - * - * @param {int} templateGroupId - */ - init: function (templateGroupId) { - _templateGroupId = templateGroupId; - - elBySel('.jsButtonCopy').addEventListener('click', this._click.bind(this)); - }, - - /** - * Handles clicks on the 'Copy Template Group' button. - * - * @param {Event} event - * @protected - */ - _click: function (event) { - event.preventDefault(); - - UiDialog.open(this); - }, - - _dialogSubmit: function () { - Ajax.api(this, { - parameters: { - templateGroupName: _name.value, - templateGroupFolderName: _folderName.value - } - }); - }, - - _ajaxSuccess: function (data) { - UiDialog.close(this); - - UiNotification.show(undefined, function () { - //noinspection JSUnresolvedVariable - window.location = data.returnValues.redirectURL; - }); - }, - - _dialogSetup: function () { - return { - id: 'templateGroupCopy', - options: { - onSetup: (function () { - ['Name', 'FolderName'].forEach((function(type) { - var input = elById('copyTemplateGroup' + type); - input.value = elById('templateGroup' + type).value; - - if (type === 'Name') _name = input; - else _folderName = input; - }).bind(this)); - }).bind(this), - title: Language.get('wcf.acp.template.group.copy') - }, - source: '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '' + - '
' - } - }, - - _ajaxSetup: function () { - return { - data: { - actionName: 'copy', - className: 'wcf\\data\\template\\group\\TemplateGroupAction', - objectIDs: [_templateGroupId] - }, - /** @var {{returnValues:{fieldName: string, errorType: string}}} data */ - failure: function (data) { - if (data && data.returnValues && data.returnValues.fieldName && data.returnValues.errorType) { - if (data.returnValues.fieldName === 'templateGroupName') { - elInnerError(_name, Language.get('wcf.acp.template.group.name.error.' + data.returnValues.errorType)); - } - else { - elInnerError(_folderName, Language.get('wcf.acp.template.group.folderName.error.' + data.returnValues.errorType)); - } - - return false; - } - } - } - } - }; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts new file mode 100644 index 0000000000..185928a141 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Template/Group/Copy.ts @@ -0,0 +1,142 @@ +/** + * Provides a dialog to copy an existing template group. + * + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Ui/Template/Group/Copy + */ + +import * as Ajax from "../../../../Ajax"; +import { AjaxCallbackObject, AjaxCallbackSetup } from "../../../../Ajax/Data"; +import { DialogCallbackObject, DialogCallbackSetup } from "../../../../Ui/Dialog/Data"; +import * as Language from "../../../../Language"; +import UiDialog from "../../../../Ui/Dialog"; +import * as UiNotification from "../../../../Ui/Notification"; +import DomUtil from "../../../../Dom/Util"; + +interface AjaxResponse { + returnValues: { + redirectURL: string; + }; +} + +interface AjaxResponseError { + returnValues?: { + fieldName?: string; + errorType?: string; + }; +} + +class AcpUiTemplateGroupCopy implements AjaxCallbackObject, DialogCallbackObject { + private folderName?: HTMLInputElement = undefined; + private name?: HTMLInputElement = undefined; + private readonly templateGroupId: number; + + constructor(templateGroupId: number) { + this.templateGroupId = templateGroupId; + + const button = document.querySelector(".jsButtonCopy") as HTMLAnchorElement; + button.addEventListener("click", (ev) => this.click(ev)); + } + + private click(event: MouseEvent): void { + event.preventDefault(); + + UiDialog.open(this); + } + + _dialogSubmit(): void { + Ajax.api(this, { + parameters: { + templateGroupName: this.name!.value, + templateGroupFolderName: this.folderName!.value, + }, + }); + } + + _ajaxSuccess(data: AjaxResponse): void { + UiDialog.close(this); + + UiNotification.show(undefined, () => { + window.location.href = data.returnValues.redirectURL; + }); + } + + _dialogSetup(): ReturnType { + return { + id: "templateGroupCopy", + options: { + onSetup: () => { + ["Name", "FolderName"].forEach((type) => { + const input = document.getElementById("copyTemplateGroup" + type) as HTMLInputElement; + input.value = (document.getElementById("templateGroup" + type) as HTMLInputElement).value; + + if (type === "Name") { + this.name = input; + } else { + this.folderName = input; + } + }); + }, + title: Language.get("wcf.acp.template.group.copy"), + }, + source: `
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+ +
`, + }; + } + + _ajaxSetup(): ReturnType { + return { + data: { + actionName: "copy", + className: "wcf\\data\\template\\group\\TemplateGroupAction", + objectIDs: [this.templateGroupId], + }, + failure: (data: AjaxResponseError) => { + if (data && data.returnValues && data.returnValues.fieldName && data.returnValues.errorType) { + if (data.returnValues.fieldName === "templateGroupName") { + DomUtil.innerError( + this.name!, + Language.get(`wcf.acp.template.group.name.error.${data.returnValues.errorType}`), + ); + } else { + DomUtil.innerError( + this.folderName!, + Language.get(`wcf.acp.template.group.folderName.error.${data.returnValues.errorType}`), + ); + } + + return false; + } + + return true; + }, + }; + } +} + +let acpUiTemplateGroupCopy: AcpUiTemplateGroupCopy; + +export function init(templateGroupId: number): void { + if (!acpUiTemplateGroupCopy) { + acpUiTemplateGroupCopy = new AcpUiTemplateGroupCopy(templateGroupId); + } +} -- 2.20.1