Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1d5a273

Browse files
committedApr 20, 2023
fix merge
1 parent 665b509 commit 1d5a273

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed
 

‎templates/repo/issue/view_content/attachments.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="dropzone-attachments">
22
{{if .Attachments}}
3-
<div class="ui clearing divider"></div>
3+
<div class="ui divider"></div>
44
{{end}}
55
{{$hasThumbnails := false}}
66
{{- range .Attachments -}}

‎web_src/css/features/dropzone.css

-5
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,3 @@
5151
.dropzone .dz-preview:hover .dz-image img {
5252
filter: opacity(0.5) !important;
5353
}
54-
55-
.dropzone-attachments .grid,
56-
.dropzone-attachments .thumbnails {
57-
padding: .5rem 1rem;
58-
}

‎web_src/js/features/repo-legacy.js

+29-24
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,19 @@ async function onEditContent(event) {
333333
let dz;
334334
const $dropzone = $editContentZone.find('.dropzone');
335335
if ($dropzone.length === 1) {
336-
$dropzone.data('saved', false);
337-
338-
const fileUuidDict = {};
339-
dz = await createDropzone($dropzone[0], {
340-
url: $dropzone.data('upload-url'),
336+
let disableRemovedfileEvent = false; // when resetting the dropzone (removeAllFiles), disable the "removedfile" event
337+
let fileUuidDict = {}; // to record: if a comment has been saved, then the uploaded files won't be deleted from server when clicking the Remove in the dropzone
338+
const dz = await createDropzone($dropzone[0], {
339+
url: $dropzone.attr('data-upload-url'),
341340
headers: {'X-Csrf-Token': csrfToken},
342-
maxFiles: $dropzone.data('max-file'),
343-
maxFilesize: $dropzone.data('max-size'),
344-
acceptedFiles: (['*/*', ''].includes($dropzone.data('accepts'))) ? null : $dropzone.data('accepts'),
341+
maxFiles: $dropzone.attr('data-max-file'),
342+
maxFilesize: $dropzone.attr('data-max-size'),
343+
acceptedFiles: (['*/*', ''].includes($dropzone.attr('data-accepts'))) ? null : $dropzone.attr('data-accepts'),
345344
addRemoveLinks: true,
346-
dictDefaultMessage: $dropzone.data('default-message'),
347-
dictInvalidFileType: $dropzone.data('invalid-input-type'),
348-
dictFileTooBig: $dropzone.data('file-too-big'),
349-
dictRemoveFile: $dropzone.data('remove-file'),
345+
dictDefaultMessage: $dropzone.attr('data-default-message'),
346+
dictInvalidFileType: $dropzone.attr('data-invalid-input-type'),
347+
dictFileTooBig: $dropzone.attr('data-file-too-big'),
348+
dictRemoveFile: $dropzone.attr('data-remove-file'),
350349
timeout: 0,
351350
thumbnailMethod: 'contain',
352351
thumbnailWidth: 480,
@@ -359,9 +358,10 @@ async function onEditContent(event) {
359358
$dropzone.find('.files').append(input);
360359
});
361360
this.on('removedfile', (file) => {
361+
if (disableRemovedfileEvent) return;
362362
$(`#${file.uuid}`).remove();
363-
if ($dropzone.data('remove-url') && !fileUuidDict[file.uuid].submitted) {
364-
$.post($dropzone.data('remove-url'), {
363+
if ($dropzone.attr('data-remove-url') && !fileUuidDict[file.uuid].submitted) {
364+
$.post($dropzone.attr('data-remove-url'), {
365365
file: file.uuid,
366366
_csrf: csrfToken,
367367
});
@@ -373,20 +373,25 @@ async function onEditContent(event) {
373373
});
374374
});
375375
this.on('reload', () => {
376-
$.getJSON($editContentZone.data('attachment-url'), (data) => {
376+
$.getJSON($editContentZone.attr('data-attachment-url'), (data) => {
377+
// do not trigger the "removedfile" event, otherwise the attachments would be deleted from server
378+
disableRemovedfileEvent = true;
377379
dz.removeAllFiles(true);
378380
$dropzone.find('.files').empty();
379-
$.each(data, function () {
380-
const imgSrc = `${$dropzone.data('link-url')}/${this.uuid}`;
381-
dz.emit('addedfile', this);
382-
dz.emit('thumbnail', this, imgSrc);
383-
dz.emit('complete', this);
384-
dz.files.push(this);
385-
fileUuidDict[this.uuid] = {submitted: true};
381+
fileUuidDict = {};
382+
disableRemovedfileEvent = false;
383+
384+
for (const attachment of data) {
385+
const imgSrc = `${$dropzone.attr('data-link-url')}/${attachment.uuid}`;
386+
dz.emit('addedfile', attachment);
387+
dz.emit('thumbnail', attachment, imgSrc);
388+
dz.emit('complete', attachment);
389+
dz.files.push(attachment);
390+
fileUuidDict[attachment.uuid] = {submitted: true};
386391
$dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%');
387-
const input = $(`<input id="${this.uuid}" name="files" type="hidden">`).val(this.uuid);
392+
const input = $(`<input id="${attachment.uuid}" name="files" type="hidden">`).val(attachment.uuid);
388393
$dropzone.find('.files').append(input);
389-
});
394+
}
390395
});
391396
});
392397
},

0 commit comments

Comments
 (0)