{% extends "app_home/base.html" %}
{% load static %}
{% load i18n %}

{% block navbar_app %}
{% include 'app_home/_sidebar.html' %}
{% endblock %}


{% block title %}
{% if permission.keyname %}<h2>{% translate "Permission" %}: {{ permission.keyname }}</h2>
{% else %}<h2>{% translate "New Permission" %}</h2>
{% endif %}
<hr>
{% endblock %}


{% block content %}

<form method="post">{% csrf_token %}

<a class="btn btn-outline-dark" href="{% url 'app_user:permission_list' %}" role="button">
<i class="fa fa-backward" aria-hidden="true"></i>&nbsp;{% translate "Back" %}</a>

<input class="btn btn-success" type="submit" value="{% translate 'Save' %}" name="save">

{% if permission and not permission.is_builtin %}
<a class="btn btn-outline-danger" data-bs-toggle="modal" data-bs-target="#DeleteModal" role="button">
<i class="fa fa-trash" aria-hidden="true"></i>&nbsp;{% translate "Delete" %}</a>
{% endif %}

<hr>

<table class="table">
  {{ form.as_table }}
</table>

</form>


{% if permission and not permission.is_builtin %}
<!-- DELETE CONFIRM Modal -->
<div class="modal fade" id="DeleteModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h1 class="modal-title fs-5" id="staticBackdropLabel">{% translate "Confirm delete ?" %}</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>

<div class="modal-body">
<p>{% translate "Permission" %}: {{ permission.keyname }}</p>
</div>

<div class="modal-footer">
<form action="{% url 'app_user:permission_delete' permission.id %}" method="post">{% csrf_token %}
<button role="button" class="btn btn-danger">{% translate "Delete" %}</button>
<a role="button" class="btn btn-outline-dark" data-bs-dismiss="modal">{% translate "Cancel" %}</a>
</form>
</div>

</div>
</div>
</div>
{% endif %}


{% endblock %}
