2 * Manages the packages entered in a devtools project required package form field.
4 * @author Matthias Schmidt
5 * @copyright 2001-2021 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Form/Acp/Builder/Field/Devtools/Project/RequiredPackages
8 * @see module:WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/AbstractPackageList
11 define(["require", "exports", "tslib", "./AbstractPackageList", "../../../../../../Core", "../../../../../../Language"], function (require, exports, tslib_1, AbstractPackageList_1, Core, Language) {
13 AbstractPackageList_1 = tslib_1.__importDefault(AbstractPackageList_1);
14 Core = tslib_1.__importStar(Core);
15 Language = tslib_1.__importStar(Language);
16 class RequiredPackages extends AbstractPackageList_1.default {
17 constructor(formFieldId, existingPackages) {
18 super(formFieldId, existingPackages);
19 this.minVersion = document.getElementById(`${this.formFieldId}_minVersion`);
20 if (this.minVersion === null) {
21 throw new Error(`Cannot find minimum version form field for packages field with id '${this.formFieldId}'.`);
23 this.minVersion.addEventListener("keypress", (ev) => this.keyPress(ev));
24 this.file = document.getElementById(`${this.formFieldId}_file`);
25 if (this.file === null) {
26 throw new Error(`Cannot find file form field for required field with id '${this.formFieldId}'.`);
29 createSubmitFields(listElement, index) {
30 super.createSubmitFields(listElement, index);
31 ["minVersion", "file"].forEach((property) => {
32 const element = document.createElement("input");
33 element.type = "hidden";
34 element.name = `${this.formFieldId}[${index}][${property}]`;
35 element.value = listElement.dataset[property];
36 this.form.appendChild(element);
41 this.minVersion.value = "";
42 this.file.checked = false;
45 return Core.extend(super.getInputData(), {
46 file: this.file.checked,
47 minVersion: this.minVersion.value,
50 populateListItem(listItem, packageData) {
51 super.populateListItem(listItem, packageData);
52 listItem.dataset.minVersion = packageData.minVersion;
53 listItem.dataset.file = packageData.file ? "1" : "0";
54 listItem.innerHTML = ` ${Language.get("wcf.acp.devtools.project.requiredPackage.requiredPackage", {
55 file: packageData.file,
56 minVersion: packageData.minVersion,
57 packageIdentifier: packageData.packageIdentifier,
61 return super.validateInput() && this.validateVersion(this.minVersion);
64 Core.enableLegacyInheritance(RequiredPackages);
65 return RequiredPackages;