{% extends 'base.html' %}
{% load helpers %}
{% load form_helpers %}
{% load render_table from django_tables2 %}

{% block content %}
    <h1>{% block title %}Editing {{ objs_count }} {{ obj_type_plural|bettertitle }}{% endblock %}</h1>
    {% if form.errors %}
        <div class="panel panel-danger">
            <div class="panel-heading"><strong>Errors</strong></div>
            <div class="panel-body">
                {{ form.non_field_errors }}
                {% for field in form %}
                    {% if field.errors %}
                        <strong class="panel-title">{{ field.label }}</strong>: {{ field.errors }}
                    {% endif %}
                {% endfor %}
            </div>
        </div>
    {% endif %}
    <form action="" method="post" class="form form-horizontal">
        {% csrf_token %}
        {% if request.POST.return_url %}
            <input type="hidden" name="return_url" value="{{ request.POST.return_url }}" />
        {% endif %}
        {% for field in form.hidden_fields %}
            {{ field }}
        {% endfor %}
        <div class="row">
            {% if table %}
                <div class="col-md-8">
                    <div class="panel panel-default">
                        <div class="table-responsive">
                            {% render_table table 'inc/table.html' %}
                        </div>
                    </div>
                </div>
            {% endif %}
            <div class="{% if table %} col-md-4 {% else %} col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 {% endif %}">
                <div class="panel panel-default">
                    <div class="panel-heading"><strong>{% block form_title %}Attributes{% endblock %}</strong></div>
                    <div class="panel-body">
                        {% block form_fields %}
                            {% for field in form.visible_fields %}
                                {% if field.name in form.nullable_fields %}
                                    {% render_field field bulk_nullable=True %}
                                {% elif field.name == "object_note" %}
                                    {% if perms.extras.add_note %}
                                        {% render_field field %}
                                    {% endif %}
                                {% else%}
                                    {% render_field field %}
                                {% endif %}
                            {% endfor %}
                        {% endblock %}
                    </div>
                </div>
                <div class="form-group text-right">
                    <div class="col-md-12">
                        <button type="submit" name="_apply" class="btn btn-primary">Apply</button>
                        <a href="{{ return_url }}" class="btn btn-default">Cancel</a>
                    </div>
                </div>
            </div>
        </div>
    </form>
{% endblock %}
