Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong attachment removal (#16915) #16917

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ async function initRepository() {
if ($dropzone.length === 1) {
$dropzone.data('saved', false);

const filenameDict = {};
const fileUuidDict = {};
dz = await createDropzone($dropzone[0], {
url: $dropzone.data('upload-url'),
headers: {'X-Csrf-Token': csrf},
Expand All @@ -1048,28 +1048,24 @@ async function initRepository() {
thumbnailHeight: 480,
init() {
this.on('success', (file, data) => {
filenameDict[file.name] = {
uuid: data.uuid,
fileUuidDict[file.uuid] = {
submitted: false
};
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
$dropzone.find('.files').append(input);
});
this.on('removedfile', (file) => {
if (!(file.name in filenameDict)) {
return;
}
$(`#${filenameDict[file.name].uuid}`).remove();
if ($dropzone.data('remove-url') && !filenameDict[file.name].submitted) {
$(`#${file.uuid}`).remove();
if ($dropzone.data('remove-url') && !fileUuidDict[file.uuid].submitted) {
$.post($dropzone.data('remove-url'), {
file: filenameDict[file.name].uuid,
file: file.uuid,
_csrf: csrf,
});
}
});
this.on('submit', () => {
$.each(filenameDict, (name) => {
filenameDict[name].submitted = true;
$.each(fileUuidDict, (fileUuid) => {
fileUuidDict[fileUuid].submitted = true;
});
});
this.on('reload', () => {
Expand All @@ -1082,9 +1078,8 @@ async function initRepository() {
dz.emit('thumbnail', this, imgSrc);
dz.emit('complete', this);
dz.files.push(this);
filenameDict[this.name] = {
fileUuidDict[this.uuid] = {
submitted: true,
uuid: this.uuid
};
$dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%');
const input = $(`<input id="${this.uuid}" name="files" type="hidden">`).val(this.uuid);
Expand Down Expand Up @@ -2674,7 +2669,6 @@ $(document).ready(async () => {

// Dropzone
for (const el of document.querySelectorAll('.dropzone')) {
const filenameDict = {};
const $dropzone = $(el);
await createDropzone(el, {
url: $dropzone.data('upload-url'),
Expand All @@ -2692,18 +2686,15 @@ $(document).ready(async () => {
thumbnailWidth: 480,
thumbnailHeight: 480,
init() {
this.on('success', (file, data) => {
filenameDict[file.name] = data.uuid;
this.on('success', (_file, data) => {
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
$dropzone.find('.files').append(input);
});
this.on('removedfile', (file) => {
if (file.name in filenameDict) {
$(`#${filenameDict[file.name]}`).remove();
}
$(`#${file.uuid}`).remove();
if ($dropzone.data('remove-url')) {
$.post($dropzone.data('remove-url'), {
file: filenameDict[file.name],
file: file.uuid,
_csrf: csrf
});
}
Expand Down