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

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

{% block title %}
  {% if object.pk %}
    Update External Link "{{ object.name }}"
  {% else %}
    Add External Link in {{ project.title }}
    {% if folder %}
      / {{ folder.name }}
    {% else %}
      / root
    {% endif %}
  {% endif %}
{% endblock title %}

{% block projectroles_extend %}

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

<div class="container-fluid sodar-page-container">
  <form method="post">
    {% csrf_token %}
    {{ form.name | as_crispy_field }}
    {{ form.url | as_crispy_field }}
    {{ form.folder | as_crispy_field }}
    {{ form.description | as_crispy_field }}
    {% include 'filesfolders/_flag_select.html' %}

    <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">
          <i class="iconify" data-icon="mdi:check-bold"></i>
          {% if object.pk %}
            Update
          {% else %}
            Add
          {% endif %}
        </button>
      </div>
    </div>
  </form>
</div>

{% endblock projectroles_extend %}
