{if $field->isBigPreview()}true{else}false{/if},
{if $field->isSimpleReplace()}true{else}false{/if},
{if $field->isHideDeleteButton()}true{else}false{/if},
+ {if $field->getThumbnailSize() === null}undefined{else}'{$field->getThumbnailSize()|encodeJS}'{/if},
[{implode from=$actionButtons item=actionButton}{
title: '{unsafe:$actionButton['title']|encodeJS}',
icon: {if $actionButton['icon'] === null}undefined{else}'{unsafe:$actionButton['icon']->toHtml()|encodeJS}'{/if},
* @since 6.1
*/
-import WoltlabCoreFileElement from "WoltLabSuite/Core/Component/File/woltlab-core-file";
+import WoltlabCoreFileElement, { Thumbnail } from "WoltLabSuite/Core/Component/File/woltlab-core-file";
import { getPhrase } from "WoltLabSuite/Core/Language";
import { deleteFile } from "WoltLabSuite/Core/Api/Files/DeleteFile";
import DomChangeListener from "WoltLabSuite/Core/Dom/Change/Listener";
readonly #singleFileUpload: boolean;
readonly #simpleReplace: boolean;
readonly #hideDeleteButton: boolean;
+ readonly #thumbnailSize?: string;
readonly #extraButtons: ExtraButton[];
#uploadResolve: undefined | (() => void);
useBigPreview: boolean = false,
simpleReplace: boolean = false,
hideDeleteButton: boolean = false,
+ thumbnailSize?: string,
extraButtons: ExtraButton[] = [],
) {
this.#fieldId = fieldId;
this.#simpleReplace = simpleReplace;
this.#hideDeleteButton = hideDeleteButton;
this.#extraButtons = extraButtons;
+ this.#thumbnailSize = thumbnailSize;
this.#container = document.getElementById(fieldId + "Container")!;
if (this.#container === null) {
#fileInitializationCompleted(element: WoltlabCoreFileElement, container: HTMLElement): void {
if (this.#useBigPreview) {
- element.dataset.previewUrl = element.link!;
- element.unbounded = true;
+ setThumbnail(
+ element,
+ element.thumbnails.find((thumbnail) => thumbnail.identifier === this.#thumbnailSize),
+ true,
+ );
} else {
if (element.isImage()) {
- const thumbnail = element.thumbnails.find((thumbnail) => thumbnail.identifier === "tiny");
- if (thumbnail !== undefined) {
- element.thumbnail = thumbnail;
- } else {
- element.dataset.previewUrl = element.link!;
- element.unbounded = false;
- }
+ const thumbnailSize = this.#thumbnailSize ?? "tiny";
+
+ const thumbnail = element.thumbnails.find((thumbnail) => thumbnail.identifier === thumbnailSize);
+ setThumbnail(element, thumbnail);
if (element.link !== undefined && element.filename !== undefined) {
const filenameLink = document.createElement("a");
}
}
+function setThumbnail(element: WoltlabCoreFileElement, thumbnail?: Thumbnail, unbounded: boolean = false) {
+ if (unbounded) {
+ element.dataset.previewUrl = thumbnail !== undefined ? thumbnail.link : element.link;
+ } else if (thumbnail !== undefined) {
+ element.thumbnail = thumbnail;
+ }
+
+ element.unbounded = unbounded;
+}
+
export function getValues(fieldId: string): undefined | number | Set<number> {
const field = fileProcessors.get(fieldId);
if (field === undefined) {
#singleFileUpload;
#simpleReplace;
#hideDeleteButton;
+ #thumbnailSize;
#extraButtons;
#uploadResolve;
- constructor(fieldId, singleFileUpload = false, useBigPreview = false, simpleReplace = false, hideDeleteButton = false, extraButtons = []) {
+ constructor(fieldId, singleFileUpload = false, useBigPreview = false, simpleReplace = false, hideDeleteButton = false, thumbnailSize, extraButtons = []) {
this.#fieldId = fieldId;
this.#useBigPreview = useBigPreview;
this.#singleFileUpload = singleFileUpload;
this.#simpleReplace = simpleReplace;
this.#hideDeleteButton = hideDeleteButton;
this.#extraButtons = extraButtons;
+ this.#thumbnailSize = thumbnailSize;
this.#container = document.getElementById(fieldId + "Container");
if (this.#container === null) {
throw new Error("Unknown field with id '" + fieldId + "'");
}
#fileInitializationCompleted(element, container) {
if (this.#useBigPreview) {
- element.dataset.previewUrl = element.link;
- element.unbounded = true;
+ setThumbnail(element, element.thumbnails.find((thumbnail) => thumbnail.identifier === this.#thumbnailSize), true);
}
else {
if (element.isImage()) {
- const thumbnail = element.thumbnails.find((thumbnail) => thumbnail.identifier === "tiny");
- if (thumbnail !== undefined) {
- element.thumbnail = thumbnail;
- }
- else {
- element.dataset.previewUrl = element.link;
- element.unbounded = false;
- }
+ const thumbnailSize = this.#thumbnailSize ?? "tiny";
+ const thumbnail = element.thumbnails.find((thumbnail) => thumbnail.identifier === thumbnailSize);
+ setThumbnail(element, thumbnail);
if (element.link !== undefined && element.filename !== undefined) {
const filenameLink = document.createElement("a");
filenameLink.href = element.link;
}
}
exports.FileProcessor = FileProcessor;
+ function setThumbnail(element, thumbnail, unbounded = false) {
+ if (unbounded) {
+ element.dataset.previewUrl = thumbnail !== undefined ? thumbnail.link : element.link;
+ }
+ else if (thumbnail !== undefined) {
+ element.thumbnail = thumbnail;
+ }
+ element.unbounded = unbounded;
+ }
function getValues(fieldId) {
const field = fileProcessors.get(fieldId);
if (field === undefined) {
->bigPreview()
->simpleReplace()
->hideDeleteButton()
+ ->thumbnailSize('128')
->addDependency(
ValueFormFieldDependency::create('avatarType')
->fieldId('avatarType')
private bool $bigPreview = false;
private bool $simpleReplace = false;
private bool $hideDeleteButton = false;
+ private ?string $thumbnailSize = null;
private array $actionButtons = [];
#[\Override]
{
return $this->hideDeleteButton;
}
+
+ /**
+ * Sets the thumbnail size for the preview.
+ *
+ * If no size is set:
+ * - And the big preview is enabled, the full size is used
+ * - Otherwise, the thumbnail size `tiny` is used
+ */
+ public function thumbnailSize(?string $thumbnailSize): self
+ {
+ $this->thumbnailSize = $thumbnailSize;
+
+ return $this;
+ }
+
+ /**
+ * Returns the thumbnail size for the preview.
+ */
+ public function getThumbnailSize(): ?string
+ {
+ return $this->thumbnailSize;
+ }
}