{% extends "admin/settings.html" %}

{% block subnavbar %}{% endblock %}

{% block form_content %}
{{block.super}}

<div id="search-backend-forms">
{%  for search_backend_id, subform in form.search_backend_forms.items %}
<fieldset class="module aligned" data-search-backend-id="{{search_backend_id}}" style="display: none">
{%   for field in subform %}
{%    include "siteconfig/settings_field.html" %}
{%   endfor %}
</fieldset>
{%  endfor %}
</div>
{% endblock form_content %}

{% block scripts-post %}
{{block.super}}
<script>
    function updateSearchFormDisplay() {
        var searchEnabled = $('#id_search_enable').prop('checked'),
            searchBackend = $('#id_search_backend_id').find(':selected').val();

        $('#search-backend-forms').find('fieldset').hide();
        $('#row-search_results_per_page, #row-search_backend_id, ' +
          '#row-search_on_the_fly_indexing, ' +
          '[data-search-backend-id="' + searchBackend + '"]')
             .toggle(searchEnabled);
    }

    $(document).ready(function() {
        $('#id_search_enable, #id_search_backend_id')
            .change(updateSearchFormDisplay);

        updateSearchFormDisplay();
    });
</script>
{% endblock scripts-post %}
