/**
* 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 <http://opensource.org/licenses/lgpl-license.php>
- * @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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
});
+++ /dev/null
-/**
- * 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 <http://opensource.org/licenses/lgpl-license.php>
- * @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;
-});
--- /dev/null
+/**
+ * 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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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<TPackageData> {
+ 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;