{% spaceless %}
<div class="inline-group" style="margin: 5px 10px">
    {{ inline_admin_formset.formset.management_form }}

    <fieldset class="gallery-items-sortable">
        <legend style="font-size: 120%; font-weight: bold;">{{ inline_admin_formset.opts.verbose_name_plural|title }}</legend>
    {{ inline_admin_formset.formset.non_form_errors }}

    {% for inline_admin_form in inline_admin_formset %}
        <div class="inline-related {% if forloop.last %}last-related{% endif %}">
            {% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %}
            <label for="id_{{ inline_admin_form.form.prefix }}-__all__" class="noscreen">
                {{ inline_admin_formset.opts.verbose_name_plural|capfirst }}
            </label>
            <span id="id_{{ inline_admin_form.form.prefix }}-__all__" class="noscreen"></span>

            {% for fieldset in inline_admin_form %}
                <div class="gallery-item">
                <img class="thumb" src="{{ inline_admin_form.original.target.thumb_url }}" alt="{{ inline_admin_form.original.target }}"/>
                {% if inline_admin_form.original %}
                    <h4>
                        {% comment %}
                        #<span>{{ inline_admin_form.original.order }}</span> &mdash;
                        {% endcomment %}
                        <span></span> {# JS gallery inline compatibility glue #}
                        <span>{{ inline_admin_form.original.target }}</span>
                        {% if inline_admin_form.show_url %}
                            &nbsp;<a class="icn web" href="{% url newman:obj-redirect inline_admin_form.original_content_type_id inline_admin_form.original.id %}">{% trans "View on site" %}</a>
                        {% endif %}
                    </h4>
                {% endif %}
                {% for line in fieldset %}
                    {{ line.errors }}
                    {% for field in line %}
                            {{ field.field }}
                    {% endfor %}
                {% endfor %}
                {% if inline_admin_formset.formset.can_delete and inline_admin_form.original %}
                    <div class="delete">
                        {{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}
                    </div>
                {% else %}
                    {% if inline_admin_formset.formset.can_delete %}
                    <div class="delete-item noscreen">{# Fake delete button if item is in unsaved state #}
                        <input type="checkbox" 
                        id="id_{{ inline_admin_form.form.prefix }}-DELETE" 
                        name="{{ inline_admin_form.form.prefix }}-DELETE" />
                        <label 
                            for="id_{{ inline_admin_form.form.prefix }}-DELETE" 
                            class="vCheckboxLabel inline">{% trans "Delete" %}
                        </label>
                    </div>
                    {% endif %}
                {% endif %}

                    <div class="cb"></div>
                </div>
            {% endfor %}
            {{ inline_admin_form.pk_field.field }}
            {{ inline_admin_form.fk_field.field }}
        </div>
    {% endfor %}

        <div class="gallery-add-item">
            <a class="icn btn add add-gallery-item-button">{% trans "Add" %}</a>
            <br />
            <a class="icn btn add js-adrstack-push js-custom-adrstack-callbacks js-multi-upload js-hashadr" href="/photos/photo/mass-upload2/">{% trans "Mass upload" %}</a>
        </div>
    </fieldset>

</div>
<script type="text/javascript">
    request_media('{{ NEWMAN_MEDIA_URL }}jquery/jquery-ui.js');
    request_media('{{ NEWMAN_MEDIA_URL }}js/mass-upload.js');
</script>
{% endspaceless %}
