{% extends "bee_django_course/base.html" %}

{% block content %}
    {#课程列表#}
    <div style="margin: 10px 0;">
        <div class="dropdown">
            <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="false">
                课程列表
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
                {% for u_c in user_course_list %}
                    <li><a href="{% url 'bee_django_course:user_course_detail' u_c.id %}">{{ u_c.course.name }}</a></li>
                {% endfor %}
            </ul>
        </div>
    </div>

    <div class="text-center"><h4>{{ user_course.course.name }}</h4></div>

    <table class="table">
        <thead>
        <tr>
            {#            <th>顺序</th>#}
            <th>ID</th>
            <th>课件</th>
            <th>状态</th>
            <th></th>
            <th></th>
        </tr>
        </thead>
        <tbody>
        {% for e in user_course_section_list %}
            <tr>
                {#                <td>#}
                {#                    {{ e.section.coursesectionmid_set.all }}#}
                {#                </td>#}
                <td>
                    {{ e.id }}
                </td>
                <td>
                    {{ e.section.name }}
                </td>
                <td>
                    {% if e.status == 0 %}
                        未开始
                    {% elif e.status == 1 %}
                        学习中
                    {% elif e.status == 2 %}
                        已通过
                    {% elif e.status == 3 %}
                        退回重修
                    {% elif e.status == 4 %}
                        已提交
                    {% endif %}
                    {% if  not e.status == 0 %}
                        <a href="{% url 'bee_django_course:user_course_section_detail' pk=e.id %}">详情</a>
                    {% endif %}
                </td>
                <td>


                    {#                    {{ e.score | default:'' }}#}
                </td>
                <td>
                    {% if e.section.has_videowork %}
                        直播分钟：
                        {% if not e.status == 0 %}
                            {{ e.work_time }}
                        {% endif %}
                        {% if e.minus_live_mins > 0 %}
                            - {{ e.minus_live_mins }}
                        {% endif %}
                        /
                        {{ e.section.video_length_req }}
                        {% if e.teacher_add_mins > 0 %}
                            + {{ e.teacher_add_mins }}
                        {% endif %}
                        {% if e.work_time > 0 and e.is_learning %}
                            {% if perms.bee_django_course.minus_live_mins %}
                                <div>
                                    修改扣减分钟数为：<input id="minus_live_mins_{{ e.id }}" size="3"
                                                    value="{{ e.minus_live_mins }}">
                                    <button class="btn-warning" onclick="save_minus_live_mins('{{ e.id }}')">确定</button>
                                </div>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                    {% if e.section.has_questionwork %}
                        {% if e.question_passed %}
                            <a href="{% url 'bee_django_course:user_question_answer' e.id %}">查看问卷</a>
                        {% endif %}
                    {% endif %}
                    {% if e.section.has_imagework or e.section.has_textwork %}
                        <a href="{% url 'bee_django_course:manage_user_assignment' ucs_id=e.id %}"
                           class="btn btn-default">作业</a>
                    {% endif %}
                </td>
                <td>
                    {% if user and user.is_pause %}

                    {% else %}
                        {% if e.status == 0 %}
                            {% if perms.bee_django_course.open_ucs %}
                                <a href="#" class="btn btn-danger create_ucs"
                                   data-confirm="{% url 'bee_django_course:open_user_course_section' ucs_id=e.id %}">
                                    开启
                                </a>
                            {% endif %}
                        {% elif e.status == 1 %}
                            {#无条件通过课件#}
                            {% if perms.bee_django_course.pass_ucs_super %}
                                <a href="#" class="btn btn-success pass_ucs"
                                   data-confirm="{% url 'bee_django_course:pass_user_course_section' ucs_id=e.id %}">
                                    通过
                                </a>
                                {#达到要求后通过课件#}
                            {% elif perms.bee_django_course.pass_ucs %}
                                {% if e.pass_check == True %}
                                    <a href="#" class="btn btn-success pass_ucs"
                                       data-confirm="{% url 'bee_django_course:pass_user_course_section' ucs_id=e.id %}">
                                        通过
                                    </a>
                                {% endif %}
                            {% endif %}
                            {% if perms.bee_django_course.close_ucs %}
                                <a href="#" class="btn btn-warning close_ucs"
                                   data-confirm="{% url 'bee_django_course:close_user_course_section' ucs_id=e.id %}">
                                    关闭
                                </a>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    {% include 'bee_django_course/paginator.html' %}


{% endblock content %}
{% block scripts %}
    <script type="text/javascript">
        $(document).ready(function () {
            $('.create_ucs').click(function (e) {
                if (confirm('确定开启此课吗?')) {
                    e.preventDefault();
                    var url = $(this).attr('data-confirm');
                    $.post(url).done(function (data) {
                        alert(data['message']);
                        window.location.href = data['new_url'];
                    });
                }
            });

            $('.pass_ucs').click(function (e) {
                if (confirm('确定通过此课吗?')) {
                    e.preventDefault();
                    var url = $(this).attr('data-confirm');
                    $.post(url).done(function (data) {
                        alert(data['message']);
                        window.location.href = data['new_url'];
                    });
                }
            });

            $('.close_ucs').click(function (e) {
                if (confirm('此操作将清空课件学习时间，是否继续?')) {
                    e.preventDefault();
                    var url = $(this).attr('data-confirm');
                    $.post(url).done(function (data) {
                        alert(data['message']);
                        window.location.href = data['new_url'];
                    });
                }
            });

        });

        function save_minus_live_mins(ucs_id) {
            var mins = $("#minus_live_mins_" + ucs_id).val();
            var url = "{% url 'bee_django_course:save_ucs_minus_live_mins' %}";
            $.post(url, {"ucs_id": ucs_id, "mins": mins}).done(function (data) {
                alert(data['msg']);
                if (data.error == 0) {
                    location.reload();
                }
            });
        }
    </script>
{% endblock scripts %}