import { formatFilesize } from "WoltLabSuite/Core/FileUtil";
import DomChangeListener from "WoltLabSuite/Core/Dom/Change/Listener";
+const _data = new Map<string, FileProcessor>();
+
export interface ExtraButton {
title: string;
icon?: string;
this.#container.querySelectorAll<WoltlabCoreFileElement>("woltlab-core-file").forEach((element) => {
this.#registerFile(element, element.parentElement);
});
+
+ _data.set(fieldId, this);
}
get classPrefix(): string {
this.addButtons(container, element);
}
+
+ get values(): Set<number> {
+ return new Set(
+ Array.from(this.#container.querySelectorAll<HTMLInputElement>('input[type="hidden"]')).map((input) =>
+ parseInt(input.value, 10),
+ ),
+ );
+ }
+}
+
+export function getValues(fieldId: string): Set<number> {
+ const field = _data.get(fieldId);
+ if (field === undefined) {
+ throw new Error("Unknown field with id '" + fieldId + "'");
+ }
+
+ return field.values;
}
--- /dev/null
+/**
+ * Data handler for a file processor form builder field in an Ajax form.
+ *
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+
+import Field from "WoltLabSuite/Core/Form/Builder/Field/Field";
+import { FormBuilderData } from "WoltLabSuite/Core/Form/Builder/Data";
+import { getValues } from "WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor";
+
+export default class FileProcessor extends Field {
+ protected _getData(): FormBuilderData {
+ return {
+ [this._fieldId]: getValues(this._fieldId),
+ };
+ }
+
+ protected _readField(): void {
+ // does nothing
+ }
+}
define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/FileUtil", "WoltLabSuite/Core/Dom/Change/Listener"], function (require, exports, tslib_1, Language_1, DeleteFile_1, FileUtil_1, Listener_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
- exports.FileProcessor = void 0;
+ exports.getValues = exports.FileProcessor = void 0;
Listener_1 = tslib_1.__importDefault(Listener_1);
+ const _data = new Map();
class FileProcessor {
#container;
#uploadButton;
this.#container.querySelectorAll("woltlab-core-file").forEach((element) => {
this.#registerFile(element, element.parentElement);
});
+ _data.set(fieldId, this);
}
get classPrefix() {
return this.showBigPreview ? "fileUpload__preview__" : "fileList__";
container.append(input);
this.addButtons(container, element);
}
+ get values() {
+ return new Set(Array.from(this.#container.querySelectorAll('input[type="hidden"]')).map((input) => parseInt(input.value, 10)));
+ }
}
exports.FileProcessor = FileProcessor;
+ function getValues(fieldId) {
+ const field = _data.get(fieldId);
+ if (field === undefined) {
+ throw new Error("Unknown field with id '" + fieldId + "'");
+ }
+ return field.values;
+ }
+ exports.getValues = getValues;
});
--- /dev/null
+/**
+ * Data handler for a file processor form builder field in an Ajax form.
+ *
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Form/Builder/Field/Field", "WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor"], function (require, exports, tslib_1, Field_1, FileProcessor_1) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ Field_1 = tslib_1.__importDefault(Field_1);
+ class FileProcessor extends Field_1.default {
+ _getData() {
+ return {
+ [this._fieldId]: (0, FileProcessor_1.getValues)(this._fieldId),
+ };
+ }
+ _readField() {
+ // does nothing
+ }
+ }
+ exports.default = FileProcessor;
+});
*/
protected $templateName = 'shared_fileProcessorFormField';
+ /**
+ * @inheritDoc
+ */
+ protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/FileProcessor';
+
private array $context = [];
/**