{% extends "admin/base_site.html" %}
{% load admin_modify djblets_js djblets_utils i18n pipeline rbadmintags %}
{% load static %}


{% block global-vars %}
{{block.super}}
{%  definevar "form_id" spaceless global %}
{%   block form_id %}{{opts.model_name|default:"change"}}_form{% endblock %}
{%  enddefinevar %}
{% endblock global-vars %}


{% block page_class %}
{{block.super}}
{% if opts %}{{opts.app_label}}-{{opts.object_name.lower}}{% endif %}
{% endblock page_class %}

{% block page-sidebar-css-classes %}-is-connected{% endblock %}
{% block js-page-view-type %}RB.Admin.ChangeFormPageView{% endblock %}
{% block js-page-view-options %}{formID: {{form_id|json_dumps}}}{% endblock %}


{% block bodyclass %}{% if opts %}{{opts.app_label}}-{{opts.object_name.lower}}{% endif %} change-form -is-content-flush-on-mobile{% endblock %}

{% block css %}
{{block.super}}

{%  if adminform %}
{{media.css}}
{%  elif form %}
{%   for bundle_name in form.css_bundle_names %}
{%    stylesheet bundle_name %}
{%   endfor %}

{{form.media.css}}
{%  endif %}

<link rel="stylesheet" href="{% static 'admin/css/widgets.css' %}">
{% endblock css %}


{% block object-tools %}
{%  if change and not is_popup %}
{%   block object-tools-items %}{% endblock %}
{%  endif %}
{% endblock object-tools %}


{% block content %}

{%  block form_tag %}
<form class="rb-c-form -is-aligned"
      id="{{form_id}}"
      {% if has_file_field %}enctype="multipart/form-data"{% endif %}
      action="{{form_url|default:"."}}" method="POST">
{%  endblock form_tag %}
 {% csrf_token %}
{%  if is_popup %}
 <input type="hidden" name="_popup" value="1">
{%  endif %}

{%  block form-alerts %}
{%   if errors %}
 <div class="rb-c-alert -is-error">
  <div class="rb-c-alert__content">
   <h3 class="rb-c-alert__heading">{% spaceless %}
{%     blocktrans count counter=errors|length %}
    Please correct the error below.
{%     plural %}
    Please correct the errors below.
{%     endblocktrans %}
{%    endspaceless %}</h3>

{% if adminform %}
{{adminform.form.non_field_errors}}
{% elif form %}
{{form.non_field_errors}}
{% endif %}
  </div>
 </div>
{%   endif %}
{%  endblock form-alerts %}

 <div class="rb-c-page-content-box -is-content-flush">
{%  block form_content %}
{%   block form_top %}{% endblock %}

{%   block field_sets %}
{%    if adminform %}
{%     for fieldset in adminform|change_form_fieldsets %}
{%      render_change_form_fieldset fieldset %}
{%     endfor %}
{%    endif %}
{%   endblock field_sets %}

{%   block after_field_sets %}{% endblock %}

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

{%   block after_related_objects %}{% endblock %}
{%  endblock form_content %}

{% comment %}
 NOTE: Much of the block setup here is to satisfy compatibility with older
       versions of Review Board, with Django, and with Djblets' templates.
       Ideally, we'd replace Django's {% submit_row %} with something else,
       but that's a task for another day.
{% endcomment %}
{%  block submit_buttons_bottom %}
{%   block submit_row %}
  <div class="rb-c-form__actions">
{%    block submit_row_buttons %}
{%     change_form_submit_buttons %}
{%    endblock submit_row_buttons %}
  </div>
{%   endblock submit_row %}
{%  endblock submit_buttons_bottom %}
 </div>
</form>
{% endblock content %}


{% block scripts-post %}
{{block.super}}

<script>
django.jQuery = $;
</script>

{%  if adminform %}
{{media.js}}
{%  elif form %}
{%   for bundle_name in form.js_bundle_names %}
{%    javascript bundle_name %}
{%   endfor %}

{{form.media.js}}
{%  endif %}

{%  block admin_change_form_document_ready %}
<script id="django-admin-form-add-constants"
        src="{% static 'admin/js/change_form.js' %}"
        {% if adminform and add and opts %}data-model-name="{{opts.model_name}}"{% endif %}>
</script>
{%  endblock %}

{%  if opts %}
{%   prepopulated_fields_js %}
{%  endif %}
{% endblock scripts-post %}
