{% extends "newman/ajax_content_base.html" %}
{% load newman_modify cache %}

{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href="{% url newman:index %}#">{% trans "Home" %}</a>
    {# &rsaquo; <a class="js-hashadr" href="../../">{% trans app_label.title %}</a> #}
    &rsaquo;
    {% if has_change_permission %}
        <a class="js-hashadr" href="../">{{ opts.verbose_name_plural|capfirst }}: {% trans 'list' %}</a>
    {% else %}
        {{ opts.verbose_name_plural|capfirst }}: {% trans 'list' %}
    {% endif %}
    {% if title %}&rsaquo; <strong id="doc-title">{{ title }}</strong>{% endif %}
</div>
{% endblock %}

{% spaceless %}
{% block content_toolbar_left %}
        <a class="icn btn save" id="save-form">{% trans "Save as template" %}</a>
        {{ draft_form.drafts }}
{% endblock %}
{% block content_toolbar_right %}
            <a href="service-container::::help/" class="icn btn help js-simpleload">{% trans 'Help' %}</a>
            {% if change %}
                <a href="service-container::::history/" class="icn btn history js-simpleload">{% trans "History" %}</a>
                {% if has_absolute_url %}
                    <a href="{% url newman:index %}r/{{ content_type_id }}/{{ object_id }}/" class="icn btn web">{% trans "View on site" %}</a>
                {% endif%}
            {% endif %}
{% endblock %}
{% endspaceless %}

{% block content %}

<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ save_url }}" method="post" id="{{ opts.module_name }}_form" class="js-form change-form">{% block form_top %}{% endblock %}
{% csrf_token %}
<div>
    <div class="js-textarea-toolbar"></div>
{% if save_on_top %}{% submit_row %}{% endif %}
{% 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 %}

{% block fieldsets %}
{% for fieldset in adminform %}
  {% include "newman/includes/fieldset.html" %}
{% endfor %}

{% block after_field_sets %}{% endblock %}

{% for inline_admin_formset in inline_admin_formsets %}
    {% include inline_admin_formset.opts.template %}
{% endfor %}
{% endblock %}

{% block after_related_objects %}{% endblock %}

{% submit_row %}

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

</div>

<div class="js-form-metadata">
    <input type="hidden" name="success" id="save-change-form-success" />
    <script type="text/javascript">
        $('#save-change-form-success').data('callback', save_change_form_success);
    </script>
</div>

</form>
{% endblock %}

{% block content_js %}
    {{ block.super }}
    {# JavaScript for prepopulated fields #}
    {% prepopulated_fields_js %}

    {% cache 300 'nm-cf-js' adminform %}
    <script type="text/javascript">
    request_media(MEDIA_URL + 'jquery/jquery-urldecode-encode.js');
    {% for m in media %}
        request_media('{{ m }}');
    {% endfor %}
    function trigger_changelist_shown() {
        $(document).trigger('changeform_shown'); // bound in inlines.js
    }
    $(document).one('media_loaded', trigger_changelist_shown);
    </script>
    {% endcache %}
{% endblock %}
