{% extends "admin_base.html" %}

{% import "admin_page.html" as pg %}
{% block content %}

    <div class="wrap js-check-wrap">

        <div class="jumbotron" >
            <div style="text-align: center">
                <h1 class="display-4">小牛定时任务管理系统</h1>
                <p class="lead">&nbsp;&nbsp;方便、统一、自由</p>
            </div>
        </div>

        <ul class="nav nav-tabs">
            <li class="active"><a href="">任务列表</a></li>
            <li><a href="{{ url_for('main.cron_add') }}">任务添加</a></li>
            <li><a href="{{ url_for('main.job_log_all_list') }}">任务执行记录</a></li>
            <li><a href="{{ url_for('main.api_doc') }}">API文档</a></li>
            <li><a href="{{ url_for('main.logout') }}">退出</a></li>
        </ul>
        <form class="well form-search" method="get" action="{{ url_for('main.cron_list') }}">高级查询：
            <input type="text" placeholder="任务名称" name="task_name" value="{{ keyword.get("task_name","") }}">
            <input type="submit" class="btn btn-primary" value="搜索"/>
            <a href="{{ url_for('main.cron_list') }}" class="btn btn-danger" >重置</a>
        </form>
        <form method="post" class="js-ajax-form" action="{{ url_for('main.cron_batch_del') }}">
            <div class="table-actions">
                <button type="submit" class="btn btn-primary btn-small js-ajax-submit">批量删除</button>
            </div>
            <table class="table table-hover table-bordered">
                <thead>
                <tr>
                    <th width="15"><label><input type="checkbox" class="js-check-all" data-direction="x"
                                                 data-checklist="js-check-x"></label></th>
                    <th>ID</th>
                    <th>任务名称</th>
                    <th>备注</th>
                    <th>具体时间</th>
                    <th>星期</th>
                    <th>日</th>
                    <th>小时</th>
                    <th>分钟</th>
                    <th>秒</th>
                    <th>URL</th>
                    <th>运行状态</th>
                    <th width="120">操作事项</th>
                </tr>
                </thead>
                <tbody>
                    {% for item in page_data.items %}
                    <tr>
                        <td><input class="js-check" data-yid="js-check-y" data-xid="js-check-x" type="checkbox" name="id" value="{{ item.id }}"></td>
                        <td>{{ item.id }}</td>
                        <td>{{ item.task_name }}</td>
                        <td>{{ item.task_keyword }}</td>
                        <td>{{ item.run_date }}</td>
                        <td>{{ item.day_of_week }}</td>
                        <td>{{ item.day }}</td>
                        <td>{{ item.hour }}</td>
                        <td>{{ item.minute }}</td>
                        <td>{{ item.second }}</td>
                        <td>{{ item.req_url }}</td>
                        <td>
                            {% if item.status == 0 %}
                            已停止
                            {% elif item.status == 1 %}
                            运行中
                            {% else %}
                            已结束
                            {% endif%}
                        </td>
                        <td>
                            <a href="javascript:;" onclick="open_iframe_dialog('{{ url_for('main.job_log_list',id=item.id) }}','运行记录查看')">运行记录</a> |

                            {% if item.status == 0 %}
                             <a href="{{ url_for('main.update_status',id=item.id) }}" class="js-ajax-dialog-btn">运行</a> |
                            {% elif item.status == 1 %}
                            <a href="{{ url_for('main.update_status',id=item.id) }}" class="js-ajax-dialog-btn">停止</a> |
                            {% else %}
                            {% endif%}
                            <a href="{{ url_for('main.cron_edit',id=item.id) }}">编辑</a> |
                            <a class="js-ajax-delete" href="{{ url_for('main.cron_del',id=item.id) }}">删除</a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </form>
        <div class="pagination">
            {{ pg.page(page_data,'main.cron_list',keyword) }}
        </div>
    </div>
{% endblock %}