{% extends '_base_list.html' %}
{% load i18n %}
{% load static %}
{% load common_tags %}
{% block content_left_head %}
    <link href="{% static 'css/plugins/datepicker/datepicker3.css' %}" rel="stylesheet">
    <style>
        #search_btn {
            margin-bottom: 0;
        }
    </style>
{% endblock %}


{% block table_search %}
    <form id="search_form" method="get" action="" class="pull-right form-inline">
        <div class="form-group" id="date">
            <div class="input-daterange input-group" id="datepicker">
                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                <input type="text" class="input-sm form-control" style="width: 100px;" name="date_from" value="{{ date_from }}">
                <span class="input-group-addon">to</span>
                <input type="text" class="input-sm form-control" style="width: 100px;" name="date_to" value="{{ date_to }}">
            </div>
        </div>
        <div class="input-group">
            <select class="select2 form-control" name="username">
                <option value="">{% trans 'Select user' %}</option>
                {% for user in user_list %}
                    <option value="{{ user.username }}" {% if user.username == username %} selected {% endif %}>{{ user.username }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="input-group">
            <input type="text" class="form-control input-sm" name="keyword" placeholder="Search" value="{{ keyword }}">
        </div>
        <div class="input-group">
            <div class="input-group-btn">
                <button id='search_btn' type="submit" class="btn btn-sm btn-primary">
                    搜索
                </button>
            </div>
        </div>
    </form>
{% endblock %}

{% block table_head %}
    <th class="text-center">{% trans 'ID' %}</th>
    <th class="text-center">{% trans 'Username' %}</th>
    <th class="text-center">{% trans 'Name' %}</th>
    <th class="text-center">{% trans 'Type' %}</th>
    <th class="text-center">{% trans 'UA' %}</th>
    <th class="text-center">{% trans 'IP' %}</th>
    <th class="text-center">{% trans 'City' %}</th>
    <th class="text-center">{% trans 'Date' %}</th>
{% endblock %}

{% block table_body %}
    {% for login_log in login_log_list %}
        <tr class="gradeX">
            <td class="text-center">
                {{ login_log.id }}
{#                <a href="{% url 'audits:proxy-log-detail' pk=login_log.id %}">{{ login_log.id }}</a>#}
            </td>
            <td class="text-center">{{ login_log.username }}</td>
            <td class="text-center">{{ login_log.name }}</td>
            <td class="text-center">{{ login_log.get_login_type_display }}</td>
            {% if login_log.login_type == 'W' %}
                <td class="text-center">
                    <span href="javascript:void(0);" data-toggle="tooltips" title="{{ login_log.user_agent  }}">{{ login_log.user_agent | truncatechars:20 }}</span>
                </td>
            {% else %}
                <td class="text-center">{{ login_log.terminal }}</td>
            {% endif %}
            <td class="text-center">{{ login_log.login_ip }}</td>
            <td class="text-center">{{ login_log.login_city }}</td>
            <td class="text-center">{{ login_log.date_login }}</td>
        </tr>
    {% endfor %}
{% endblock %}

{% block custom_foot_js %}
    <script src="{% static 'js/plugins/datepicker/bootstrap-datepicker.js' %}"></script>
    <script>
        $(document).ready(function() {
            $('table').DataTable({
                "searching": false,
                "bInfo" : false,
                "paging": false,
                "order": []
            });
            $('#date .input-daterange').datepicker({
                dateFormat: 'mm/dd/yy',
                keyboardNavigation: false,
                forceParse: false,
                autoclose: true
            });
            $('.select2').select2();
        })
    </script>
{% endblock %}

