<!-- Handle modal code -->
<script type="text/javascript">
    // wrap boiler plate code for handling modal events
    function handle_modal_events(modalId, modalContentId,) {
        $('#' + modalId ).on('show.bs.modal', function (event) {
            $(this).find('.modal-body').load("{% url 'corphandouts:modal_loader_body' %}?is_night_mode={{NIGHT_MODE}}")
            let button = $(event.relatedTarget);
            let ajax_url = button.data('ajax_url');
            $('#' + modalContentId).load(ajax_url, function( response, status, xhr ) {
                if ( status == "error" ) {
                    let msg = `
                        <p class="text-danger">
                            Sorry but there was an error: ${xhr.status} ${xhr.statusText}
                        </p>`;
                    $(this).find('.modal-body').html(msg);
                }
            });
        });
    }
</script>
