{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}

{% block title-page %}{% trans "Edit lease" %}{% endblock %}

{% block content %}
<div class="row">
  <div class="col-md-6">
    <div class="panel panel-default">
      <div class="panel-heading">
        <a class="pull-right btn btn-default btn-xs" href="{% url "dashboard.views.template-list" %}">{% trans "Back" %}</a>
        <h3 class="no-margin"><i class="fa fa-clock-o"></i> {% trans "Edit lease" %}</h3>
      </div>
      <div class="panel-body">
        {% with form=form %}
          {% include "display-form-errors.html" %}
        {% endwith %}
        {% crispy form %}
      </div>
    </div>
  </div>

  <div class="col-md-6">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="no-margin"><i class="icon-group"></i> {% trans "Manage access" %}</h4>
      </div>
      <div class="panel-body">
        <form action="{% url "dashboard.views.lease-acl" pk=object.pk %}" method="post">{% csrf_token %}
          <table class="table table-striped table-with-form-fields" id="template-access-table">
            <thead>
              <tr>
                <th></th>
                <th>{% trans "Who" %}</th>
                <th>{% trans "What" %}</th>
                <th><i class="icon-remove"></i></th>
              </tr>
            </thead>
            <tbody>
              {% for i in acl.users %}
              <tr>
                <td>
                  <i class="icon-user"></i>
                </td>
                <td>
                  <a href="{% url "dashboard.views.profile" username=i.user.username %}"
                    title="{{ i.user.username }}">
                    {% include "dashboard/_display-name.html" with user=i.user show_org=True %}
                  </a>
                </td>
                <td>
                  <select class="form-control" name="perm-u-{{i.user.id}}">
                    {% for id, name in acl.levels %}
                    <option{%if id == i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option>
                    {% endfor %}
                  </select>
                </td>
                <td>
                  <input type="checkbox" name="remove-u-{{i.user.id}}" title="{% trans "Remove" %}"/>
                </td>
              </tr>
              {% endfor %}
              {% for i in acl.groups %}
              <tr>
                <td><i class="icon-group"></i></td>
                <td>
                  <a href="{% url "dashboard.views.group-detail" pk=i.group.pk %}">
                    {{i.group}}
                  </a>
                </td>
                <td>
                  <select class="form-control" name="perm-g-{{i.group.id}}">
                    {% for id, name in acl.levels %}
                    <option{%if id == i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option>
                    {% endfor %}
                  </select>
                </td>
                <td>
                  <input type="checkbox" name="remove-g-{{i.group.id}}" title="{% trans "Remove" %}"/>
                </td>
              </tr>
              {% endfor %}
              <tr><td><i class="icon-plus"></i></td>
                  <td><input type="text" class="form-control" name="name"
                      placeholder="{% trans "Name of group or user" %}"></td>
                  <td><select class="form-control" name="level">
                          {% for id, name in acl.levels %}
                          <option value="{{id}}">{{name}}</option>
                          {% endfor %}
                  </select></td><td></td>
              </tr>
            </tbody>
          </table>
          <div class="form-actions">
            <button type="submit" class="btn btn-success">{% trans "Save" %}</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

{% endblock %}
