{% extends 'inactivity/base.html' %}
{% load i18n %}
{% load humanize %}
{% load static %}

{% block details %}

    <span class="pull-right">
        <a class="btn btn-success btn-tabs" href="{% url 'inactivity:create_loa_request' %}">
            {% translate "Create Request" %}
        </a>
    </span>

    <!-- Nav tabs -->
    <ul id="myTabs" class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active">
            <a href="#tab-pending-requests" aria-controls="tab-pending-requests" role="tab" data-toggle="tab">
                {% translate "Pending" %}
            </a>
        </li>
        <li role="presentation" >
            <a href="#tab-closed-requests" aria-controls="tab-closed-requests" role="tab" data-toggle="tab">
                {% translate "Closed" %}
            </a>
        </li>
    </ul>

    <div class="panel panel-default panel-tabs">
        <div class="panel-body">
            <div class="tab-content">

                <div role="tabpanel" class="tab-pane active" id="tab-pending-requests">
                    <div class="table-responsive">
                        <table id="table-pending-requests" style="width: 100%;" class="table table-striped">
                            <thead>
                                <tr>
                                    <th>{% translate "Submitted" %}</th>
                                    <th>{% translate "Start" %}</th>
                                    <th>{% translate "End" %}</th>
                                    <th>{% translate "Duration" %}</th>
                                    <th>{% translate "Description" %}</th>
                                    <th></th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>

                <div role="tabpanel" class="tab-pane" id="tab-closed-requests">
                    <div class="table-responsive">
                        <table id="table-closed-requests" style="width: 100%;" class="table table-striped">
                            <thead>
                                <tr>
                                    <th>{% translate "Submitted" %}</th>
                                    <th>{% translate "Start" %}</th>
                                    <th>{% translate "End" %}</th>
                                    <th>{% translate "Duration" %}</th>
                                    <th>{% translate "Description" %}</th>
                                    <th>{% translate "Result" %}</th>
                                    <th>{% translate "Processed By" %}</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>

            </div>
        </div>
    </div>


{% endblock %}

{% block extra_javascript %}

    {% include 'bundles/datatables-js.html' %}

    <script>
        "use strict";
        $(document).ready(function () {

            /* dataTable def */
            let lengthMenu =  [
                [10, 25, 50, 100, -1],
                [10, 25, 50, 100, "All"],
            ];

            $("#table-pending-requests").DataTable({
                ajax: {
                    url: '{% url "inactivity:my_open_requests_data" %}',
                    dataSrc: "data",
                    cache: false,
                },

                columns: [
                    {
                        data: 'created_at',
                        render: {
                            _: 'display',
                            sort: 'sort'
                        }
                    },
                    { data: "start" },
                    { data: "end" },
                    { data: "duration" },
                    { data: "notes" },
                    { data: "actions" },
                ],

                lengthMenu: lengthMenu,

                columnDefs: [
                    { sortable: false, targets: [5] }
                ],

                order: [
                    [0, "desc"],
                ],
            });

            $("#table-closed-requests").DataTable({
                ajax: {
                    url: '{% url "inactivity:my_completed_requests_data" %}',
                    dataSrc: "data",
                    cache: false,
                },

                columns: [
                    {
                        data: 'created_at',
                        render: {
                            _: 'display',
                            sort: 'sort'
                        }
                    },
                    { data: "start" },
                    { data: "end" },
                    { data: "duration" },
                    { data: "notes" },
                    { data: "status_html" },
                    { data: "approver_html" },
                ],

                lengthMenu: lengthMenu,

                order: [
                    [0, "desc"],
                ],
            });

        });
    </script>

{% endblock %}

{% block extra_css %}
    {% include 'bundles/datatables-css.html' %}
    <link rel="stylesheet" href="{% static 'inactivity/css/aa-bootstrap-fix.min.css' %}" type="text/css">
    <link rel="stylesheet" href="{% static 'inactivity/css/inactivity.css' %}" type="text/css">
    <link rel="stylesheet" href="{% static 'inactivity/css/my_requests.css' %}" type="text/css">
{% endblock %}

{% block extra_script %}
{% endblock %}
