import { dispatchToCkeditor } from "../Ckeditor/Event";
import { deleteFile } from "WoltLabSuite/Core/Api/Files/DeleteFile";
import { getPhrase } from "WoltLabSuite/Core/Language";
-import { removeUploadProgress, trackUploadProgress } from "WoltLabSuite/Core/Component/File/File";
+import {
+ fileInitializationFailed,
+ removeUploadProgress,
+ trackUploadProgress,
+} from "WoltLabSuite/Core/Component/File/File";
type FileProcessorData = {
attachmentID: number;
return button;
}
-function fileInitializationFailed(element: HTMLElement, file: WoltlabCoreFileElement, reason: unknown): void {
- if (reason instanceof Error) {
- throw reason;
- }
-
- if (file.apiError === undefined) {
- return;
- }
-
- let errorMessage: string;
-
- const validationError = file.apiError.getValidationError();
- if (validationError !== undefined) {
- switch (validationError.param) {
- case "preflight":
- errorMessage = getPhrase(`wcf.upload.error.${validationError.code}`);
- break;
-
- default:
- errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
- break;
- }
- } else {
- errorMessage = `Unexpected server error: [${file.apiError.type}] ${file.apiError.message}`;
- }
-
- markElementAsErroneous(element, errorMessage);
-}
-
-function markElementAsErroneous(element: HTMLElement, errorMessage: string): void {
- element.classList.add("fileList__item--error");
-
- const errorElement = document.createElement("div");
- errorElement.classList.add("attachemnt__item__errorMessage");
- errorElement.textContent = errorMessage;
-
- element.append(errorElement);
-}
-
export function createAttachmentFromFile(file: WoltlabCoreFileElement, editor: HTMLElement) {
const element = document.createElement("li");
element.classList.add("fileList__item", "attachment__item");
import WoltlabCoreFileElement from "WoltLabSuite/Core/Component/File/woltlab-core-file";
+import { getPhrase } from "WoltLabSuite/Core/Language";
export function trackUploadProgress(element: HTMLElement, file: WoltlabCoreFileElement): void {
const progress = document.createElement("progress");
element.classList.remove("fileProcessor__item--uploading");
element.querySelector(".fileList__item__progress")?.remove();
}
+
+export function fileInitializationFailed(element: HTMLElement, file: WoltlabCoreFileElement, reason: unknown): void {
+ if (reason instanceof Error) {
+ throw reason;
+ }
+
+ if (file.apiError === undefined) {
+ return;
+ }
+
+ let errorMessage: string;
+
+ const validationError = file.apiError.getValidationError();
+ if (validationError !== undefined) {
+ switch (validationError.param) {
+ case "preflight":
+ errorMessage = getPhrase(`wcf.upload.error.${validationError.code}`);
+ break;
+
+ default:
+ errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
+ break;
+ }
+ } else {
+ errorMessage = `Unexpected server error: [${file.apiError.type}] ${file.apiError.message}`;
+ }
+
+ markElementAsErroneous(element, errorMessage);
+}
+
+function markElementAsErroneous(element: HTMLElement, errorMessage: string): void {
+ element.classList.add("fileList__item--error");
+
+ const errorElement = document.createElement("div");
+ errorElement.classList.add("attachemnt__item__errorMessage");
+ errorElement.textContent = errorMessage;
+
+ element.append(errorElement);
+}
import { deleteFile } from "WoltLabSuite/Core/Api/Files/DeleteFile";
import { formatFilesize } from "WoltLabSuite/Core/FileUtil";
import DomChangeListener from "WoltLabSuite/Core/Dom/Change/Listener";
-import { removeUploadProgress, trackUploadProgress } from "WoltLabSuite/Core/Component/File/File";
+import {
+ fileInitializationFailed,
+ removeUploadProgress,
+ trackUploadProgress,
+} from "WoltLabSuite/Core/Component/File/File";
const _data = new Map<string, FileProcessor>();
}
#markElementUploadHasFailed(container: HTMLElement, element: WoltlabCoreFileElement, reason: unknown): void {
- if (reason instanceof Error) {
- throw reason;
- }
- if (element.apiError === undefined) {
- return;
- }
- let errorMessage: string;
-
- const validationError = element.apiError.getValidationError();
- if (validationError !== undefined) {
- switch (validationError.param) {
- case "preflight":
- errorMessage = getPhrase(`wcf.upload.error.${validationError.code}`);
- break;
-
- default:
- errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
- break;
- }
- } else {
- errorMessage = `Unexpected server error: [${element.apiError.type}] ${element.apiError.message}`;
- }
+ fileInitializationFailed(container, element, reason);
container.classList.add("innerError");
-
- const errorElement = document.createElement("div");
- errorElement.classList.add(this.classPrefix + "item__errorMessage");
- errorElement.textContent = errorMessage;
-
- element.append(errorElement);
}
protected addDeleteButton(element: WoltlabCoreFileElement, buttons: HTMLUListElement): void {
});
return button;
}
- function fileInitializationFailed(element, file, reason) {
- if (reason instanceof Error) {
- throw reason;
- }
- if (file.apiError === undefined) {
- return;
- }
- let errorMessage;
- const validationError = file.apiError.getValidationError();
- if (validationError !== undefined) {
- switch (validationError.param) {
- case "preflight":
- errorMessage = (0, Language_1.getPhrase)(`wcf.upload.error.${validationError.code}`);
- break;
- default:
- errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
- break;
- }
- }
- else {
- errorMessage = `Unexpected server error: [${file.apiError.type}] ${file.apiError.message}`;
- }
- markElementAsErroneous(element, errorMessage);
- }
- function markElementAsErroneous(element, errorMessage) {
- element.classList.add("fileList__item--error");
- const errorElement = document.createElement("div");
- errorElement.classList.add("attachemnt__item__errorMessage");
- errorElement.textContent = errorMessage;
- element.append(errorElement);
- }
function createAttachmentFromFile(file, editor) {
const element = document.createElement("li");
element.classList.add("fileList__item", "attachment__item");
fileInitializationCompleted(element, file, editor);
})
.catch((reason) => {
- fileInitializationFailed(element, file, reason);
+ (0, File_1.fileInitializationFailed)(element, file, reason);
})
.finally(() => {
(0, File_1.removeUploadProgress)(element);
-define(["require", "exports"], function (require, exports) {
+define(["require", "exports", "WoltLabSuite/Core/Language"], function (require, exports, Language_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
- exports.removeUploadProgress = exports.trackUploadProgress = void 0;
+ exports.fileInitializationFailed = exports.removeUploadProgress = exports.trackUploadProgress = void 0;
function trackUploadProgress(element, file) {
const progress = document.createElement("progress");
progress.classList.add("fileList__item__progress__bar");
element.querySelector(".fileList__item__progress")?.remove();
}
exports.removeUploadProgress = removeUploadProgress;
+ function fileInitializationFailed(element, file, reason) {
+ if (reason instanceof Error) {
+ throw reason;
+ }
+ if (file.apiError === undefined) {
+ return;
+ }
+ let errorMessage;
+ const validationError = file.apiError.getValidationError();
+ if (validationError !== undefined) {
+ switch (validationError.param) {
+ case "preflight":
+ errorMessage = (0, Language_1.getPhrase)(`wcf.upload.error.${validationError.code}`);
+ break;
+ default:
+ errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
+ break;
+ }
+ }
+ else {
+ errorMessage = `Unexpected server error: [${file.apiError.type}] ${file.apiError.message}`;
+ }
+ markElementAsErroneous(element, errorMessage);
+ }
+ exports.fileInitializationFailed = fileInitializationFailed;
+ function markElementAsErroneous(element, errorMessage) {
+ element.classList.add("fileList__item--error");
+ const errorElement = document.createElement("div");
+ errorElement.classList.add("attachemnt__item__errorMessage");
+ errorElement.textContent = errorMessage;
+ element.append(errorElement);
+ }
});
container.append(buttons);
}
#markElementUploadHasFailed(container, element, reason) {
- if (reason instanceof Error) {
- throw reason;
- }
- if (element.apiError === undefined) {
- return;
- }
- let errorMessage;
- const validationError = element.apiError.getValidationError();
- if (validationError !== undefined) {
- switch (validationError.param) {
- case "preflight":
- errorMessage = (0, Language_1.getPhrase)(`wcf.upload.error.${validationError.code}`);
- break;
- default:
- errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
- break;
- }
- }
- else {
- errorMessage = `Unexpected server error: [${element.apiError.type}] ${element.apiError.message}`;
- }
+ (0, File_1.fileInitializationFailed)(container, element, reason);
container.classList.add("innerError");
- const errorElement = document.createElement("div");
- errorElement.classList.add(this.classPrefix + "item__errorMessage");
- errorElement.textContent = errorMessage;
- element.append(errorElement);
}
addDeleteButton(element, buttons) {
const deleteButton = document.createElement("button");