Skip to content

Commit f66c44c

Browse files
committed
fix: correct Magnific-popup init
+ simplify inline tabular classes
1 parent ac74cca commit f66c44c

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

advanced_filters/templates/admin/advanced_filters.html

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{# Add the dialog content to the bottom of the content #}
2323
{% if advanced_filters %}
2424
{% with advanced_filters.fields_formset as formset %}
25-
<div class="white-popup mfp-hide" id="advanced_filters">
25+
<div class="{{ formset.classes }} white-popup mfp-hide" id="advanced_filters">
2626
<h1>{% trans "Create advanced filter" %}:</h1>
2727
<form novalidate method="POST" id="advanced_filters_form">
2828
{% csrf_token %}
@@ -42,7 +42,7 @@ <h1>{% trans "Create advanced filter" %}:</h1>
4242
</thead>
4343
<tbody>
4444
{% for form in formset %}
45-
<tr class="form-row {% cycle "row1" "row2" %} {% if forloop.last %}empty-form{% endif %}" id="{{ formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
45+
<tr class="form-row {% if forloop.last %}empty-form{% endif %}" id="{{ formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
4646
{{form.non_field_errors}}
4747
{% for field in form.visible_fields %}
4848
<td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
@@ -63,31 +63,38 @@ <h1>{% trans "Create advanced filter" %}:</h1>
6363
<br />
6464
<input method="POST" type="submit" value="{% trans "Save" %}">
6565
<input method="POST" name="_save_goto" type="submit" value="{% trans "Save & Filter Now!" %}">
66-
<a href="#" class="grp-button" style="margin:auto" onclick="$.magnificPopup.close();">{% trans "Cancel" %}</a>
66+
<a href="#" class="grp-button close" style="margin:auto">{% trans "Cancel" %}</a>
6767
</form>
6868

6969
{{ advanced_filters.media.js }}
7070

7171
<script type="text/javascript" charset="utf-8">
72-
// using django's original jquery, initial formset
73-
var FORM_MODEL = undefined;
74-
var MODEL_LABEL = '{{ app_label }}.{{ opts.model_name }}';
75-
(function($) {
76-
$.magnificPopup.instance._onFocusIn = function(e) {
77-
// Do nothing if target element is select2 input
78-
if( $(e.target).hasClass('select2-input') ) {
79-
return true;
72+
'use strict';
73+
{
74+
// using django's original jquery, initial formset
75+
const $ = django.jQuery;
76+
var FORM_MODEL = undefined;
77+
var MODEL_LABEL = '{{ app_label }}.{{ opts.model_name }}';
78+
$(function () {
79+
$.magnificPopup.instance._onFocusIn = function(e) {
80+
// Do nothing if target element is select2 input
81+
if( $(e.target).hasClass('select2-input') ) {
82+
return true;
83+
}
84+
// Else call parent method
85+
$.magnificPopup.proto._onFocusIn.call(this,e);
86+
};
87+
$('.ajax-popup-link').magnificPopup({
88+
type:'inline',
89+
});
90+
if ($(".errorlist", "#advanced_filters").length) {
91+
$('.ajax-popup-link').magnificPopup('open');
8092
}
81-
// Else call parent method
82-
$.magnificPopup.proto._onFocusIn.call(this,e);
83-
};
84-
$('.ajax-popup-link').magnificPopup({
85-
type:'inline',
93+
$("#advanced_filters_form a.close").on("click", function() {
94+
$.magnificPopup.close();
95+
})
8696
});
87-
if ($(".errorlist", "#advanced_filters").length) {
88-
$('.ajax-popup-link').magnificPopup('open');
89-
}
90-
})(jQuery);
97+
}
9198
</script>
9299

93100
{% include "admin/common_js_init.html" with formset=formset %}

advanced_filters/templates/admin/advanced_filters/change_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h1>{% trans "Change advanced filter" %}:</h1>
3131
</thead>
3232
<tbody>
3333
{% for form in formset %}
34-
<tr class="form-row {% cycle "row1" "row2" %} {% if forloop.last %}empty-form{% endif %}" id="{{ formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
34+
<tr class="form-row {% if forloop.last %}empty-form{% endif %}" id="{{ formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
3535
{% for field in form.visible_fields %}
3636
<td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
3737
{{ field }}

0 commit comments

Comments
 (0)