Skip to content

Commit e70b679

Browse files
authored
Fix wrong attachment removal (#16915) (#16917)
Backport #16917
1 parent 02de432 commit e70b679

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

web_src/js/index.js

+11-20
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ async function initRepository() {
10301030
if ($dropzone.length === 1) {
10311031
$dropzone.data('saved', false);
10321032

1033-
const filenameDict = {};
1033+
const fileUuidDict = {};
10341034
dz = await createDropzone($dropzone[0], {
10351035
url: $dropzone.data('upload-url'),
10361036
headers: {'X-Csrf-Token': csrf},
@@ -1048,28 +1048,24 @@ async function initRepository() {
10481048
thumbnailHeight: 480,
10491049
init() {
10501050
this.on('success', (file, data) => {
1051-
filenameDict[file.name] = {
1052-
uuid: data.uuid,
1051+
fileUuidDict[file.uuid] = {
10531052
submitted: false
10541053
};
10551054
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
10561055
$dropzone.find('.files').append(input);
10571056
});
10581057
this.on('removedfile', (file) => {
1059-
if (!(file.name in filenameDict)) {
1060-
return;
1061-
}
1062-
$(`#${filenameDict[file.name].uuid}`).remove();
1063-
if ($dropzone.data('remove-url') && !filenameDict[file.name].submitted) {
1058+
$(`#${file.uuid}`).remove();
1059+
if ($dropzone.data('remove-url') && !fileUuidDict[file.uuid].submitted) {
10641060
$.post($dropzone.data('remove-url'), {
1065-
file: filenameDict[file.name].uuid,
1061+
file: file.uuid,
10661062
_csrf: csrf,
10671063
});
10681064
}
10691065
});
10701066
this.on('submit', () => {
1071-
$.each(filenameDict, (name) => {
1072-
filenameDict[name].submitted = true;
1067+
$.each(fileUuidDict, (fileUuid) => {
1068+
fileUuidDict[fileUuid].submitted = true;
10731069
});
10741070
});
10751071
this.on('reload', () => {
@@ -1082,9 +1078,8 @@ async function initRepository() {
10821078
dz.emit('thumbnail', this, imgSrc);
10831079
dz.emit('complete', this);
10841080
dz.files.push(this);
1085-
filenameDict[this.name] = {
1081+
fileUuidDict[this.uuid] = {
10861082
submitted: true,
1087-
uuid: this.uuid
10881083
};
10891084
$dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%');
10901085
const input = $(`<input id="${this.uuid}" name="files" type="hidden">`).val(this.uuid);
@@ -2674,7 +2669,6 @@ $(document).ready(async () => {
26742669

26752670
// Dropzone
26762671
for (const el of document.querySelectorAll('.dropzone')) {
2677-
const filenameDict = {};
26782672
const $dropzone = $(el);
26792673
await createDropzone(el, {
26802674
url: $dropzone.data('upload-url'),
@@ -2692,18 +2686,15 @@ $(document).ready(async () => {
26922686
thumbnailWidth: 480,
26932687
thumbnailHeight: 480,
26942688
init() {
2695-
this.on('success', (file, data) => {
2696-
filenameDict[file.name] = data.uuid;
2689+
this.on('success', (_file, data) => {
26972690
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
26982691
$dropzone.find('.files').append(input);
26992692
});
27002693
this.on('removedfile', (file) => {
2701-
if (file.name in filenameDict) {
2702-
$(`#${filenameDict[file.name]}`).remove();
2703-
}
2694+
$(`#${file.uuid}`).remove();
27042695
if ($dropzone.data('remove-url')) {
27052696
$.post($dropzone.data('remove-url'), {
2706-
file: filenameDict[file.name],
2697+
file: file.uuid,
27072698
_csrf: csrf
27082699
});
27092700
}

0 commit comments

Comments
 (0)