return this.#singleFileUpload && this.#imageOnly;
}
- async #registerFile(element: WoltlabCoreFileElement, elementContainer: HTMLElement | null = null): Promise<void> {
- if (elementContainer === null) {
- if (this.showBigPreview) {
- elementContainer = this.#container.querySelector(".fileUpload__preview");
- if (elementContainer === null) {
- elementContainer = document.createElement("div");
- elementContainer.classList.add("fileUpload__preview");
- this.#uploadButton.insertAdjacentElement("beforebegin", elementContainer);
- }
- } else {
- elementContainer = document.createElement("li");
- elementContainer.classList.add("fileUpload__fileList__item");
- this.#container.querySelector(".fileUpload__fileList")!.append(elementContainer);
- }
- elementContainer.append(element);
- }
-
- try {
- await element.ready;
-
- if (this.#replaceElement !== undefined) {
- await deleteFile(this.#replaceElement.fileId!);
- this.#replaceElement = undefined;
- }
- } catch (reason) {
- // reinsert the element and show an error message
- if (this.#replaceElement !== undefined) {
- await this.#registerFile(this.#replaceElement);
- this.#replaceElement = undefined;
- }
- this.#markElementUploadHasFailed(elementContainer, element, reason);
- return;
- }
-
- if (this.showBigPreview) {
- element.dataset.previewUrl = element.link!;
- element.unbounded = 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;
- }
- }
+ protected addButtons(element: WoltlabCoreFileElement): void {
+ const buttons = document.createElement("ul");
+ buttons.classList.add("buttonList");
+ buttons.classList.add(this.classPrefix + "buttons");
- const input = document.createElement("input");
- input.type = "hidden";
- input.name = this.#singleFileUpload ? this.#fieldId : this.#fieldId + "[]";
- input.value = element.fileId!.toString();
- elementContainer.append(input);
+ this.addDeleteButton(element, buttons);
+ this.addReplaceButton(element, buttons);
- this.#addButtons(element);
+ element.parentElement!.append(buttons);
}
#markElementUploadHasFailed(container: HTMLElement, element: WoltlabCoreFileElement, reason: unknown): void {
element.append(errorElement);
}
- #addButtons(element: WoltlabCoreFileElement): void {
- const buttons = document.createElement("ul");
- buttons.classList.add("buttonList");
- buttons.classList.add(this.classPrefix + "buttons");
-
- this.#addDeleteButton(element, buttons);
- this.#addReplaceButton(element, buttons);
-
- element.parentElement!.append(buttons);
- }
-
- #addDeleteButton(element: WoltlabCoreFileElement, buttons: HTMLUListElement): void {
+ protected addDeleteButton(element: WoltlabCoreFileElement, buttons: HTMLUListElement): void {
const deleteButton = document.createElement("button");
deleteButton.type = "button";
deleteButton.classList.add("button", "small");
buttons.append(listItem);
}
- #unregisterFile(element: WoltlabCoreFileElement): void {
- if (this.showBigPreview) {
- element.parentElement!.innerHTML = "";
- } else {
- element.parentElement!.remove();
- }
- }
-
- #addReplaceButton(element: WoltlabCoreFileElement, buttons: HTMLUListElement): void {
+ protected addReplaceButton(element: WoltlabCoreFileElement, buttons: HTMLUListElement): void {
const replaceButton = document.createElement("button");
replaceButton.type = "button";
replaceButton.classList.add("button", "small");
listItem.append(replaceButton);
buttons.append(listItem);
}
+
+ #unregisterFile(element: WoltlabCoreFileElement): void {
+ if (this.showBigPreview) {
+ element.parentElement!.innerHTML = "";
+ } else {
+ element.parentElement!.remove();
+ }
+ }
+
+ async #registerFile(element: WoltlabCoreFileElement, elementContainer: HTMLElement | null = null): Promise<void> {
+ if (elementContainer === null) {
+ if (this.showBigPreview) {
+ elementContainer = this.#container.querySelector(".fileUpload__preview");
+ if (elementContainer === null) {
+ elementContainer = document.createElement("div");
+ elementContainer.classList.add("fileUpload__preview");
+ this.#uploadButton.insertAdjacentElement("beforebegin", elementContainer);
+ }
+ } else {
+ elementContainer = document.createElement("li");
+ elementContainer.classList.add("fileUpload__fileList__item");
+ this.#container.querySelector(".fileUpload__fileList")!.append(elementContainer);
+ }
+ elementContainer.append(element);
+ }
+
+ try {
+ await element.ready;
+
+ if (this.#replaceElement !== undefined) {
+ await deleteFile(this.#replaceElement.fileId!);
+ this.#replaceElement = undefined;
+ }
+ } catch (reason) {
+ // reinsert the element and show an error message
+ if (this.#replaceElement !== undefined) {
+ await this.#registerFile(this.#replaceElement);
+ this.#replaceElement = undefined;
+ }
+ this.#markElementUploadHasFailed(elementContainer, element, reason);
+ return;
+ }
+
+ if (this.showBigPreview) {
+ element.dataset.previewUrl = element.link!;
+ element.unbounded = 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 input = document.createElement("input");
+ input.type = "hidden";
+ input.name = this.#singleFileUpload ? this.#fieldId : this.#fieldId + "[]";
+ input.value = element.fileId!.toString();
+ elementContainer.append(input);
+
+ this.addButtons(element);
+ }
}
get showBigPreview() {
return this.#singleFileUpload && this.#imageOnly;
}
- async #registerFile(element, elementContainer = null) {
- if (elementContainer === null) {
- if (this.showBigPreview) {
- elementContainer = this.#container.querySelector(".fileUpload__preview");
- if (elementContainer === null) {
- elementContainer = document.createElement("div");
- elementContainer.classList.add("fileUpload__preview");
- this.#uploadButton.insertAdjacentElement("beforebegin", elementContainer);
- }
- }
- else {
- elementContainer = document.createElement("li");
- elementContainer.classList.add("fileUpload__fileList__item");
- this.#container.querySelector(".fileUpload__fileList").append(elementContainer);
- }
- elementContainer.append(element);
- }
- try {
- await element.ready;
- if (this.#replaceElement !== undefined) {
- await (0, DeleteFile_1.deleteFile)(this.#replaceElement.fileId);
- this.#replaceElement = undefined;
- }
- }
- catch (reason) {
- // reinsert the element and show an error message
- if (this.#replaceElement !== undefined) {
- await this.#registerFile(this.#replaceElement);
- this.#replaceElement = undefined;
- }
- this.#markElementUploadHasFailed(elementContainer, element, reason);
- return;
- }
- if (this.showBigPreview) {
- element.dataset.previewUrl = element.link;
- element.unbounded = 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 input = document.createElement("input");
- input.type = "hidden";
- input.name = this.#singleFileUpload ? this.#fieldId : this.#fieldId + "[]";
- input.value = element.fileId.toString();
- elementContainer.append(input);
- this.#addButtons(element);
+ addButtons(element) {
+ const buttons = document.createElement("ul");
+ buttons.classList.add("buttonList");
+ buttons.classList.add(this.classPrefix + "buttons");
+ this.addDeleteButton(element, buttons);
+ this.addReplaceButton(element, buttons);
+ element.parentElement.append(buttons);
}
#markElementUploadHasFailed(container, element, reason) {
if (reason instanceof Error) {
errorElement.textContent = errorMessage;
element.append(errorElement);
}
- #addButtons(element) {
- const buttons = document.createElement("ul");
- buttons.classList.add("buttonList");
- buttons.classList.add(this.classPrefix + "buttons");
- this.#addDeleteButton(element, buttons);
- this.#addReplaceButton(element, buttons);
- element.parentElement.append(buttons);
- }
- #addDeleteButton(element, buttons) {
+ addDeleteButton(element, buttons) {
const deleteButton = document.createElement("button");
deleteButton.type = "button";
deleteButton.classList.add("button", "small");
listItem.append(deleteButton);
buttons.append(listItem);
}
- #unregisterFile(element) {
- if (this.showBigPreview) {
- element.parentElement.innerHTML = "";
- }
- else {
- element.parentElement.remove();
- }
- }
- #addReplaceButton(element, buttons) {
+ addReplaceButton(element, buttons) {
const replaceButton = document.createElement("button");
replaceButton.type = "button";
replaceButton.classList.add("button", "small");
listItem.append(replaceButton);
buttons.append(listItem);
}
+ #unregisterFile(element) {
+ if (this.showBigPreview) {
+ element.parentElement.innerHTML = "";
+ }
+ else {
+ element.parentElement.remove();
+ }
+ }
+ async #registerFile(element, elementContainer = null) {
+ if (elementContainer === null) {
+ if (this.showBigPreview) {
+ elementContainer = this.#container.querySelector(".fileUpload__preview");
+ if (elementContainer === null) {
+ elementContainer = document.createElement("div");
+ elementContainer.classList.add("fileUpload__preview");
+ this.#uploadButton.insertAdjacentElement("beforebegin", elementContainer);
+ }
+ }
+ else {
+ elementContainer = document.createElement("li");
+ elementContainer.classList.add("fileUpload__fileList__item");
+ this.#container.querySelector(".fileUpload__fileList").append(elementContainer);
+ }
+ elementContainer.append(element);
+ }
+ try {
+ await element.ready;
+ if (this.#replaceElement !== undefined) {
+ await (0, DeleteFile_1.deleteFile)(this.#replaceElement.fileId);
+ this.#replaceElement = undefined;
+ }
+ }
+ catch (reason) {
+ // reinsert the element and show an error message
+ if (this.#replaceElement !== undefined) {
+ await this.#registerFile(this.#replaceElement);
+ this.#replaceElement = undefined;
+ }
+ this.#markElementUploadHasFailed(elementContainer, element, reason);
+ return;
+ }
+ if (this.showBigPreview) {
+ element.dataset.previewUrl = element.link;
+ element.unbounded = 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 input = document.createElement("input");
+ input.type = "hidden";
+ input.name = this.#singleFileUpload ? this.#fieldId : this.#fieldId + "[]";
+ input.value = element.fileId.toString();
+ elementContainer.append(input);
+ this.addButtons(element);
+ }
}
exports.FileProcessor = FileProcessor;
});