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

<!-- LOADING -->
{% load i18n admin_urls admin_static admin_modify %}

<!-- JAVASCRIPTS -->
{% block javascripts %}
    {{ block.super }}
    {% url "admin:jsi18n" as jsi18nurl %}
    <script src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
    {{ media }}
    {% if inline_admin_formsets %}
    <script src="{% static "wladmin/js/admin/Inline.js" %}"></script>
    <script src="{% static "wladmin/js/admin/CollapsedInlineFieldsets.js" %}"></script>
    {% endif %}
{% endblock %}

<!-- COLTYPE/BODYCLASS -->
{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}

<!-- BREADCRUMBS -->
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
    {% url "admin:index" as admin_index_url %}
    <a href="{{ admin_index_url }}">{% trans "Home" %}</a> &rsaquo;
    <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
    {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
    {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div>
{% endif %}{% endblock %}

<!-- CONTENT -->
{% block content %}
<div id="content-main">

    <!-- Object-Tools -->
    {% block object-tools %}
    {% if change %}
    {% if not is_popup %}
    <ul class="object-tools">
        {% block object-tools-items %}
            {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
            <li><a href="{{ history_url }}">{% trans "History" %}</a></li>
            {% if has_absolute_url %}<li><a href="{{ absolute_url }}" class="focus" target="_blank">{% trans "View on site" %}</a></li>{% endif%}
        {% endblock %}
    </ul>
    {% endif %}
    {% endif %}
    {% endblock %}

    <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
        <div>
            <!-- Popup Hidden Field -->
            {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}

            <!-- Submit-Row -->
            {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}

            <!-- Related-objects js that was brought in with Django 1.8 (merge from wladmin) -->
            {% block admin_change_form_document_ready %}
            <script type="text/javascript">
                (function($) {
                    $(document).ready(function() {
                        $('.add-another').click(function(e) {
                            e.preventDefault();
                            showAddAnotherPopup(this);
                        });
                        $('.related-lookup').click(function(e) {
                            e.preventDefault();
                            showRelatedObjectLookupPopup(this);
                        });
                    {% if adminform and add %}
                        $('form#{{ opts.model_name }}_form :input:visible:enabled:first').focus()
                    {% endif %}
                    });
                })(django.jQuery);
            </script>
            {% endblock %}

            <!-- Errors -->
            {% if errors %}
            <p class="errornote">
                {% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
            </p>
            <ul class="errorlist">{% for error in adminform.form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
            {% endif %}

            <!-- Fieldsets -->
            {% block field_sets %}
            {% for fieldset in adminform %}
            {% include "admin/includes/fieldset.html" %}
            {% endfor %}
            {% endblock %}

            {% block after_field_sets %}{% endblock %}

            <!-- Inlines -->
            {% block inline_field_sets %}
            {% for inline_admin_formset in inline_admin_formsets %}
            {% include inline_admin_formset.opts.template %}
            {% endfor %}
            {% endblock %}

            {% block after_related_objects %}{% endblock %}

            <!-- Submit-Row -->
            {% block submit_buttons_bottom %}{% submit_row %}{% endblock %}

            {% if add %}
            <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
            {% endif %}

            <!-- JS for prepopulated fields -->
            {% prepopulated_fields_js %}

        </div>
    </form>
</div>
{% endblock %}
