{% extends "vault/base.html" %}

{% load storage_tags %}

{% block title %}Storage - {{ project_name }}{% endblock %}

{% block content_title %}Storage{% endblock %}

{% block content_breadcrumb %}
  <a href="{% url "containerview" project_name %}">Containers</a>
  <span>Add ACL to container {{ container }}</span>
{% endblock %}

{% block content %}
  {% include "addacl_modal.html" %}

  <div class="box">
    <table class="items-list table">
      <thead>
        <tr>
          <th></th>
          <th>Name</th>
          <th></th>
          <th>
            <div class="dropdown pull-right">
              <a class="dropdown-toggle btn btn-sm btn-danger" data-bs-toggle="dropdown"><i class="fa fa-cog icon-white"></i></a>
              <ul class="dropdown-menu">
                <li>
                  {% if not public %}
                  <form method="POST" action="{% url "edit_acl" project=project_name container=container %}" id="mkpublic">
                    {% csrf_token %}
                    <input name="username" type="hidden" value=".r:*">
                    <input name="read" type="hidden" value="On">
                  </form>
                  <a href="#" onclick="mkpublic.submit()"><i class="fa fa-eye"></i> Make public</a>
                  {% else %}
                  <a href="{% url "edit_acl" project=project_name container=container %}?delete=.r:*,.rlistings"><i class="fa fa-eye-slash"></i> Make private</a>
                  {% endif %}
                </li>
                <li class="divider" />
                <li><a href="#addacl_modal" data-bs-target="#addacl_modal" data-bs-toggle="modal"><i class="fa fa-user"></i> Add ACL</a></li>
              </ul>
            </div>
          </th>
        </tr>
    </thead>

    <tbody>
    {% for user, permission in acls.items %}
      <tr>
        <td><i class="fa fa-user"></i></td>
        <td>
          {% if user == ".rlistings" %}
            {{user}} <a href="#" data-bs-toggle="tooltip" title="This entry allows the listing of objects and is required for public readable containers."><i class="fa fa-question"></i></a>
          {% elif user == ".r:*" %}
            {{user}} <a href="#" data-bs-toggle="tooltip" title="This entry allows the download of objects and is required for public readable containers."><i class="fa fa-question"></i></a>
          {% else %}
            {{user}}
          {% endif %}
        </td>
        <td style="text-align:right;">
          {% if permission.read %}
          <a class="btn btn-sm btn-success">Read</a>
          {% endif %}

          {% if permission.write %}
          <a class="btn btn-sm btn-danger">Write</a>
          {% endif %}
        </td>
        <td>
          <a class="btn btn-sm btn-danger" href="{% url "edit_acl" project=project_name container=container%}?delete={{ user }}"><i class="fas fa-trash icon-white"></i></a>
        </td>
      </tr>
    {% empty %}
      <tr>
        <td colspan="5">
          <strong><center>There are no ACLs for this container yet. Add a new ACL by clicking the red button.<center></strong>
        </td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
</div>
{% endblock %}

{% block jsadd %}
<script type="text/javascript">
  $(document).ready(function () {
    $("a").tooltip({
      'selector': '',
      'placement': 'bottom'
    });
  });
</script>
{% endblock %}
