parent
02de43236a
commit
e70b679d21
|
@ -1030,7 +1030,7 @@ async function initRepository() {
|
||||||
if ($dropzone.length === 1) {
|
if ($dropzone.length === 1) {
|
||||||
$dropzone.data('saved', false);
|
$dropzone.data('saved', false);
|
||||||
|
|
||||||
const filenameDict = {};
|
const fileUuidDict = {};
|
||||||
dz = await createDropzone($dropzone[0], {
|
dz = await createDropzone($dropzone[0], {
|
||||||
url: $dropzone.data('upload-url'),
|
url: $dropzone.data('upload-url'),
|
||||||
headers: {'X-Csrf-Token': csrf},
|
headers: {'X-Csrf-Token': csrf},
|
||||||
|
@ -1048,28 +1048,24 @@ async function initRepository() {
|
||||||
thumbnailHeight: 480,
|
thumbnailHeight: 480,
|
||||||
init() {
|
init() {
|
||||||
this.on('success', (file, data) => {
|
this.on('success', (file, data) => {
|
||||||
filenameDict[file.name] = {
|
fileUuidDict[file.uuid] = {
|
||||||
uuid: data.uuid,
|
|
||||||
submitted: false
|
submitted: false
|
||||||
};
|
};
|
||||||
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
|
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
|
||||||
$dropzone.find('.files').append(input);
|
$dropzone.find('.files').append(input);
|
||||||
});
|
});
|
||||||
this.on('removedfile', (file) => {
|
this.on('removedfile', (file) => {
|
||||||
if (!(file.name in filenameDict)) {
|
$(`#${file.uuid}`).remove();
|
||||||
return;
|
if ($dropzone.data('remove-url') && !fileUuidDict[file.uuid].submitted) {
|
||||||
}
|
|
||||||
$(`#${filenameDict[file.name].uuid}`).remove();
|
|
||||||
if ($dropzone.data('remove-url') && !filenameDict[file.name].submitted) {
|
|
||||||
$.post($dropzone.data('remove-url'), {
|
$.post($dropzone.data('remove-url'), {
|
||||||
file: filenameDict[file.name].uuid,
|
file: file.uuid,
|
||||||
_csrf: csrf,
|
_csrf: csrf,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.on('submit', () => {
|
this.on('submit', () => {
|
||||||
$.each(filenameDict, (name) => {
|
$.each(fileUuidDict, (fileUuid) => {
|
||||||
filenameDict[name].submitted = true;
|
fileUuidDict[fileUuid].submitted = true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.on('reload', () => {
|
this.on('reload', () => {
|
||||||
|
@ -1082,9 +1078,8 @@ async function initRepository() {
|
||||||
dz.emit('thumbnail', this, imgSrc);
|
dz.emit('thumbnail', this, imgSrc);
|
||||||
dz.emit('complete', this);
|
dz.emit('complete', this);
|
||||||
dz.files.push(this);
|
dz.files.push(this);
|
||||||
filenameDict[this.name] = {
|
fileUuidDict[this.uuid] = {
|
||||||
submitted: true,
|
submitted: true,
|
||||||
uuid: this.uuid
|
|
||||||
};
|
};
|
||||||
$dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%');
|
$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="${this.uuid}" name="files" type="hidden">`).val(this.uuid);
|
||||||
|
@ -2674,7 +2669,6 @@ $(document).ready(async () => {
|
||||||
|
|
||||||
// Dropzone
|
// Dropzone
|
||||||
for (const el of document.querySelectorAll('.dropzone')) {
|
for (const el of document.querySelectorAll('.dropzone')) {
|
||||||
const filenameDict = {};
|
|
||||||
const $dropzone = $(el);
|
const $dropzone = $(el);
|
||||||
await createDropzone(el, {
|
await createDropzone(el, {
|
||||||
url: $dropzone.data('upload-url'),
|
url: $dropzone.data('upload-url'),
|
||||||
|
@ -2692,18 +2686,15 @@ $(document).ready(async () => {
|
||||||
thumbnailWidth: 480,
|
thumbnailWidth: 480,
|
||||||
thumbnailHeight: 480,
|
thumbnailHeight: 480,
|
||||||
init() {
|
init() {
|
||||||
this.on('success', (file, data) => {
|
this.on('success', (_file, data) => {
|
||||||
filenameDict[file.name] = data.uuid;
|
|
||||||
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
|
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
|
||||||
$dropzone.find('.files').append(input);
|
$dropzone.find('.files').append(input);
|
||||||
});
|
});
|
||||||
this.on('removedfile', (file) => {
|
this.on('removedfile', (file) => {
|
||||||
if (file.name in filenameDict) {
|
$(`#${file.uuid}`).remove();
|
||||||
$(`#${filenameDict[file.name]}`).remove();
|
|
||||||
}
|
|
||||||
if ($dropzone.data('remove-url')) {
|
if ($dropzone.data('remove-url')) {
|
||||||
$.post($dropzone.data('remove-url'), {
|
$.post($dropzone.data('remove-url'), {
|
||||||
file: filenameDict[file.name],
|
file: file.uuid,
|
||||||
_csrf: csrf
|
_csrf: csrf
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue