<div class="messageTabMenuContent" id="attachments_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}">
{unsafe:$attachmentHandler->getHtmlElement()}
+
+ <div class="attachment__list__existingFiles">
+ {foreach from=$attachmentHandler->getAttachmentList() item=attachment}
+ {unsafe:$attachment->toHtmlElement()}
+ {/foreach}
+ </div>
+
<dl class="wide">
<dt></dt>
<dd>
</dd>
</dl>
- {foreach from=$attachmentHandler->getAttachmentList() item=attachment}
- {unsafe:$attachment->toHtmlElement()}
- {/foreach}
-
<script data-relocate="true">
require(["WoltLabSuite/Core/Component/Attachment/List"], ({ setup }) => {
setup("{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}");
import { dispatchToCkeditor } from "../Ckeditor/Event";
import WoltlabCoreFileElement from "../File/woltlab-core-file";
+import "../File/woltlab-core-file";
+
type FileProcessorData = {
attachmentID: number;
};
uploadButton.addEventListener("uploadStart", (event: CustomEvent<WoltlabCoreFileElement>) => {
upload(fileList!, event.detail, editorId);
});
+
+ const existingFiles = container.querySelector<HTMLElement>(".attachment__list__existingFiles");
+ if (existingFiles !== null) {
+ existingFiles.querySelectorAll("woltlab-core-file").forEach((file) => {
+ upload(fileList, file, editorId);
+ });
+
+ existingFiles.remove();
+ }
}
}
connectedCallback() {
+ let wasAlreadyReady = false;
if (this.#state === State.Initial) {
- this.#initializeState();
+ wasAlreadyReady = this.#initializeState();
}
this.#rebuildElement();
+
+ if (wasAlreadyReady) {
+ this.#readyResolve();
+ }
}
- #initializeState(): void {
+ #initializeState(): boolean {
// Files that exist at page load have a valid file id, otherwise a new
// file element can only be the result of an upload attempt.
if (this.#fileId === undefined) {
} else {
this.#state = State.Uploading;
- return;
+ return false;
}
}
}
}
+ if (this.dataset.metaData) {
+ this.#data = JSON.parse(this.dataset.metaData);
+ }
+
this.#state = State.Ready;
+
+ return true;
}
#rebuildElement(): void {
-define(["require", "exports", "WoltLabSuite/Core/Api/Files/DeleteFile", "../Ckeditor/Event"], function (require, exports, DeleteFile_1, Event_1) {
+define(["require", "exports", "WoltLabSuite/Core/Api/Files/DeleteFile", "../Ckeditor/Event", "../File/woltlab-core-file"], function (require, exports, DeleteFile_1, Event_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setup = void 0;
uploadButton.addEventListener("uploadStart", (event) => {
upload(fileList, event.detail, editorId);
});
+ const existingFiles = container.querySelector(".attachment__list__existingFiles");
+ if (existingFiles !== null) {
+ existingFiles.querySelectorAll("woltlab-core-file").forEach((file) => {
+ upload(fileList, file, editorId);
+ });
+ existingFiles.remove();
+ }
}
exports.setup = setup;
});
});
}
connectedCallback() {
+ let wasAlreadyReady = false;
if (this.#state === 0 /* State.Initial */) {
- this.#initializeState();
+ wasAlreadyReady = this.#initializeState();
}
this.#rebuildElement();
+ if (wasAlreadyReady) {
+ this.#readyResolve();
+ }
}
#initializeState() {
// Files that exist at page load have a valid file id, otherwise a new
}
else {
this.#state = 1 /* State.Uploading */;
- return;
+ return false;
}
}
// Initialize the list of thumbnails from the data attribute.
this.#thumbnails.push(new Thumbnail(thumbnail.identifier, thumbnail.link));
}
}
+ if (this.dataset.metaData) {
+ this.#data = JSON.parse(this.dataset.metaData);
+ }
this.#state = 3 /* State.Ready */;
+ return true;
}
#rebuildElement() {
switch (this.#state) {
public function toHtmlElement(): ?string
{
- return $this->getFile()?->toHtmlElement();
+ return $this->getFile()?->toHtmlElement([
+ 'attachmentID' => $this->attachmentID,
+ ]);
}
public static function findByFileID(int $fileID): ?Attachment
return $this->thumbnails[$identifier] ?? null;
}
- public function toHtmlElement(): string
+ public function toHtmlElement(array $metaData): string
{
$thumbnails = [];
foreach ($this->thumbnails as $thumbnail) {
data-filename="%s"
data-mime-type="%s"
data-thumbnails="%s"
+ data-meta-data="%s"
></woltlab-core-file>
EOT,
$this->fileID,
StringUtil::encodeHTML($this->filename),
StringUtil::encodeHTML($this->mimeType),
StringUtil::encodeHTML(\json_encode($thumbnails)),
+ StringUtil::encodeHTML(\json_encode($metaData)),
);
}