{% extends "admin/polymorphic_tree/change_form.html" %}
{% load i18n suit_tags admin_urls admin_modify admin_static fluent_pages_admin_tags %}

{% block suit_jquery %}{% if '1.9'|django_version_gte %}<script src="{% static 'suit/js/jquery-2.2.4.min.js' %}">{% else %}<script src="{% static 'suit/js/jquery-1.12.4.min.js' %}">{% endif %}</script>{% endblock %}
  
{% block content %}<div id="content-main" class="inner-two-columns">
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts|get_meta_model_name }}_form" class="form-horizontal">
    <div class="inner-right-column">
        <div class="box save-box">
            <input type="hidden" name="_action" />
            {% block submit_buttons_bottom %}
            {% if add %}
            {% submit_row %}
            {% else %}
            {% include "admin/fluent_pages/page/submit_line.html" %}
            {% endif %}
            {% endblock %}
        </div>
        {% block object-tools %}
{% if change %}{% if not is_popup %}
  <h4 class="italic-title">{% trans 'tools'|capfirst %}</h4>
  <ul class="box menu-box">
    {% block object-tools-items %}
    <li>
        {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
        <a href="{% add_preserved_filters history_url %}" class="historylink"><i class="icon-time icon-alpha75"></i>{% trans "History" %}</a>
    </li>
    {% if original.url %}<li><a href="{{ original.url }}" class="viewsitelink"><i class="icon-eye-open icon-alpha75"></i>{% trans "View on site" %}</a></li>{% endif %}
    {% if has_add_permission %}
    <li>
        <a href="../add/?ct_id={{ content_type_id }}"><i class="icon-plus-sign icon-alpha75"></i>{% blocktrans with opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
        </a></li>
        {% endif %}
        {% endblock %}
  </ul>
{% endif %}{% endif %}
        {% endblock %}

  {% block sidebar %}{% endblock %}
    </div>
    <div class="inner-center-column">
        {% csrf_token %}{% block form_top %}{% endblock %}
        {% block suit_form_tabs %}
        {% if adminform.model_admin.suit_form_tabs %}
        <ul id="suit_form_tabs" class="nav nav-tabs nav-tabs-suit" data-tab-prefix="suit-tab">
            {% for tab in adminform.model_admin.suit_form_tabs %}
            <li><a href="#{{ tab.0 }}">{{ tab.1 }}</a></li>{% endfor %}
        </ul>
        {% endif %}
        {% if language_tabs %}{% include "admin/parler/language_tabs.html" %}{% endif %}
        {% endblock %}
                <div class="tab-content tab-content-main">
{% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1" />{% endif %}
{% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}" />{% endif %}
{% if errors %}
            <div class="alert alert-error">
    {% if errors|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
    {{ adminform.form.non_field_errors }}
            </div>
{% endif %}

{# render suit_form_includes at top position #}
{% include 'suit/includes/change_form_includes.html' with position='top' %}

{% block field_sets %}
{# first fieldset #}
{% for fieldset in adminform %}
  {% if forloop.first %}{% include "admin/includes/fieldset.html" %}{% endif %}
{% endfor %}

{% block after_first_fieldset %}{% endblock %}

{# all remaining fieldsets #}
{% for fieldset in adminform %}
  {% if not forloop.first %}{% include "admin/includes/fieldset.html" %}{% endif %}
{% endfor %}
{% endblock %}

{% block after_field_sets %}{% endblock %}

          {# render suit_form_includes at middle position #}
          {% include 'suit/includes/change_form_includes.html' with position='middle' %}

{% block inline_field_sets %}
{% for inline_admin_formset in inline_admin_formsets %}
    {% include inline_admin_formset.opts.template %}
{% endfor %}
{% endblock %}

</div>

{% block after_related_objects %}{% endblock %}

{# render suit_form_includes at last position #}
{% include 'suit/includes/change_form_includes.html' with position='bottom' %}

{% block admin_change_form_document_ready %}
    <script type="text/javascript">
        (function($) {
            $(document).ready(function() {
                $(document).on('click', '.add-another', function(e) {
                    e.preventDefault();
                    showAddAnotherPopup(this);
                });
                $(document).on('click', '.related-lookup', function(e) {
                    e.preventDefault();
                    showRelatedObjectLookupPopup(this);
                });
            {% if adminform and add %}
                $('form#{{ opts|get_meta_model_name }}_form :input:visible:enabled:first').focus()
            {% endif %}
            });
        })(django.jQuery);
    </script>
{% endblock %}

{# JavaScript for prepopulated fields #}
{% prepopulated_fields_js %}

</div>
</form></div>
{% endblock %}
