{% extends "smartmin/base.html" %}

{% load smartmin %}

{% block content %}
{% block pjax %}
<div class="row" id="pjax">
  {% block modal %}
  <div id="modal">
  <div class="{% block form-span %}span12{% endblock %}">

  {% block pre-form %}{% endblock %}

  {% if show_form %}
  <form class="smartmin-form" method="post" enctype="multipart/form-data" {% if action_url  %}action="{{ action_url }}"{% endif %}>
    {% block pre-form-errors %}
    {% endblock pre-form-errors %}

    {% if form.non_field_errors %}
    <div class="alert alert-error form-errors">
      {{ form.non_field_errors }}
    </div>
    {% endif %}

    {% block post-form-errors %}
    {% endblock post-form-errors %}

    {% block pre-fields %}
    {% endblock %}

    {% block form-help %}{% endblock form-help %}

    {% block fields %}
    <fieldset>
    {% for field in fields %}
    {% render_field field %}
    {% endfor %}

    {% block extra-fields %}
    {% endblock %}
    </fieldset>
    {% endblock fields %}

    {% block post-fields %}
    {% endblock post-fields %}

    {% csrf_token %}

    {% block form-buttons %}
    <div class="form-actions">
      <input type="submit" class="btn btn-primary" value="{{ submit_button_name }}">
    </div>
    {% endblock %}
  </form>
  {% endif %}

  {% block post-form %}{% endblock post-form %}
  </div>

  {% block form-right %}
  {% endblock %}
  </div>
  {% endblock modal %}
</div>
{% endblock pjax %}
{% endblock content %}

{% block extra-script %}

{{ block.super }}
{% if javascript_submit %}
<script>
  // attach a submit handler to the form
  $("#smartmin_form").submit(function(event) {

  // stop form from submitting normally
  event.preventDefault();
  event.stopPropagation();

  // get some values from elements on the page:
  var form = $(this);
  var data = form.serialize();
  {{ javascript_submit }}(form, data);
  });
</script>
{% endif %}
{% endblock %}
