-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JS elements regression in modal windows
In #2406 we removed some seemingly-duplicate network requests for `bs4_modal.js` every time a modal window is loaded. This would have been fine if that file didn't not include any side-effects, but it did: it re-applied 'global styling' every time the JS file is loaded. The goal here was to process 'styling' for any dynamica/interactive elements, such as map widgets, and fields that use 'select2' or 'x-editable'. When we removed these 'extra' JS calls, the modal windows stopped getting these interactive elements enabled/setup. This patch restores that functionality, while still retaining the goal of PR #2406: to prevent duplicate network requests for a file. We load `bs<x>_modal.js` on all pages that can display modals; this file now only sets up the event listener that is responsible for making sure a modal is cleared out/refreshed between multiple modal displays. The logic for applying styling to the window is now added inline to all of the relevant modal components. A further improvement on what we had before is that now, the call to add styling is scoped specifically to the modal. This prevents the issue described in #2351, where map elements may show up multiple times on the page because `applyGlobalStyles` is called multiple times.
- Loading branch information
1 parent
685e566
commit 36b3ef4
Showing
16 changed files
with
105 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
// fixes "remote modal shows same content every time" | ||
$('.modal').on('hidden', function() { | ||
$(this).removeData('modal'); | ||
}); | ||
|
||
$(function() { | ||
// Apply flask-admin form styles after the modal is loaded | ||
window.faForm.applyGlobalStyles(document); | ||
}); | ||
// fixes "remote modal shows same content every time" | ||
$('.modal').on('hidden', function() { | ||
$(this).removeData('modal'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
// fixes "remote modal shows same content every time", avoiding the flicker | ||
$('body').on('hidden.bs.modal', '.modal', function () { | ||
$(this).removeData('bs.modal').find(".modal-content").empty(); | ||
}); | ||
|
||
$(function() { | ||
// Apply flask-admin form styles after the modal is loaded | ||
window.faForm.applyGlobalStyles(document); | ||
}); | ||
// fixes "remote modal shows same content every time", avoiding the flicker | ||
$('body').on('hidden.bs.modal', '.modal', function () { | ||
$(this).removeData('bs.modal').find(".modal-content").empty(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 40 additions & 40 deletions
80
flask_admin/templates/bootstrap2/admin/model/modals/details.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
{% import 'admin/static.html' as admin_static with context%} | ||
{% import 'admin/lib.html' as lib with context %} | ||
|
||
{% block body %} | ||
{% block details_search %} | ||
<div class="row-fluid"> | ||
<div class="input-prepend fa_filter_container"> | ||
<span class="add-on">{{ _gettext('Filter') }}</span> | ||
<input id="fa_filter" id="prependedInput" type="text"> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block details_table %} | ||
<table class="table table-hover table-bordered searchable"> | ||
{% for c, name in details_columns %} | ||
<tr> | ||
<td> | ||
<b>{{ name }}</b> | ||
</td> | ||
<td> | ||
{{ get_value(model, c) }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endblock %} | ||
{% endblock %} | ||
|
||
{% block tail %} | ||
<script src="{{ admin_static.url(filename='admin/js/details_filter.js', v='1.0.0') }}"></script> | ||
<script src="{{ admin_static.url(filename='admin/js/bs2_modal.js', v='1.0.0') }}"></script> | ||
|
||
<script> | ||
// fill the header of modal dynamically | ||
$('.modal-header h3').html('{% block header_text -%} | ||
{{ _gettext('View Record') + ' #' + request.args.get('id') }} | ||
{%- endblock %}'); | ||
</script> | ||
{% endblock %} | ||
{% import 'admin/static.html' as admin_static with context%} | ||
{% import 'admin/lib.html' as lib with context %} | ||
|
||
{% block body %} | ||
{% block details_search %} | ||
<div class="row-fluid"> | ||
<div class="input-prepend fa_filter_container"> | ||
<span class="add-on">{{ _gettext('Filter') }}</span> | ||
<input id="fa_filter" id="prependedInput" type="text"> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block details_table %} | ||
<table class="table table-hover table-bordered searchable"> | ||
{% for c, name in details_columns %} | ||
<tr> | ||
<td> | ||
<b>{{ name }}</b> | ||
</td> | ||
<td> | ||
{{ get_value(model, c) }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endblock %} | ||
{% endblock %} | ||
|
||
{% block tail %} | ||
<script src="{{ admin_static.url(filename='admin/js/details_filter.js', v='1.0.0') }}"></script> | ||
<script>window.faForm.applyGlobalStyles(document.getElementsByClassName('modal'))</script> | ||
|
||
<script> | ||
// fill the header of modal dynamically | ||
$('.modal-header h3').html('{% block header_text -%} | ||
{{ _gettext('View Record') + ' #' + request.args.get('id') }} | ||
{%- endblock %}'); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 40 additions & 40 deletions
80
flask_admin/templates/bootstrap3/admin/model/modals/details.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
{% import 'admin/static.html' as admin_static with context%} | ||
{% import 'admin/lib.html' as lib with context %} | ||
|
||
{% block body %} | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | ||
{% block header_text %} | ||
<h3>{{ _gettext('View Record') + ' #' + request.args.get('id') }}</h3> | ||
{% endblock %} | ||
</div> | ||
|
||
<div class="modal-body"> | ||
{% block details_search %} | ||
<div class="input-group fa_filter_container col-lg-6"> | ||
<span class="input-group-addon">{{ _gettext('Filter') }}</span> | ||
<input id="fa_filter" type="text" class="form-control"> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block details_table %} | ||
<table class="table table-hover table-bordered searchable"> | ||
{% for c, name in details_columns %} | ||
<tr> | ||
<td> | ||
<b>{{ name }}</b> | ||
</td> | ||
<td> | ||
{{ get_value(model, c) }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endblock %} | ||
</div> | ||
{% endblock %} | ||
|
||
{% block tail %} | ||
<script src="{{ admin_static.url(filename='admin/js/details_filter.js', v='1.0.0') }}"></script> | ||
<script src="{{ admin_static.url(filename='admin/js/bs3_modal.js', v='1.0.0') }}"></script> | ||
{% endblock %} | ||
{% import 'admin/static.html' as admin_static with context%} | ||
{% import 'admin/lib.html' as lib with context %} | ||
|
||
{% block body %} | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | ||
{% block header_text %} | ||
<h3>{{ _gettext('View Record') + ' #' + request.args.get('id') }}</h3> | ||
{% endblock %} | ||
</div> | ||
|
||
<div class="modal-body"> | ||
{% block details_search %} | ||
<div class="input-group fa_filter_container col-lg-6"> | ||
<span class="input-group-addon">{{ _gettext('Filter') }}</span> | ||
<input id="fa_filter" type="text" class="form-control"> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block details_table %} | ||
<table class="table table-hover table-bordered searchable"> | ||
{% for c, name in details_columns %} | ||
<tr> | ||
<td> | ||
<b>{{ name }}</b> | ||
</td> | ||
<td> | ||
{{ get_value(model, c) }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endblock %} | ||
</div> | ||
{% endblock %} | ||
|
||
{% block tail %} | ||
<script src="{{ admin_static.url(filename='admin/js/details_filter.js', v='1.0.0') }}"></script> | ||
<script>window.faForm.applyGlobalStyles(document.getElementsByClassName('modal-content'));</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters