<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="定时任务列表" libs=["table"]/>
<div class="container-div">
	<div class="row">
	<div class="col-sm-12 search-collapse">
	<@f.form id="job-form">
		<div class="select-list">
			<ul>
				<li>
					<@ctx.i18n text = "任务名称"/>：
					<input type="text" class="form-control" name="jobName"/>
				</li>
				<li>
					<@ctx.i18n text = "任务分组"/>：
					<@f.select name="jobGroup" blankValue="" blankLabel="所有" dictType="sys_job_group" />
				</li>
				<li>
					<@ctx.i18n text = "任务状态"/>：
					<@f.select name="status" blankValue="" blankLabel="所有" dictType="sys_job_status" />
				</li>
				<li>
					<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
					<a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
				</li>
			</ul>
		</div>
	</@f.form>
	</div>
	<@table id="bootstrap-table">
			<@shiro.hasPermission name="sys:job:add">
				<a class="btn btn-success" onclick="opt.operate.addTab()"><i class="fa fa-plus"></i>&nbsp;<@ctx.i18n text = "新增"/></a>
			</@shiro.hasPermission>
			<@shiro.hasPermission name="sys:job:edit">
				<a class="btn btn-primary single disabled" onclick="opt.operate.editTab()"><i class="fa fa-pencil-square-o"></i>&nbsp;<@ctx.i18n text = "修改"/></a>
			</@shiro.hasPermission>
			<@shiro.hasPermission name="sys:job:del">
				<a class="btn btn-danger multiple disabled" onclick="opt.operate.delAll()">
					<i class="fa fa-remove"></i> <@ctx.i18n text = "删除"/>
				</a>
			</@shiro.hasPermission>
			<@shiro.hasPermission name="sys:job:loglist">
				<a class="btn btn-info" onclick="javascript:jobLog()">
					<i class="fa fa-list"></i> 日志
				</a>
			</@shiro.hasPermission>
	</@table>
	</div>
</div>
<@footer>
	<script>
        <#--var detailFlag = "${permission.hasPermi('sys:job:detail')}";-->
		var statusFlag = "${permission.hasPermi('sys:job:changeStatus')}";
		var datas = ${dict.getDictListJson('sys_job_group')};
		var visible = ${permission.isPermitteds("sys:job:detail,sys:job:changeStatus")?string('true', 'false')};

		var prefix = baseURL + "sys/schedule";

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        detailUrl: prefix + "/detail/{id}",
		        addUrl: prefix + "/add",
		        editUrl: prefix + "/edit/{id}",
		        delUrl: prefix + "/del",
		        sortName: "createTime",
		        uniqueId: "id",
		        sortOrder: "asc",
		        modalName: "任务",
		        columns: [
	        	{
                    title: $.i18n.prop("序号"), width: 5, align: "center", formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
		        {
		            field: 'id',
		            title: '任务编号'
		        },
		        {
		            field: 'jobName',
		            title: '任务名称'
		        },
		        {
		            field: 'jobGroup',
		            title: '任务分组',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(datas, value);
		            }
		        },
				{
					field: 'invokeTarget',
					title: '调用目标字符串',
					formatter: function(value, row, index) {
						return $.table.tooltip(value);
					}
				},
		        {
		            field: 'cronExpression',
		            title: '执行表达式'
		        },
				{
					field: 'nextDate',
					title: '下次执行时间'
				},
		        {
		        	visible: statusFlag == 'hidden' ? false : true,
		        	title: '任务状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
		        },
		        {
		            field: 'createTime',
		            title: $.i18n.prop("创建时间"),
		            sortable: true
		        },
		        {
		            title:"<@ctx.i18n text = "操作"/>",
		            align: 'center',
					visible:visible,
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-primary btn-xs ' + statusFlag + '" href="javascript:void(0)" onclick="run(\'' + row.id + '\', \'' + row.jobGroup + '\')"><i class="fa fa-play-circle-o"></i> 执行一次</a> ');
		                /*actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="opt.operate.detail(\'' + row.jobId + '\')"><i class="fa fa-search"></i>详细</a> ');*/
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});
        
		/* 调度任务状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="start(\'' + row.id + '\', \'' + row.jobGroup + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="stop(\'' + row.id + '\', \'' + row.jobGroup + '\')"></i> ';
    		}
		}
		
		/* 立即执行一次 */
		function run(jobId, jobGroup) {
			opt.modal.confirm("确认要立即执行一次任务吗？", function() {
				opt.operate.post(prefix + "/run", { "ids": jobId});
		    })
		}

		/* 调度任务-停用 */
		function stop(jobId, jobGroup) {
			opt.modal.confirm("确认要停用任务吗？", function() {
				opt.operate.post(prefix + "/status", { "id": jobId, "jobGroup": jobGroup, "status": "1"});
		    })
		}

		/* 调度任务-启用 */
		function start(jobId, jobGroup) {
			opt.modal.confirm("确认要启用任务吗？", function() {
				opt.operate.post(prefix + "/status", { "id": jobId, "jobGroup": jobGroup, "status": "0"});
		    })
		}

		/* 调度日志查询 */
		function jobLog(id) {
			var url = baseURL + 'sys/jobLog';
			opt.modal.openTab("调度日志", url);
		}
	</script>
</@footer>
</@pageTheme>