{% extends "admin/base_site.html" %}
{% load i18n admin_urls admin_static admin_modify bootstrapped_goodies_tags %}

{% block extrahead %}{{ block.super }}
{% url 'admin:jsi18n' as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
<script type="text/javascript">
window.setTimeout(function() { $(".alert-success").fadeOut('slow'); }, 2000);
window.setTimeout(function() { $(".alert-info").fadeOut('slow'); }, 4000);
</script>
{{ media }}
{% endblock %}

{% block messages %}
	{% if messages %}
        <div class="row">
            <div class="col-sm-12">
                {% for message in messages %}
                <div class="alert {{ message.tags|default:"alert-info" }}">
                    {{ message|capfirst|safe }}
                </div>
                {% endfor %}
            </div>
        </div>
    {% endif %}
{% endblock messages %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %}

{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}

{% block bodyclass %}{{ block.super }} {{ opts.app_label }}-{{ opts.object_model }} change-form{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
	<li><a href="{% url 'admin:index' %}">{% trans 'Home' %}</a></li>
	<li><a href="{% url 'admin:app_list' app_label=opts.app_label %}">{% with app_label=opts.app_config.verbose_name|default:opts.app_label %}{{ app_label|title }}{% endwith %}</a></li>
	<li>{% if has_change_permission %}<a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}</li>
	<li>{% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}</li>
</ul>
<div id="topbar_left">
	{% if change %}
		{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
		 <a href="{% add_preserved_filters history_url %}" class="historylink"><i class="fa fa-lg fa-history"></i></a>
		{% if has_absolute_url %}<a href="{% url 'admin:view_on_site' content_type_id original.pk %}" class="viewsitelink">
			<i class="fa fa-lg fa-eye" style="padding-left:0.5em"></i>
		</a>{% endif %}
	{% endif %}
</div>
{% endblock %}

{% block navbar %}{% endblock %}

{% block content %}

{% with module_name=opts.model_name|lower|slugify %}
    {% render_with_template_if_exist opts.app_label|lower|add:"/admin_model_"|add:module_name|add:"_change_form.html" "" %}
{% endwith %}


<form class="form-horizontal" {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %}
    {% if errors %}
    <div class="alert alert-danger">
        {% 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 %}

    {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}

    <div id="content-main">
        <div>
        {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}

        {% block field_sets %}
        {% for fieldset in adminform %}
          {% include "admin/includes/fieldset.html" with group_column_width=adminform|form_fieldset_column_width %}
        {% endfor %}
        {% endblock %}

        {% block after_field_sets %}{% endblock %}

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

        {% block after_related_objects %}{% endblock %}

        {% block admin_change_form_document_ready %}

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

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

        </div>
    </div>

    <div class="form-actions">
        {% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
    </div>
</form>
{% endblock %}
