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

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

{% block container %}

{% block header %}
<header>
  <h1>
    {% block title %}
    {% with ct_label=view.ct_label %}
    {% if object and not object.is_tmp %}
    {% blocktrans %}Edit {{ ct_label }}{% endblocktrans %}
    {% else %}
    {% blocktrans %}Add {{ ct_label }}{% endblocktrans %}
    {% endif %}
    {% endwith %}
    {% endblock title %}
  </h1>
</header>
{% block metainfo %}
{% endblock metainfo %}
{% endblock header %}

{% block form_preamble %}
{% endblock %}

{% block form %}

<form action="" method="POST" 
      id="editform" class="protected {% block form_class %}{% endblock %}">

  {{ form.media }}
  {% csrf_token %}

  {% if object and object.is_tmp %}
  <input type="hidden" name="tmp_id" value="{{ object.pk }}" />
  {% endif %}

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

  {% block help %}
  {% if form.help %}
  <div class="general-help alert alert-info">
  {{ form.help|safe }}
  </div>
  {% endif %}
  {% endblock help %}

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

  {% block extra_formfields %}{% endblock %}

  {% block formcontrols %}
  <div class="btn-group form-actions">

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

{% endblock container %}
