2 * Manages the packages entered in a devtools project required package form field.
4 * @author Matthias Schmidt
5 * @copyright 2001-2019 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(['./AbstractPackageList', 'Core', 'Language'], function (AbstractPackageList, Core, Language) {
16 function RequiredPackages(formFieldId, existingPackages) {
17 this.init(formFieldId, existingPackages);
20 Core.inherit(RequiredPackages, AbstractPackageList, {
22 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#init
24 init: function (formFieldId, existingPackages) {
25 RequiredPackages._super.prototype.init.call(this, formFieldId, existingPackages);
26 this._minVersion = elById(this._formFieldId + '_minVersion');
27 if (this._minVersion === null) {
28 throw new Error("Cannot find minimum version form field for packages field with id '" + this._formFieldId + "'.");
30 this._minVersion.addEventListener('keypress', this._keyPress.bind(this));
31 this._file = elById(this._formFieldId + '_file');
32 if (this._file === null) {
33 throw new Error("Cannot find file form field for required field with id '" + this._formFieldId + "'.");
37 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_createSubmitFields
39 _createSubmitFields: function (listElement, index) {
40 RequiredPackages._super.prototype._createSubmitFields.call(this, listElement, index);
41 var minVersion = elCreate('input');
42 elAttr(minVersion, 'type', 'hidden');
43 elAttr(minVersion, 'name', this._formFieldId + '[' + index + '][minVersion]');
44 minVersion.value = elData(listElement, 'min-version');
45 this._form.appendChild(minVersion);
46 var file = elCreate('input');
47 elAttr(file, 'type', 'hidden');
48 elAttr(file, 'name', this._formFieldId + '[' + index + '][file]');
49 file.value = elData(listElement, 'file');
50 this._form.appendChild(file);
53 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_emptyInput
55 _emptyInput: function () {
56 RequiredPackages._super.prototype._emptyInput.call(this);
57 this._minVersion.value = '';
58 this._file.checked = false;
61 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_getInputData
63 _getInputData: function () {
64 return Core.extend(RequiredPackages._super.prototype._getInputData.call(this), {
65 file: this._file.checked,
66 minVersion: this._minVersion.value
70 * Returns the error element for the minimum version form field.
71 * If `createIfNonExistent` is not given or `false`, `null` is returned
72 * if there is no error element, otherwise an empty error element
73 * is created and returned.
75 * @param {?boolean} createIfNonExistent
76 * @return {?HTMLElement}
78 _getMinVersionErrorElement: function (createIfNonExistent) {
79 return this._getErrorElement(this._minVersion, createIfNonExistent);
82 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_populateListItem
84 _populateListItem: function (listItem, packageData) {
85 RequiredPackages._super.prototype._populateListItem.call(this, listItem, packageData);
86 elData(listItem, 'min-version', packageData.minVersion);
87 elData(listItem, 'file', ~~packageData.file);
88 listItem.innerHTML = ' ' + Language.get('wcf.acp.devtools.project.requiredPackage.requiredPackage', {
89 file: ~~packageData.file,
90 minVersion: packageData.minVersion,
91 packageIdentifier: packageData.packageIdentifier
95 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_validateInput
97 _validateInput: function () {
98 return RequiredPackages._super.prototype._validateInput.call(this) && this._validateVersion(this._minVersion.value, this._getMinVersionErrorElement.bind(this));
101 return RequiredPackages;