{#{% extends adminform.model_admin.original_change_form_template %}#}
{% extends "admin/change_form.html" %}
{% load i18n static admin_list admin_urls %}
{% block extrastyle %}{{ block.super }}
{% include "admin_extra_urls/includes/styles.html" %}{% endblock %}

{% block object-tools-items %}
    {{ block.super }}
    {% include "admin_extra_urls/includes/change_form_buttons.html" %}
{% endblock %}
{% block admin_change_form_document_ready %}{{ block.super }}
    <script>
        (function ($) {
            $('.btn.disable-on-click').click(function (e) {
                if ($(this).hasClass("disabled")) {
                    e.preventDefault();
                } else {
                    $(this).removeClass('btn-success').addClass('disabled');
                }
            });

            window.AdminExtraUrl = {
                update: function () {
                    var changes = $mainForm.serialize()
                    if (changes !== $mainForm.data('serialized')) {
                        $('.object-tools').find('a.auto-disable').addClass('disabled');
                    } else {
                        $('.object-tools').find('a.auto-disable').removeClass('disabled');
                    }
                }
            }
            var $mainForm = $('#{{ opts.model_name }}_form');
            $mainForm.data('serialized', $mainForm.serialize());
            $mainForm.on('change input', AdminExtraUrl.update);
        })(django.jQuery)
    </script>
{% endblock %}
