{% load static %}
<html lang="en">
<head>
    <title>ViewLogger - Search in archives</title>
    <script src="{% static "js/jquery-1.11.min.js" %}"></script>
    <script src="{% static 'js/chosen.jquery.min.js' %}"></script>
    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static "css/chosen.min.css" %}" rel="stylesheet"/>
    <script type="text/javaScript">
        $(document).ready(function () {
            $("#id_request_method").chosen("id_request_method");
        });
    </script>
    <style>
        #ViewLoggerTable ul {
            list-style: none;
            padding-left: 0;
        }

        .collapsible {
            background-color: #777;
            color: white;
            cursor: pointer;
            padding: 18px;
            width: 100%;
            border: none;
            border-radius: 15px;
            text-align: left;
            outline: none;
            font-size: 15px;

        }

        .active, .collapsible:hover {
            background-color: #555;
        }

        .content {
            padding: 0 18px;
            display: none;
            overflow: hidden;
        }
    </style>
</head>
<body class="container" style="width: 100%">
<div style=""><h4 style="font-weight: bold;">View Logger</h4></div>
<form action="{% url 'search_in_archives' %}" method="post">
    {% csrf_token %}
    <div class="row">
        <div class="col-md-4 label-div"><label>{{ form.view_name.label }}</label></div>
        <div class="col-md-4">{{ form.view_name }}</div>
    </div>
<br/>
    <div class="row">
        <div class="col-md-4 label-div"><label>{{ form.request_method.label }}</label></div>
        <div class="col-md-4">{{ form.request_method }}</div>
    </div>
<br/>
    <div class="row">
        <div class="col-md-4 label-div"><label>{{ form.url.label }}</label></div>
        <div class="col-md-4">{{ form.url }}</div>
    </div>
<br/>
    <div class="row">
        <div class="col-md-4 label-div"><label>{{ form.done_by.label }}</label></div>
        <div class="col-md-4">{{ form.done_by }}</div>
    </div>
<br/>
    <div class="row">
        <div class="col-md-4 label-div"><label>Done On</label></div>
        <div class="col-md-2" id="done_on_from" title="From">{{ form.done_on_from}}</div>
        <div class="col-md-2" id="done_on_to" title="To">{{ form.done_on_to}}</div>
    </div>
    <br/>
    <div class="row">
        <div class="col-md-4" align="center">
            <button type="submit" name="submit" class="btn btn-primary">Search</button>
        </div>
        <div class="col-md-4" align="center">
            <a href="{% url 'LogMain' %}" class="btn btn-info">Back</a>
        </div>
        {% if count and count > 0 %}
            <div class="col-md-4">

                <button type="submit" name="export" class="btn btn-success">Export As Excel</button>
            </div>
        {% endif %}
    </div>

</form>
{% if count %}
    {% if count == 0 %}
        <div class="alert alert-danger">
            No Record Found {{ id }}.
        </div>
    {% endif %}
    {% for object in objects %}
        <br/>
        <button class="collapsible">File Name = {{ object.file }}</button>
        <div class="content" id="ViewLoggerTable">
            <table class="table table-hover table-bordered">
                <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">View Name</th>
                    <th scope="col">Done By</th>
                    <th scope="col">Done On</th>
                    <th scope="col">URL</th>
                    <th scope="col">View Args</th>
                    <th scope="col">View Kwargs</th>
                    <th scope="col">Request Method</th>
                    <th scope="col">Request Body</th>

                </tr>
                </thead>
                <tbody>
                {% for change in object.changes %}
                    <tr>
                        <th scope="row">
                            <ul>
                                {% for obj in change.id %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </th>
                        <td>
                            <ul>
                                {% for obj in change.view_name %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                        <td>
                            <ul>
                                {% for obj in change.done_by %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                        <td>
                            <ul>
                                {% for obj in change.done_on %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                        <td>
                            <ul>
                                {% for obj in change.url %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                        <td>
                            <ul>
                                {% for obj in change.view_args %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                        <td>
                            <ul>
                                {% for obj in change.view_kwargs %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                        <td>
                            <ul>
                                {% for obj in change.request_method %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                        <td style="width: 30%">
                            <ul>
                                {% for obj in change.request_body %}
                                    <li>{{ obj }}</li>
                                {% endfor %}
                            </ul>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        <br/>
    {% endfor %}
{% else %}
{% endif %}
<script>
    var coll = document.getElementsByClassName("collapsible");
    var i;

    for (i = 0; i < coll.length; i++) {
        coll[i].addEventListener("click", function () {
            this.classList.toggle("active");
            var content = this.nextElementSibling;
            if (content.style.display === "block") {
                content.style.display = "none";
            } else {
                content.style.display = "block";
            }
        });
    }
</script>
</body>
</html>
