{% extends "base.html" %}
{% load staticfiles %}

{% block title %}任务列表{% endblock %}

{% block staticcss %}


{% endblock %}

{% block staticjs %}

<script type="text/javascript">

    $(".js-example-basic-multiple").select2();

    $(".form_datetime").datetimepicker({
        format: "yyyy-mm-dd",
        minView: 2,
        autoclose: true,
        todayBtn: true,
        pickerPosition: "bottom-left",
        language: 'zh',
        todayHighlight: true
    });


</script>

<script>
    $(document).ready(function () {
        $('#dataTable').DataTable({
            responsive: true,
            "language": {

                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "表中数据为空",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    });
</script>
{% endblock %}

{% block content %}


<!-- Page Content -->
<div id="page-wrapper">


    {% if messages %}
    <ul class="messages">
        {% for message in messages %}
        <div {% if message.tags %} class="alert alert-{{ message.tags }}" {% endif %}><strong>{{ message }}</strong>
        </div>
        {% endfor %}
    </ul>
    {% endif %}

    <div class="container-fluid">
        <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h1 class="h3 mb-0 text-gray-800">本周任务</h1>
        </div>
    </div>
    <!-- /.container-fluid -->
    <!-- /.row -->


    {% if search_results %}
    <div class="card shadow mb-4">
        <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
            <h6 class="m-0 font-weight-bold text-primary">本周任务列表</h6>
            <div class="dropdown no-arrow">
                <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="false">
                    <i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
                </a>
                <div class="dropdown-menu dropdown-menu-right shadow animated--fade-in"
                    aria-labelledby="dropdownMenuLink">
                    <a class="dropdown-item" data-toggle="modal" data-target="#myModal">
                        <li>
                            <button class="btn btn-outline" data-toggle="modal" data-target="#myExport">
                                导出 <i class="glyphicon glyphicon-export"></i>
                            </button>

                        </li>
                    </a>


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

        <div class="card-body">
            <!--表单报错显示-->
            {% if form.errors %}

            {% for field, error in form.errors.items %}
            <div class="alert alert-error">
                {{ field }} <code>{{ error }}</code>
            </div>
            {% endfor %}


            {% endif %}
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>选择</th>
                            <th>ID</th>
                            <th>任务名称</th>
                            <th>任务类型</th>
                            <th>业务类型</th>
                            <th>权重</th>
                            <th>创建人</th>
                            <th>创建日期</th>
                            <th>截止日期</th>
                            <th>分配给</th>
                            <th>状态</th>
                            <th>评论</th>
                            <th>绩效值</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>选择</th>
                            <th>ID</th>
                            <th>任务名称</th>
                            <th>任务类型</th>
                            <th>业务类型</th>
                            <th>权重</th>
                            <th>创建人</th>
                            <th>创建日期</th>
                            <th>截止日期</th>
                            <th>分配给</th>
                            <th>状态</th>
                            <th>评论</th>
                            <th>绩效值</th>
                            <th>操作</th>
                        </tr>
                    </tfoot>
                    <tbody>
                        {% for list in search_results %}
                        <tr class="odd gradeX ">

                            <td><input type="checkbox" value="{{ list.id }}" name="mark_done"></td>
                            <td>{{ forloop.counter }}</td>
                            <td>
                                <p title="{{ list.title }}">{{ list.title|slice:'20' }}</p>
                            </td>
                            <td>{{ list.get_tasktype_display }}</td>
                            <td>
                                <p title="{{ list.type }}"> {{ list.type |slice:'10'}}</p>
                            </td>
                            <td class="{% ifequal list.priority 1 %}danger {% endifequal %}">
                                {{ list.get_priority_display }}</td>
                            <td>{{ list.created_by }}</td>
                            <td>{{ list.created_date }}</td>
                            <td class="center">{{ list.due_date|default:'' }}</td>
                            <td class="center">{{ list.assigned_to|default:'' }}</td>
                            <td>{{ list.get_status_display }}</td>
                            <td><a href="#">{{ list.itemcomment_set.all.count }}</a> </td>
                            <td>{{ list.per_value }}</td>
                            <td>
                                <a class="btn btn-outline btn-primary" href="{% url 'taskview' list.id %}">查看</a>

                                <a class="btn btn-outline btn-info" href="{% url 'edittaskitem'  list.id %}">编辑</a>

                                <a class="btn btn-outline btn-danger" href="#"
                                    data-href="{% url 'delitem'%}?type=task&id={{ list.id }}" data-toggle="modal"
                                    data-target="#confirm-delete">删除</a>

                            </td>
                        </tr>
                        {% endfor %}

                    </tbody>
                </table>
                <button type="submit" class="btn btn-outline btn-danger" name="mark">批量删除</button>
            </div>
        </div>
    </div>


    {% endif %}
</div>
<form role="form" onsubmit="return dosubmit()" method="post">
    {% csrf_token %}
    <div class="modal fade" id="myExport" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-body">
                    确认导出记录吗？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button class="btn btn-primary" type="submit" name="export">导出</button>
                </div>
            </div>
        </div>
    </div>
</form>
<!--表单报错显示-->
{% if form.errors %}

{% for field, error in form.errors.items %}
<div class="alert alert-error">
    {{ field }} <code>{{ error }}</code>
</div>
{% endfor %}


{% endif %}



{% endblock %}