{% load i18n %}
{% if perms.auth.run_db %}
<form class="form" role="form" method="post"
  onsubmit="return $('#loaddatafile').val() != ''"
  action="{{request.prefix}}/execute/launch/loaddata/">{% csrf_token %}
<table>
  <tr>
    <td style="padding:15px; vertical-align:top">
      <button  class="btn btn-primary" id="load" type="submit" value="{% trans "launch"|capfirst %}">
        {% trans "launch"|capfirst %}
      </button>
    </td>
    <td style="padding:15px">
      <div class="dropdown">
        <p>{% trans "Load one of the available datasets." %}</p>
        <button class="d-inline dropdown-toggle form-control" id="entity" type="button" data-bs-toggle="dropdown">
          <span>-</span>
        </button>
        <ul class="dropdown-menu col-12" aria-labelledby="entity" id="entityul">
          {% for i in fixtures %}<li><a class="dropdown-item">{{i}}</a></li>{% endfor %}
        </ul>
      </div>
    </td>
    <td style="padding:15px">
      <div class="mb-2">
        <input class="form-check-input" type="checkbox" id="loaddatacb2" onclick="checkbox_changed(this, '#emptyvar')" checked />
        <label for="loaddatacb2">{% trans "Purge all data before loading" %}</label>
      </div>
      <div>
        <input class="form-check-input" type="checkbox" id="loaddatacb1" onclick="checkbox_changed(this, '#regeneratevar')" checked />
        <label for="loaddatacb1">{% trans "Execute plan after loading" %}</label>
      </div>
    </td>
  </tr>
</table>
<input type="hidden" name="fixture" id="loaddatafile" value="">
<input type="hidden" name="regenerateplan" id="regeneratevar" value="true">
<input type="hidden" name="emptybefore" id="emptyvar" value="true">
</form>
<script>
$(function() {
  $("#entityul li a").click(function(){
    $("#entity span").text($(this).text());
    $("#loaddatafile").val($(this).text());
  });
});
function checkbox_changed(checkbox, slctr) {
  $(slctr).val(checkbox.checked);
};
</script>
{% else %}
  {% trans "Sorry, You don't have any execute permissions..." %}
{% endif %}
