From: Matthias Schmidt Date: Wed, 9 Dec 2020 16:34:41 +0000 (+0100) Subject: Convert `Form/Builder/Field/SimpleAcl` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~526^2~27 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=aac82cc2b7b7ca8cd596fb8c7ba8f82b868d3b7e;p=GitHub%2FWoltLab%2FWCF.git Convert `Form/Builder/Field/SimpleAcl` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js index 731c508b5e..7932459c87 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js @@ -1,47 +1,22 @@ -/** - * Data handler for a simple acl form builder field in an Ajax form. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/SimpleAcl - * @since 5.2 - */ -define(['Core', './Field'], function (Core, FormBuilderField) { +define(["require", "exports", "tslib", "./Field", "../../../Core"], function (require, exports, tslib_1, Field_1, Core) { "use strict"; - /** - * @constructor - */ - function FormBuilderFieldSimpleAcl(fieldId) { - this.init(fieldId); - } - ; - Core.inherit(FormBuilderFieldSimpleAcl, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function () { - var groupIds = []; - elBySelAll('input[name="' + this._fieldId + '[group][]"]', undefined, function (input) { - groupIds.push(~~input.value); - }); - var usersIds = []; - elBySelAll('input[name="' + this._fieldId + '[user][]"]', undefined, function (input) { - usersIds.push(~~input.value); - }); - var data = {}; - data[this._fieldId] = { - group: groupIds, - user: usersIds + Field_1 = tslib_1.__importDefault(Field_1); + Core = tslib_1.__importStar(Core); + class SimpleAcl extends Field_1.default { + _getData() { + const groupIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[group][]"]')).map((input) => input.value); + const usersIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[user][]"]')).map((input) => input.value); + return { + [this._fieldId]: { + group: groupIds, + user: usersIds, + }, }; - return data; - }, - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_readField - */ - _readField: function () { + } + _readField() { // does nothing } - }); - return FormBuilderFieldSimpleAcl; + } + Core.enableLegacyInheritance(SimpleAcl); + return SimpleAcl; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js deleted file mode 100644 index 2da8625915..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Data handler for a simple acl form builder field in an Ajax form. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/SimpleAcl - * @since 5.2 - */ -define(['Core', './Field'], function(Core, FormBuilderField) { - "use strict"; - - /** - * @constructor - */ - function FormBuilderFieldSimpleAcl(fieldId) { - this.init(fieldId); - }; - Core.inherit(FormBuilderFieldSimpleAcl, FormBuilderField, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData - */ - _getData: function() { - var groupIds = []; - elBySelAll('input[name="' + this._fieldId + '[group][]"]', undefined, function(input) { - groupIds.push(~~input.value); - }); - - var usersIds = []; - elBySelAll('input[name="' + this._fieldId + '[user][]"]', undefined, function(input) { - usersIds.push(~~input.value); - }); - - var data = {}; - - data[this._fieldId] = { - group: groupIds, - user: usersIds - }; - - return data; - }, - - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Field#_readField - */ - _readField: function() { - // does nothing - } - }); - - return FormBuilderFieldSimpleAcl; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.ts new file mode 100644 index 0000000000..0eb2226c56 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/SimpleAcl.ts @@ -0,0 +1,30 @@ +import Field from "./Field"; +import { FormBuilderData } from "../Data"; +import * as Core from "../../../Core"; + +class SimpleAcl extends Field { + protected _getData(): FormBuilderData { + const groupIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[group][]"]')).map( + (input: HTMLInputElement) => input.value, + ); + + const usersIds = Array.from(document.querySelectorAll('input[name="' + this._fieldId + '[user][]"]')).map( + (input: HTMLInputElement) => input.value, + ); + + return { + [this._fieldId]: { + group: groupIds, + user: usersIds, + }, + }; + } + + protected _readField(): void { + // does nothing + } +} + +Core.enableLegacyInheritance(SimpleAcl); + +export = SimpleAcl;