From: Matthias Schmidt Date: Sat, 12 Dec 2020 15:06:48 +0000 (+0100) Subject: Convert `Form/Builder/Field/Dependency/Empty` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~526^2~10 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5e5c2b72cc6b654d968e98470f148208355918ba;p=GitHub%2FWoltLab%2FWCF.git Convert `Form/Builder/Field/Dependency/Empty` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js index bc8c77073b..2736d2e8cd 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js @@ -1,59 +1,51 @@ /** * Form field dependency implementation that requires the value of a field to be empty. * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty - * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty + * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract + * @since 5.2 */ -define(['./Abstract', 'Core'], function (Abstract, Core) { +define(["require", "exports", "tslib", "./Abstract", "../../../../Core"], function (require, exports, tslib_1, Abstract_1, Core) { "use strict"; - /** - * @constructor - */ - function Empty(dependentElementId, fieldId) { - this.init(dependentElementId, fieldId); - } - ; - Core.inherit(Empty, Abstract, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract#checkDependency - */ - checkDependency: function () { + Abstract_1 = tslib_1.__importDefault(Abstract_1); + Core = tslib_1.__importStar(Core); + class Empty extends Abstract_1.default { + checkDependency() { if (this._field !== null) { switch (this._field.tagName) { - case 'INPUT': - switch (this._field.type) { - case 'checkbox': - return !this._field.checked; - case 'radio': + case "INPUT": { + const field = this._field; + switch (field.type) { + case "checkbox": + return !field.checked; + case "radio": if (this._noField && this._noField.checked) { return true; } - return !this._field.checked; + return !field.checked; default: - return this._field.value.trim().length === 0; + return field.value.trim().length === 0; } - case 'SELECT': - if (this._field.multiple) { - return elBySelAll('option:checked', this._field).length === 0; + } + case "SELECT": { + const field = this._field; + if (field.multiple) { + return this._field.querySelectorAll("option:checked").length === 0; } - return this._field.value == 0 || this._field.value.length === 0; - case 'TEXTAREA': + return field.value == "0" || field.value.length === 0; + } + case "TEXTAREA": { return this._field.value.trim().length === 0; - } - } - else { - for (var i = 0, length = this._fields.length; i < length; i++) { - if (this._fields[i].checked) { - return false; } } - return true; } + // Check that none of the fields are checked. + return this._fields.every((field) => !field.checked); } - }); + } + Core.enableLegacyInheritance(Empty); return Empty; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js deleted file mode 100644 index 2be7614271..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Form field dependency implementation that requires the value of a field to be empty. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty - * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract - * @since 5.2 - */ -define(['./Abstract', 'Core'], function(Abstract, Core) { - "use strict"; - - /** - * @constructor - */ - function Empty(dependentElementId, fieldId) { - this.init(dependentElementId, fieldId); - }; - Core.inherit(Empty, Abstract, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract#checkDependency - */ - checkDependency: function() { - if (this._field !== null) { - switch (this._field.tagName) { - case 'INPUT': - switch (this._field.type) { - case 'checkbox': - return !this._field.checked; - - case 'radio': - if (this._noField && this._noField.checked) { - return true; - } - - return !this._field.checked; - - default: - return this._field.value.trim().length === 0; - } - - case 'SELECT': - if (this._field.multiple) { - return elBySelAll('option:checked', this._field).length === 0; - } - - return this._field.value == 0 || this._field.value.length === 0; - - case 'TEXTAREA': - return this._field.value.trim().length === 0; - } - } - else { - for (var i = 0, length = this._fields.length; i < length; i++) { - if (this._fields[i].checked) { - return false; - } - } - - return true; - } - } - }); - - return Empty; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.ts new file mode 100644 index 0000000000..04c9171265 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.ts @@ -0,0 +1,59 @@ +/** + * Form field dependency implementation that requires the value of a field to be empty. + * + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty + * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract + * @since 5.2 + */ + +import Abstract from "./Abstract"; +import * as Core from "../../../../Core"; + +class Empty extends Abstract { + public checkDependency(): boolean { + if (this._field !== null) { + switch (this._field.tagName) { + case "INPUT": { + const field = this._field as HTMLInputElement; + switch (field.type) { + case "checkbox": + return !field.checked; + + case "radio": + if (this._noField && this._noField.checked) { + return true; + } + + return !field.checked; + + default: + return field.value.trim().length === 0; + } + } + + case "SELECT": { + const field = this._field as HTMLSelectElement; + if (field.multiple) { + return this._field.querySelectorAll("option:checked").length === 0; + } + + return field.value == "0" || field.value.length === 0; + } + + case "TEXTAREA": { + return (this._field as HTMLTextAreaElement).value.trim().length === 0; + } + } + } + + // Check that none of the fields are checked. + return this._fields.every((field: HTMLInputElement) => !field.checked); + } +} + +Core.enableLegacyInheritance(Empty); + +export = Empty;