{% extends "bee_django_user/base.html" %}
{% load bee_django_user_filter %}

{% block content %}
    {% include 'bee_django_user/logo.html' %}
    {% include 'bee_django_user/nav.html' %}
    {% include 'bee_django_user/user/search.html' %}

    <div class="text-center"><h3>
        学生列表
    </h3>
    </div>
    {#    <div class="text-right">#}
    {#        <a class="btn btn-default" href="{% url 'bee_django_exam:notice_add' %}">添加须知</a>#}
    {#    </div>#}

    <table class="table">
        <thead>
        <tr>
            <th>缦客号</th>
            <th>姓名</th>
            <th>结课时间</th>
            <th>足迹</th>
            <th>课程</th>
            <th>考级</th>
            <th></th>

        </tr>
        </thead>
        <tbody>
        {% for user in user_list %}
            <tr>

                <td>{{ user.userprofile.get_sn }}</td>
                <td>{{ user.first_name }}
                    {% get_leave_status user as status %}
                    {% if status %}
                        （{{ status }}）
                    {% endif %}
                    {% if not user.is_active %}
                        (已禁用)
                    {% endif %}
                    {% if user.is_pause %}
                        (已暂停)
                    {% endif %}
                </td>
                <td>
                    {{ user.get_expire_date|default:"" }}
                </td>
                <td><a href="{% url "bee_django_track:record_list" user.id %}" class="btn btn-success">足迹</a></td>
                <td><a href="{% url "bee_django_course:choose_user_course" user.id %}" class="btn btn-success">课程表</a></td>
                <td><a href="{% url "bee_django_exam:user_exam_record_list" user.id %}" class="btn btn-success">考级</a>
                </td>
                <td>
                    <a href="{% url 'bee_django_user:user_detail' user.id %}  ">详情</a>
                    {% if perms.bee_django_user.change_userprofile %}
                        <a href="{% url 'bee_django_user:user_update' user.id %}  ">修改</a>
                    {% endif %}

                    {% if not user.is_pause %}
                        <button onclick="update_user_status({{ user.id }},1,0)">暂停</button>
                    {% endif %}

                    {% if user.is_active %}
                        <button onclick="update_user_status({{ user.id }},0,1)">禁用</button>
                    {% endif %}
                    {% if not user.is_active or user.is_pause %}
                        <button onclick="update_user_status({{ user.id }},0,0)">恢复正常</button>
                    {% endif %}
                    {% if request.user.is_superuser %}
                        <a href="#" id="delete_{{ user.id }}"
                       data-confirm="{% url "bee_django_user:user_delete" user.id %}"
                       onclick="click_del(this)" class="btn btn-danger">删除</a>
                    {% endif %}
                </td>
            </tr>

        {% endfor %}
        </tbody>
    </table>
    {% include 'bee_django_user/paginator.html' %}
{% endblock %}
{% block scripts %}
    <script>
        function click_del(_this) {
            if (!confirm('确认要执行这个操作？')) {
                return false;
            }
            var url = $(_this).attr('data-confirm');
            $.post(url).done(function (data) {
                alert('删除成功!');
                location.reload();
            });


        }

        function update_user_status(user_id, is_pause, is_disable) {
            if (!confirm('确认要修改学生状态？')) {
                return false;
            }
            var url = "{% url 'bee_django_user:status_save' %}";
            $.post(url, {"user_id": user_id, "is_pause": is_pause, "is_disable": is_disable}).done(function (data) {
                alert('修改成功!');
                location.reload();
            });

        }
    </script>
{% endblock %}