Skip to content

Commit 3090f25

Browse files
authored
Merge pull request #6653 from WoltLab/62-attachment-delete-confirmation
Add missing confirmation when deleting attachments
2 parents 4caecbc + 1b5c5fd commit 3090f25

2 files changed

Lines changed: 27 additions & 18 deletions

File tree

  • ts/WoltLabSuite/Core/Component/Attachment
  • wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment

ts/WoltLabSuite/Core/Component/Attachment/Entry.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
trackUploadProgress,
1212
updateFileInformation,
1313
} from "WoltLabSuite/Core/Component/File/Helper";
14+
import { confirmationFactory } from "../Confirmation";
1415

1516
export type FileProcessorData = {
1617
attachmentID: number;
@@ -108,7 +109,9 @@ function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFile
108109
}
109110

110111
const listItem = document.createElement("li");
111-
listItem.append(getDeleteAttachButton(fileId, (data as FileProcessorData).attachmentID, editor, element));
112+
listItem.append(
113+
getDeleteAttachButton(fileId, (data as FileProcessorData).attachmentID, editor, element, file.filename),
114+
);
112115
dropdownMenu.append(listItem);
113116

114117
const moreOptions = document.createElement("button");
@@ -137,21 +140,25 @@ function getDeleteAttachButton(
137140
attachmentId: number,
138141
editor: HTMLElement,
139142
element: HTMLElement,
143+
filename: string | undefined,
140144
): HTMLButtonElement {
141145
const button = document.createElement("button");
142146
button.type = "button";
143147
button.textContent = getPhrase("wcf.global.button.delete");
144148

145-
button.addEventListener("click", () => {
146-
void deleteFile(fileId).then((result) => {
147-
result.unwrap();
149+
button.addEventListener("click", async () => {
150+
const confirmationResult = await confirmationFactory().delete(filename);
151+
if (!confirmationResult) {
152+
return;
153+
}
148154

149-
dispatchToCkeditor(editor).removeAttachment({
150-
attachmentId,
151-
});
155+
(await deleteFile(fileId)).unwrap();
152156

153-
element.remove();
157+
dispatchToCkeditor(editor).removeAttachment({
158+
attachmentId,
154159
});
160+
161+
element.remove();
155162
});
156163

157164
return button;

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment/Entry.js

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)