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) {
17 function RequiredPackages(formFieldId, existingPackages) {
18 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);
27 this._minVersion = elById(this._formFieldId + '_minVersion');
28 if (this._minVersion === null) {
29 throw new Error("Cannot find minimum version form field for packages field with id '" + this._formFieldId + "'.");
31 this._minVersion.addEventListener('keypress', this._keyPress.bind(this));
33 this._file = elById(this._formFieldId + '_file');
34 if (this._file === null) {
35 throw new Error("Cannot find file form field for required field with id '" + this._formFieldId + "'.");
40 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_createSubmitFields
42 _createSubmitFields: function(listElement, index) {
43 RequiredPackages._super.prototype._createSubmitFields.call(this, listElement, index);
45 var minVersion = elCreate('input');
46 elAttr(minVersion, 'type', 'hidden');
47 elAttr(minVersion, 'name', this._formFieldId + '[' + index + '][minVersion]')
48 minVersion.value = elData(listElement, 'min-version');
49 this._form.appendChild(minVersion);
51 var file = elCreate('input');
52 elAttr(file, 'type', 'hidden');
53 elAttr(file, 'name', this._formFieldId + '[' + index + '][file]')
54 file.value = elData(listElement, 'file');
55 this._form.appendChild(file);
59 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_emptyInput
61 _emptyInput: function() {
62 RequiredPackages._super.prototype._emptyInput.call(this);
64 this._minVersion.value = '';
65 this._file.checked = false;
69 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_getInputData
71 _getInputData: function() {
72 return Core.extend(RequiredPackages._super.prototype._getInputData.call(this), {
73 file: this._file.checked,
74 minVersion: this._minVersion.value
79 * Returns the error element for the minimum version form field.
80 * If `createIfNonExistent` is not given or `false`, `null` is returned
81 * if there is no error element, otherwise an empty error element
82 * is created and returned.
84 * @param {?boolean} createIfNonExistent
85 * @return {?HTMLElement}
87 _getMinVersionErrorElement: function(createIfNonExistent) {
88 return this._getErrorElement(this._minVersion, createIfNonExistent);
92 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_populateListItem
94 _populateListItem: function(listItem, packageData) {
95 RequiredPackages._super.prototype._populateListItem.call(this, listItem, packageData);
97 elData(listItem, 'min-version', packageData.minVersion);
98 elData(listItem, 'file', ~~packageData.file);
99 listItem.innerHTML = ' ' + Language.get('wcf.acp.devtools.project.requiredPackage.requiredPackage', {
100 file: ~~packageData.file,
101 minVersion: packageData.minVersion,
102 packageIdentifier: packageData.packageIdentifier
107 * @see WoltLabSuite/Core/Form/Builder/Field/Devtools/Project/AbstractPackageList#_validateInput
109 _validateInput: function() {
110 return RequiredPackages._super.prototype._validateInput.call(this) && this._validateVersion(
111 this._minVersion.value,
112 this._getMinVersionErrorElement.bind(this)
117 return RequiredPackages;