{% extends "admin/change_list.html" %}

{% block extrahead %}
    <script>
        window.addEventListener("load", function () {
            var $ = django.jQuery;

            var initialData = "";
            var isSubmitting = false;

            $('form').not("#changelist-search").submit(function (event) {
                isSubmitting = true;
                console.log("Form submitted...");
            })

            initialData = $('form').not("#changelist-search").serialize();

            $(window).on('beforeunload', function () {
                console.log("[Beforeunload] - Event triggered!");
                var formChanged = $('form').not("#changelist-search").serialize() != initialData;
                console.log("[Beforeunload] - Form changed:", formChanged);
                if (!isSubmitting && formChanged) {
                    console.log("[Beforeunload] - Unload prevented!");
                    swal.close();
                    return 'Du hast ungesicherte Änderungen vorgenommen. Wenn du die Seite verlässt, werden diese gelöscht.'
                }
            });
        });

        function blur() {
            var $ = django.jQuery;

            $(".results td").css({"color": "transparent", "text-shadow": "0 0 6.5px rgba(0,0,0,0.55)"})
        }
    </script>
    {{ block.super }}
{% endblock %}