<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>

<body class="timo-layout-page">
<div class="layui-card">
    <div class="layui-card-header timo-card-header">
        <span><i class="fa fa-bars"></i> 监控任务列表</span>
        <i class="layui-icon layui-icon-refresh refresh-btn"></i>
    </div>
    <div class="layui-card-body">
        <div class="layui-row timo-card-screen put-row">
            <div class="layui-row timo-card-screen put-row">
                <div class="pull-left layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">环境</label>
                        <div class="layui-input-block timo-search-status">
                            <select id="getPageByEnv" class="timo-search-select" name="env" onchange="getPageByEnv()"
                                    mo:dict="ENVIRONMENT" mo-selected="${env}"></select>
                        </div>
                    </div>
                    <div class="layui-inline timo-search-box">
                        <label class="layui-form-label">任务 ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="jobId" th:value="${param.jobId}" placeholder="请输入任务 ID"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn timo-search-btn">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="timo-table-wrap">
            <table class="layui-table timo-table">
                <thead>
                <tr>
                    <th class="sortable" data-field="jobId">任务 ID</th>
                    <th class="sortable" data-field="jobClassName">任务类名</th>
                    <th class="sortable" data-field="cronExp">CRON 表达式</th>
                    <th class="sortable" data-field="enable">是否启用</th>
                    <th class="sortable" data-field="notifyGroups">通知组</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td th:text="${item.jobId}">任务 ID</td>
                    <td th:text="${item.jobClassName}">任务类名</td>
                    <td th:text="${item.cronExp}">CRON 表达式</td>
                    <td th:text="${item.enable}">是否启用</td>
                    <td>
                        <a class="open-popup" data-title="设置通知组" th:attr="data-url=@{'/monitor/notify/'+${item.id}}"
                           data-size="640,480" href="#">设置</a>
                    </td>
                    <td>
                        <a class="open-popup" data-title="编辑任务" th:attr="data-url=@{'/monitor/job/edit/'+${item.id}}"
                           data-size="640,480" href="#">编辑</a>
                        <a class="ajax-post"
                           th:href="@{'/api/monitor/job/'+${item.jobId}+'/1'}">启用</a>
                        <a class="ajax-post"
                           th:href="@{'/api/monitor/job/'+${item.jobId}+'/0'}">禁用</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div th:replace="/common/fragment :: page"></div>
    </div>
</div>

<script th:replace="/common/template :: script"></script>
<script type="text/javascript" th:src="@{/js/plugins/jquery-2.2.4.min.js}"></script>
<script type="text/javascript">
    function getPageByEnv() {
        var selectedOption = $("#getPageByEnv option:selected")
        var param = selectedOption.text()
        url = '?env=' + param
        window.location.href = window.location.pathname + url;
    }
</script>
</body>
</html>