Skip to content

Commit

Permalink
chore: drop support for Django < 1.9 in the dropzone init handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mbi committed Oct 2, 2023
1 parent 797fd21 commit bfa7045
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions filer/static/filer/js/addons/dropzone.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,38 +160,31 @@ djQuery(function ($) {
Dropzone.autoDiscover = false;
}
dropzones.each(createDropzone);
// window.__admin_utc_offset__ is used as canary to detect Django 1.8
// There is no way to feature detect the new behavior implemented in Django 1.9
if (!window.__admin_utc_offset__) {
$(document).on('formset:added', function (ev, row) {
if(ev.detail && ev.detail.formsetName) {
/*
Django 4.1 changed the event type being fired when adding
a new formset from a jQuery to a vanilla JavaScript event.
https://docs.djangoproject.com/en/4.1/ref/contrib/admin/javascript/

In this case we find the newly added row and initialize the
dropzone on any dropzoneSelector on that row.
*/
let rowIdx = parseInt(
document.getElementById(
'id_' + event.detail.formsetName + '-TOTAL_FORMS'
).value, 10
) - 1;
let row_ = document.getElementById( event.detail.formsetName + '-' + rowIdx);
var dropzones = $(row_).find(dropzoneSelector)
// Handle initialization of the dropzone on dynamic formsets (i.e. Django admin inlines)
$(document).on('formset:added', function (ev, row) {
if(ev.detail && ev.detail.formsetName) {
/*
Django 4.1 changed the event type being fired when adding
a new formset from a jQuery to a vanilla JavaScript event.
https://docs.djangoproject.com/en/4.1/ref/contrib/admin/javascript/
} else {
var dropzones = $(row).find(dropzoneSelector);
}
In this case we find the newly added row and initialize the
dropzone on any dropzoneSelector on that row.
*/
let rowIdx = parseInt(
document.getElementById(
'id_' + event.detail.formsetName + '-TOTAL_FORMS'
).value, 10
) - 1;
let row_ = document.getElementById(event.detail.formsetName + '-' + rowIdx);
var dropzones = $(row_).find(dropzoneSelector)

dropzones.each(createDropzone);
});
} else {
$('.add-row a').on('click', function () {
var dropzones = $(dropzoneSelector);
dropzones.each(createDropzone);
});
}
} else {
var dropzones = $(row).find(dropzoneSelector);
}

dropzones.each(createDropzone);
});
}
});

0 comments on commit bfa7045

Please sign in to comment.