Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Apr 20, 2023
1 parent 665b509 commit 1d5a273
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion templates/repo/issue/view_content/attachments.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="dropzone-attachments">
{{if .Attachments}}
<div class="ui clearing divider"></div>
<div class="ui divider"></div>
{{end}}
{{$hasThumbnails := false}}
{{- range .Attachments -}}
Expand Down
5 changes: 0 additions & 5 deletions web_src/css/features/dropzone.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,3 @@
.dropzone .dz-preview:hover .dz-image img {
filter: opacity(0.5) !important;
}

.dropzone-attachments .grid,
.dropzone-attachments .thumbnails {
padding: .5rem 1rem;
}
53 changes: 29 additions & 24 deletions web_src/js/features/repo-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,19 @@ async function onEditContent(event) {
let dz;
const $dropzone = $editContentZone.find('.dropzone');
if ($dropzone.length === 1) {
$dropzone.data('saved', false);

const fileUuidDict = {};
dz = await createDropzone($dropzone[0], {
url: $dropzone.data('upload-url'),
let disableRemovedfileEvent = false; // when resetting the dropzone (removeAllFiles), disable the "removedfile" event
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
const dz = await createDropzone($dropzone[0], {
url: $dropzone.attr('data-upload-url'),
headers: {'X-Csrf-Token': csrfToken},
maxFiles: $dropzone.data('max-file'),
maxFilesize: $dropzone.data('max-size'),
acceptedFiles: (['*/*', ''].includes($dropzone.data('accepts'))) ? null : $dropzone.data('accepts'),
maxFiles: $dropzone.attr('data-max-file'),
maxFilesize: $dropzone.attr('data-max-size'),
acceptedFiles: (['*/*', ''].includes($dropzone.attr('data-accepts'))) ? null : $dropzone.attr('data-accepts'),
addRemoveLinks: true,
dictDefaultMessage: $dropzone.data('default-message'),
dictInvalidFileType: $dropzone.data('invalid-input-type'),
dictFileTooBig: $dropzone.data('file-too-big'),
dictRemoveFile: $dropzone.data('remove-file'),
dictDefaultMessage: $dropzone.attr('data-default-message'),
dictInvalidFileType: $dropzone.attr('data-invalid-input-type'),
dictFileTooBig: $dropzone.attr('data-file-too-big'),
dictRemoveFile: $dropzone.attr('data-remove-file'),
timeout: 0,
thumbnailMethod: 'contain',
thumbnailWidth: 480,
Expand All @@ -359,9 +358,10 @@ async function onEditContent(event) {
$dropzone.find('.files').append(input);
});
this.on('removedfile', (file) => {
if (disableRemovedfileEvent) return;
$(`#${file.uuid}`).remove();
if ($dropzone.data('remove-url') && !fileUuidDict[file.uuid].submitted) {
$.post($dropzone.data('remove-url'), {
if ($dropzone.attr('data-remove-url') && !fileUuidDict[file.uuid].submitted) {
$.post($dropzone.attr('data-remove-url'), {
file: file.uuid,
_csrf: csrfToken,
});
Expand All @@ -373,20 +373,25 @@ async function onEditContent(event) {
});
});
this.on('reload', () => {
$.getJSON($editContentZone.data('attachment-url'), (data) => {
$.getJSON($editContentZone.attr('data-attachment-url'), (data) => {
// do not trigger the "removedfile" event, otherwise the attachments would be deleted from server
disableRemovedfileEvent = true;
dz.removeAllFiles(true);
$dropzone.find('.files').empty();
$.each(data, function () {
const imgSrc = `${$dropzone.data('link-url')}/${this.uuid}`;
dz.emit('addedfile', this);
dz.emit('thumbnail', this, imgSrc);
dz.emit('complete', this);
dz.files.push(this);
fileUuidDict[this.uuid] = {submitted: true};
fileUuidDict = {};
disableRemovedfileEvent = false;

for (const attachment of data) {
const imgSrc = `${$dropzone.attr('data-link-url')}/${attachment.uuid}`;
dz.emit('addedfile', attachment);
dz.emit('thumbnail', attachment, imgSrc);
dz.emit('complete', attachment);
dz.files.push(attachment);
fileUuidDict[attachment.uuid] = {submitted: true};
$dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%');
const input = $(`<input id="${this.uuid}" name="files" type="hidden">`).val(this.uuid);
const input = $(`<input id="${attachment.uuid}" name="files" type="hidden">`).val(attachment.uuid);
$dropzone.find('.files').append(input);
});
}
});
});
},
Expand Down

0 comments on commit 1d5a273

Please sign in to comment.