{% extends 'projectroles/project_base.html' %}

{% load rules %}
{% load static %}
{% load crispy_forms_filters %}

{% block title %}
  {% if object.pk %}
    Update File
  {% else %}
    Upload File in {{ project.title }}
    {% if folder %}
      ({{ folder.name }})
    {% else %}
      (root)
    {% endif %}
  {% endif %}
{% endblock title %}

{% block css %}
  {{ block.super }}
  {# Workaround for django-db-file-storage Bootstrap4 issue (#164) #}
  <style type="text/css">
    div#div_id_file div p.invalid-feedback {
      display: block;
    }
  </style>
{% endblock css %}

{% block projectroles_extend %}

<div class="container-fluid sodar-subtitle-container">
  {% if object.pk %}
    <h3>Update File</h3>
  {% else %}
    <h3>
      Upload File in
      {% if folder %}
        {{ folder.name }}
      {% else %}
        root
      {% endif %}
    </h3>
  {% endif %}
</div>

<div class="container-fluid sodar-page-container">
  <form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    {{ form.file | as_crispy_field }}
    {{ form.unpack_archive | as_crispy_field }}
    {{ form.folder | as_crispy_field }}
    {{ form.description | as_crispy_field }}
    {% include 'filesfolders/_flag_select.html' %}
    {{ form.public_url | as_crispy_field }}

    <div class="row">
      <div class="btn-group ml-auto">
        <a role="button" class="btn btn-secondary"
          {% if object.pk %}
            {% if object.folder %}
              href="{% url 'filesfolders:list' folder=object.folder.sodar_uuid %}"
            {% else %}
              href="{% url 'filesfolders:list' project=object.project.sodar_uuid %}"
            {% endif %}
          {% else %}
            {% if folder %}
              href="{% url 'filesfolders:list' folder=folder.sodar_uuid %}"
            {% else %}
              href="{% url 'filesfolders:list' project=project.sodar_uuid %}"
            {% endif %}
          {% endif %}
          >
          <i class="iconify" data-icon="mdi:arrow-left-circle"></i> Cancel
        </a>
        <button type="submit" class="btn btn-primary sodar-btn-submit-once">
          {% if object.pk %}
            <i class="iconify" data-icon="mdi:lead-pencil"></i> Update
          {% else %}
            <i class="iconify" data-icon="mdi:upload"></i> Upload
          {% endif %}
         </button>
      </div>
    </div>
  </form>
</div>

{% endblock projectroles_extend %}

{% block javascript %}
  {{ block.super }}
  <!-- Filesfolders Javascript -->
  <script type="text/javascript" src="{% static 'filesfolders/js/filesfolders.js' %}"></script>
{% endblock javascript %}
