{% extends "passerelle/manage/resource_child_form.html" %}
{% load i18n gadjo %}

{% block form %}
  {{ block.super }}
  <h3>{% trans "Computed properties" %}</h3>
  {{ formset.management_form }}
  <table id="computed-property-forms">
    <thead>
      <tr>
        {% for field in formset.0 %}
          <th class="column-{{ field.name }}{% if field.required %} required{% endif %}">{{ field.label }}</th>
        {% endfor %}
      </tr>
    </thead>
    <tbody>
      {% for sub_form in formset %}
        <tr class='computed-property-form'>
          {% for field in sub_form %}
            <td class="field-{{ field.name }}">
              {{ field.errors.as_ul }}
              {{ field }}
            </td>
          {% endfor %}
        </tr>
      {% endfor %}
    </tbody>
  </table>
  <button id="add-computed-property-form" type="button">{% trans "Add another computed property" %}</button>
  {% if object.pk %}
    <script
      id="indexing-template-script"
      data-url="{% url 'opengis-query-test-indexing-template' slug=object.resource.slug pk=object.pk %}"
    >
      $('button#test-indexing-template').click(function (e) {
        $('div.template-result').show();
        $.ajax({
          url : $('#indexing-template-script').data('url'),
          data: {'template': $('#id_indexing_template').val()},
          type: 'GET',
          success: function(data) {
            $('span.template-result').html(data['data'].join(', '));
          }
        });
      });
    </script>
  {% endif %}
{% endblock %}
