From ed715236144f903a633d9c8e8c5f2c9fb76e925b Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Wed, 13 Nov 2024 11:13:01 +0100 Subject: [PATCH] Display an error message if the file cannot be deleted --- .../Builder/Field/Controller/FileProcessor.ts | 17 ++++++++++++++-- .../Builder/Field/Controller/FileProcessor.js | 20 ++++++++++++++++--- ...PreloadPhrasesCollectingListener.class.php | 2 ++ wcfsetup/install/files/style/ui/fileList.scss | 7 ++++++- wcfsetup/install/lang/de.xml | 2 ++ wcfsetup/install/lang/en.xml | 2 ++ 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts index 0a55ad8202..e317778672 100644 --- a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts @@ -16,6 +16,7 @@ import { trackUploadProgress, } from "WoltLabSuite/Core/Component/File/Helper"; import { clearPreviousErrors } from "WoltLabSuite/Core/Component/File/Upload"; +import { innerError } from "WoltLabSuite/Core/Dom/Util"; type FileId = string; const fileProcessors = new Map(); @@ -129,9 +130,21 @@ export class FileProcessor { deleteButton.classList.add("button", "small"); deleteButton.textContent = getPhrase("wcf.global.button.delete"); deleteButton.addEventListener("click", async () => { - await deleteFile(element.fileId!); + const result = await deleteFile(element.fileId!); + if (result.ok) { + this.#unregisterFile(element); + } else { + let container: HTMLElement = element; + if (!this.#useBigPreview) { + container = container.parentElement!; + } - this.#unregisterFile(element); + if (result.error.code === "permission_denied") { + innerError(container, getPhrase("wcf.upload.error.delete.permissionDenied"), true); + } else { + innerError(container, result.error.message ?? getPhrase("wcf.upload.error.delete.unknownError")); + } + } }); return deleteButton; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js index c08dbf919a..9732fb6df6 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js @@ -4,7 +4,7 @@ * @license GNU Lesser General Public License * @since 6.1 */ -define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/Dom/Change/Listener", "WoltLabSuite/Core/Component/File/Helper", "WoltLabSuite/Core/Component/File/Upload"], function (require, exports, tslib_1, Language_1, DeleteFile_1, Listener_1, Helper_1, Upload_1) { +define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/Dom/Change/Listener", "WoltLabSuite/Core/Component/File/Helper", "WoltLabSuite/Core/Component/File/Upload", "WoltLabSuite/Core/Dom/Util"], function (require, exports, tslib_1, Language_1, DeleteFile_1, Listener_1, Helper_1, Upload_1, Util_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileProcessor = void 0; @@ -92,8 +92,22 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui deleteButton.classList.add("button", "small"); deleteButton.textContent = (0, Language_1.getPhrase)("wcf.global.button.delete"); deleteButton.addEventListener("click", async () => { - await (0, DeleteFile_1.deleteFile)(element.fileId); - this.#unregisterFile(element); + const result = await (0, DeleteFile_1.deleteFile)(element.fileId); + if (result.ok) { + this.#unregisterFile(element); + } + else { + let container = element; + if (!this.#useBigPreview) { + container = container.parentElement; + } + if (result.error.code === "permission_denied") { + (0, Util_1.innerError)(container, (0, Language_1.getPhrase)("wcf.upload.error.delete.permissionDenied"), true); + } + else { + (0, Util_1.innerError)(container, result.error.message ?? (0, Language_1.getPhrase)("wcf.upload.error.delete.unknownError")); + } + } }); return deleteButton; } diff --git a/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php b/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php index eab6ba99d9..6bced647c0 100644 --- a/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php +++ b/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php @@ -153,6 +153,8 @@ final class PreloadPhrasesCollectingListener $event->preload('wcf.upload.error.fileExtensionNotPermitted'); $event->preload('wcf.upload.error.fileSizeTooLarge'); $event->preload('wcf.upload.error.maximumCountReached'); + $event->preload('wcf.upload.error.delete.permissionDenied'); + $event->preload('wcf.upload.error.delete.unknownError'); $event->preload('wcf.user.activityPoint'); $event->preload('wcf.user.language'); diff --git a/wcfsetup/install/files/style/ui/fileList.scss b/wcfsetup/install/files/style/ui/fileList.scss index 21f32e74ce..ccd0a1067f 100644 --- a/wcfsetup/install/files/style/ui/fileList.scss +++ b/wcfsetup/install/files/style/ui/fileList.scss @@ -25,7 +25,8 @@ grid-template-areas: "file filename" "file fileSize" - "file buttons"; + "file buttons" + "file error"; grid-template-columns: 80px auto; padding: 10px; } @@ -38,6 +39,10 @@ color: var(--wcfStatusErrorText); } +.fileList__item .innerError { + grid-area: error; +} + .fileList__item__file { display: flex; grid-area: file; diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 99fa14ec69..0f1663d4d8 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -5566,6 +5566,8 @@ Benachrichtigungen auf {PAGE_TITLE|phra + + Ersetzen, um die Datei zu erneuern.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 179f1f29da..bbdb302647 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -5568,6 +5568,8 @@ your notifications on {PAGE_TITLE|phras + + Replace instead to renew the file.]]> -- 2.20.1