@@ -284,7 +284,8 @@ async function onEditContent(event) {
284
284
if ( $dropzone . length === 1 ) {
285
285
$dropzone . data ( 'saved' , false ) ;
286
286
287
- const fileUuidDict = { } ; // if a comment has been saved, then the uploaded files won't be deleted when clicking the Remove in the dropzone
287
+ let disableRemovedfileEvent = false ; // when resetting the dropzone (removeAllFiles), disable the removedfile event
288
+ let fileUuidDict = { } ; // if a comment has been saved, then the uploaded files won't be deleted from server when clicking the Remove in the dropzone
288
289
dz = await createDropzone ( $dropzone [ 0 ] , {
289
290
url : $dropzone . data ( 'upload-url' ) ,
290
291
headers : { 'X-Csrf-Token' : csrfToken } ,
@@ -308,6 +309,7 @@ async function onEditContent(event) {
308
309
$dropzone . find ( '.files' ) . append ( input ) ;
309
310
} ) ;
310
311
this . on ( 'removedfile' , ( file ) => {
312
+ if ( disableRemovedfileEvent ) return ;
311
313
$ ( `#${ file . uuid } ` ) . remove ( ) ;
312
314
if ( $dropzone . data ( 'remove-url' ) && ! fileUuidDict [ file . uuid ] ?. submitted ) {
313
315
$ . post ( $dropzone . data ( 'remove-url' ) , {
@@ -328,8 +330,11 @@ async function onEditContent(event) {
328
330
} ) ;
329
331
this . on ( 'reload' , ( ) => {
330
332
$ . getJSON ( $editContentZone . data ( 'attachment-url' ) , ( data ) => {
333
+ disableRemovedfileEvent = true ;
331
334
dz . removeAllFiles ( true ) ;
335
+ disableRemovedfileEvent = false ;
332
336
$dropzone . find ( '.files' ) . empty ( ) ;
337
+ fileUuidDict = { } ;
333
338
$ . each ( data , function ( ) {
334
339
const imgSrc = `${ $dropzone . data ( 'link-url' ) } /${ this . uuid } ` ;
335
340
dz . emit ( 'addedfile' , this ) ;
0 commit comments