{% extends "admin/base_site.html" %}
{% load i18n admin_urls admin_static admin_modify material_form material_admin %}

{% block extrahead %}
{{ block.super }}
{{ media.css }}
{% endblock %}


{% block brand-logo %}{{ title }}{% endblock %}

{% block breadcrumbs_items %}
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
<a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
<a class="active" href="{% url opts|admin_urlname:'changelist' %}">{% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}{% trans 'Change' %}{% endif %}</a>
{% endblock %}


{% block content %}
<div class="left-panel change-form">
    <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">
        {% csrf_token %}
        {% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1" />{% endif %}
        {% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}" />{% endif %}
        <div class="card">
            <div class="card-content">
                <span class="card-title">{% if add %}{% trans 'New' %} {{ opts.verbose_name }}{% else %}{{ adminform.form.instance|title }}{% endif %}</span>
                {% if errors %}
                <div class="row">
                    <div class="col s12">
                        <small class="errornote">
                            {% if errors|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
                            <br/><br/>
                        </small>
                    </div>
                </div>
                {% endif %}
                
                {% block change_form %}
                {% fieldset_layout adminform inline_admin_formsets as layout %}
                {% form form=adminform.form layout=layout %}{% endform %}
                {% prepopulated_fields_js %}
                {% endblock %}
                {% block after_related_objects %}{% endblock %}
            </div>
            <div class="card-action">
                {% submit_row %}
            </div>
        </div>
    </form>
</div>
<div class="right-panel">
    {% if not is_popup and change %}
    <div class="z-depth-1">
        {% block object-tools %}
        <ul class="object-tools collection with-header">
            <li class="collection-header"><h5>{% trans "Tools" %}</h5></li>
            {% block object-tools-items %}
            <li class="collection-item">
                {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
                <a href="{% add_preserved_filters history_url %}" class="historylink"><i class="left material-icons">history</i> {% trans "History" %}</a>
            </li>
            {% if has_absolute_url %}
            <li class="collection-item">
                <a href="{{ absolute_url }}" class="viewsitelink"><i class="left material-icons">open_in_new</i> {% trans "View on site" %}</a>
            </li>
            {% endif %}
            {% endblock %}
            <li class="collection-item">&nbsp;</li>
        </ul>
        {% endblock %}
        <div style="clear:both"></div>
    </div>
    {% endif %}
</div>

{% if adminform and add %}
<script type="text/javascript">
  $('form#{{ opts.model_name }}_form :input:visible:enabled:first').attr('autofocus', true);
  $('form#{{ opts.model_name }}_form :input:visible:enabled:first').focus();
</script>
{% endif %}
{% endblock %}
