From: Matthias Schmidt Date: Tue, 12 Jan 2021 09:57:26 +0000 (+0100) Subject: Convert `Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~450^2~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=47f19bc7801da8127c0d21595ef8c698bfb6d924;p=GitHub%2FWoltLab%2FWCF.git Convert `Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.js index a0f56080c0..4e2e95bce7 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.js @@ -1,89 +1,56 @@ /** * Manages the packages entered in a devtools project excluded package form field. * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages - * @see module:WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/AbstractPackageList - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages + * @see module:WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/AbstractPackageList + * @since 5.2 */ -define(['./AbstractPackageList', 'Core', 'Language'], function (AbstractPackageList, Core, Language) { +define(["require", "exports", "tslib", "./AbstractPackageList", "../../../../../../Core", "../../../../../../Language"], function (require, exports, tslib_1, AbstractPackageList_1, Core, Language) { "use strict"; - /** - * @constructor - */ - function ExcludedPackages(formFieldId, existingPackages) { - this.init(formFieldId, existingPackages); - } - ; - Core.inherit(ExcludedPackages, AbstractPackageList, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#init - */ - init: function (formFieldId, existingPackages) { - ExcludedPackages._super.prototype.init.call(this, formFieldId, existingPackages); - this._version = elById(this._formFieldId + '_version'); - if (this._version === null) { - throw new Error("Cannot find version form field for packages field with id '" + this._formFieldId + "'."); + AbstractPackageList_1 = tslib_1.__importDefault(AbstractPackageList_1); + Core = tslib_1.__importStar(Core); + Language = tslib_1.__importStar(Language); + class ExcludedPackages extends AbstractPackageList_1.default { + constructor(formFieldId, existingPackages) { + super(formFieldId, existingPackages); + this.version = document.getElementById(`${this.formFieldId}_version`); + if (this.version === null) { + throw new Error(`Cannot find version form field for packages field with id '${this.formFieldId}'.`); } - this._version.addEventListener('keypress', this._keyPress.bind(this)); - }, - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_createSubmitFields - */ - _createSubmitFields: function (listElement, index) { - ExcludedPackages._super.prototype._createSubmitFields.call(this, listElement, index); - var version = elCreate('input'); - elAttr(version, 'type', 'hidden'); - elAttr(version, 'name', this._formFieldId + '[' + index + '][version]'); - version.value = elData(listElement, 'version'); - this._form.appendChild(version); - }, - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_emptyInput - */ - _emptyInput: function () { - ExcludedPackages._super.prototype._emptyInput.call(this); - this._version.value = ''; - }, - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_getInputData - */ - _getInputData: function () { - return Core.extend(ExcludedPackages._super.prototype._getInputData.call(this), { - version: this._version.value + this.version.addEventListener("keypress", (ev) => this.keyPress(ev)); + } + createSubmitFields(listElement, index) { + super.createSubmitFields(listElement, index); + const version = document.createElement("input"); + version.type = "hidden"; + version.name = `${this.formFieldId}[${index}][version]`; + version.value = listElement.dataset.version; + this.form.appendChild(version); + } + emptyInput() { + super.emptyInput(); + this.version.value = ""; + } + getInputData() { + return Core.extend(super.getInputData(), { + version: this.version.value, }); - }, - /** - * Returns the error element for the version form field. - * If `createIfNonExistent` is not given or `false`, `null` is returned - * if there is no error element, otherwise an empty error element - * is created and returned. - * - * @param {?boolean} createIfNonExistent - * @return {?HTMLElement} - */ - _getVersionErrorElement: function (createIfNonExistent) { - return this._getErrorElement(this._version, createIfNonExistent); - }, - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_populateListItem - */ - _populateListItem: function (listItem, packageData) { - ExcludedPackages._super.prototype._populateListItem.call(this, listItem, packageData); - elData(listItem, 'version', packageData.version); - listItem.innerHTML = ' ' + Language.get('wcf.acp.devtools.project.excludedPackage.excludedPackage', { + } + populateListItem(listItem, packageData) { + super.populateListItem(listItem, packageData); + listItem.dataset.version = packageData.version; + listItem.innerHTML = ` ${Language.get("wcf.acp.devtools.project.excludedPackage.excludedPackage", { packageIdentifier: packageData.packageIdentifier, - version: packageData.version - }); - }, - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_validateInput - */ - _validateInput: function () { - return ExcludedPackages._super.prototype._validateInput.call(this) && this._validateVersion(this._version.value, this._getVersionErrorElement.bind(this)); + version: packageData.version, + })}`; } - }); + validateInput() { + return super.validateInput() && this.validateVersion(this.version); + } + } + Core.enableLegacyInheritance(ExcludedPackages); return ExcludedPackages; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.js deleted file mode 100644 index cd03ed34be..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.js +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Manages the packages entered in a devtools project excluded package form field. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages - * @see module:WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/AbstractPackageList - * @since 5.2 - */ -define(['./AbstractPackageList', 'Core', 'Language'], function(AbstractPackageList, Core, Language) { - "use strict"; - - /** - * @constructor - */ - function ExcludedPackages(formFieldId, existingPackages) { - this.init(formFieldId, existingPackages); - }; - Core.inherit(ExcludedPackages, AbstractPackageList, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#init - */ - init: function(formFieldId, existingPackages) { - ExcludedPackages._super.prototype.init.call(this, formFieldId, existingPackages); - - this._version = elById(this._formFieldId + '_version'); - if (this._version === null) { - throw new Error("Cannot find version form field for packages field with id '" + this._formFieldId + "'."); - } - this._version.addEventListener('keypress', this._keyPress.bind(this)); - }, - - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_createSubmitFields - */ - _createSubmitFields: function(listElement, index) { - ExcludedPackages._super.prototype._createSubmitFields.call(this, listElement, index); - - var version = elCreate('input'); - elAttr(version, 'type', 'hidden'); - elAttr(version, 'name', this._formFieldId + '[' + index + '][version]') - version.value = elData(listElement, 'version'); - this._form.appendChild(version); - }, - - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_emptyInput - */ - _emptyInput: function() { - ExcludedPackages._super.prototype._emptyInput.call(this); - - this._version.value = ''; - }, - - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_getInputData - */ - _getInputData: function() { - return Core.extend(ExcludedPackages._super.prototype._getInputData.call(this), { - version: this._version.value - }); - }, - - /** - * Returns the error element for the version form field. - * If `createIfNonExistent` is not given or `false`, `null` is returned - * if there is no error element, otherwise an empty error element - * is created and returned. - * - * @param {?boolean} createIfNonExistent - * @return {?HTMLElement} - */ - _getVersionErrorElement: function(createIfNonExistent) { - return this._getErrorElement(this._version, createIfNonExistent); - }, - - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_populateListItem - */ - _populateListItem: function(listItem, packageData) { - ExcludedPackages._super.prototype._populateListItem.call(this, listItem, packageData); - - elData(listItem, 'version', packageData.version); - listItem.innerHTML = ' ' + Language.get('wcf.acp.devtools.project.excludedPackage.excludedPackage', { - packageIdentifier: packageData.packageIdentifier, - version: packageData.version - }); - }, - - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_validateInput - */ - _validateInput: function() { - return ExcludedPackages._super.prototype._validateInput.call(this) && this._validateVersion( - this._version.value, - this._getVersionErrorElement.bind(this) - ); - } - }); - - return ExcludedPackages; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.ts new file mode 100644 index 0000000000..503a259210 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages.ts @@ -0,0 +1,72 @@ +/** + * Manages the packages entered in a devtools project excluded package form field. + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/ExcludedPackages + * @see module:WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/AbstractPackageList + * @since 5.2 + */ + +import AbstractPackageList from "./AbstractPackageList"; +import * as Core from "../../../../../../Core"; +import * as Language from "../../../../../../Language"; +import { ExcludedPackageData } from "./Data"; + +class ExcludedPackages< + TPackageData extends ExcludedPackageData = ExcludedPackageData +> extends AbstractPackageList { + protected readonly version: HTMLInputElement; + + constructor(formFieldId: string, existingPackages: TPackageData[]) { + super(formFieldId, existingPackages); + + this.version = document.getElementById(`${this.formFieldId}_version`) as HTMLInputElement; + if (this.version === null) { + throw new Error(`Cannot find version form field for packages field with id '${this.formFieldId}'.`); + } + this.version.addEventListener("keypress", (ev) => this.keyPress(ev)); + } + + protected createSubmitFields(listElement: HTMLLIElement, index: number): void { + super.createSubmitFields(listElement, index); + + const version = document.createElement("input"); + version.type = "hidden"; + version.name = `${this.formFieldId}[${index}][version]`; + version.value = listElement.dataset.version!; + this.form.appendChild(version); + } + + protected emptyInput(): void { + super.emptyInput(); + + this.version.value = ""; + } + + protected getInputData(): TPackageData { + return Core.extend(super.getInputData(), { + version: this.version.value, + }) as TPackageData; + } + + protected populateListItem(listItem: HTMLLIElement, packageData: TPackageData): void { + super.populateListItem(listItem, packageData); + + listItem.dataset.version = packageData.version; + + listItem.innerHTML = ` ${Language.get("wcf.acp.devtools.project.excludedPackage.excludedPackage", { + packageIdentifier: packageData.packageIdentifier, + version: packageData.version, + })}`; + } + + protected validateInput(): boolean { + return super.validateInput() && this.validateVersion(this.version); + } +} + +Core.enableLegacyInheritance(ExcludedPackages); + +export = ExcludedPackages;