{% extends "base.html" %}
{% load i18n auth_tags bootstrap %}

{% block body_class %}ct {{ object.ct_name }} edit{% endblock %}

{% block container %}

{% block header %}

<header>
  <h1>
    {% if object and not.object.is_tmp %}
    {% trans "Edit" %} {{ view.ct_label|lower }}
    {% else %}
    {% trans "New" %} {{ view.ct_label|lower }}
    {% endif %}
  </h1>
</header>

{% endblock %}

{% block errors %}
  
{% if form.errors %}
<div class="alert alert-error">
  <strong>{% trans "Please correct the following errors" %}</strong>
  <ul class="basic-list">    
    {% for field in form %}
    {% if field.errors %}
    <li><strong>{{ field.label }}</strong>: {{ field.errors }}</li>
    {% endif %}
    {% endfor %}    
  </ul>
</div>
{% endif %}

{% endblock %}

{% block form %}
<form action="" method="POST" id="editform">
  {% csrf_token %}

  {% block formfields %}
  {{ form|bootstrap }}
  {% endblock %}

  {% block formcontrols %}
  <div class="btn-group form-actions">
    <button class="btn btn-primary protected save-action" type="submit" 
            value="save" name="action">
      {% trans "Save" %}
    </button>
    <button class="btn protected cancel-action" type="submit" 
            value="cancel" name="action">
      {% trans "Cancel" %}
    </button>
    {% if object %}
    {% ifpermission object request.user contenttypes.delete_contenttype %}
    <a class="btn btn-danger delete-action"
       data-toggle="modal"
       href="{{ view.delete_url }}"
       data-target="#MyModal">
      {% block delete_label %}
      {% with object_name=view.ct_label %}
      {% blocktrans %}Delete this {{ object_name }}{% endblocktrans %}
      {% endwith %}
      {% endblock %}
    </a>
    {% endifpermission %}
    {% endif %}
  </div>
  {% endblock %}

</form>
{% endblock %}

{% endblock %}
