<%@page trimDirectiveWhitespaces="true"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="gen" uri="http://help.jspgen.com/taglib/jstl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1" />
<title>定时</title>
<!-- 当前页面 -->
<link type="text/css" href="${config.statie}ui/admin/images/admin.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
  <div class="area">
    <h2><i>
      <gen:if test='${empty param.id}'>添加
        <gen:else />
        编辑</gen:if>
      任务</i></h2>
    <div class="area-content">
      <form id="form" name="form" method="post" action="cron!save.gen">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
          <tr>
            <td width="30%" align="right"><span class="red">*</span>&nbsp;任务名称：</td>
            <td><input name="name" type="text" class="text small" id="name" value="${cron.name}" size="20" />
              <label for="name" generated="true" class="tip" tip=""></label></td>
          </tr>
          <tr class="border-top">
            <td align="right"><span class="red">*</span>&nbsp;实现类路径：</td>
            <td><input name="impl" type="text" class="text small" id="impl" value="${cron.impl}" size="50" />
              <label for="impl" generated="true" class="tip" tip=""></label></td>
          </tr>
          <tr class="border-top">
            <td align="right" valign="top">实现类参数：</td>
            <td><table border="0" cellspacing="0" cellpadding="0" class="var">
                <tr class="ignore">
                  <td align="left"><a href="javascript:void(0);" class="button green tiny add" title="增加">增加</a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="orange">请与类中使用的参数名保持一致</span></td>
                </tr>
                <gen:if test="${not empty cron.paramMap}">
          		<c:forEach items="${cron.paramMap}" var="map">
                <tr class="ignore">
                  <td align="left">参数名：<input name="key[]" type="text" class="text small ignore" value="${map.key}" size="10" />&nbsp;&nbsp;&nbsp;&nbsp;参数值：<input name="value[]" type="text" class="text small ignore" value="${map.value}" size="35" />&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="delete">删除</a></td>
                </tr>
                </c:forEach>
          		<gen:else />
                <tr class="ignore">
                  <td align="left">参数名：<input name="key[]" type="text" class="text small ignore" value="" size="10" />&nbsp;&nbsp;&nbsp;&nbsp;参数值：<input name="value[]" type="text" class="text small ignore" value="" size="35" />&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="delete">删除</a></td>
                </tr>
                </gen:if>
            </table></td>
          </tr>
          <tr class="border-top">
            <td align="right"><span class="red">*</span>&nbsp;运行模式：</td>
            <td><label><input type="radio" name="mode" value="time" ${(empty cron.mode || cron.mode == "time") ? 'checked="checked"' : ''}/>
              定时</label>&nbsp;&nbsp;
              <label><input type="radio" name="mode" value="loop" ${cron.mode == "loop" ? 'checked="checked"' : ''}/>
              循环</label>&nbsp;&nbsp;
              <label><input type="radio" name="mode" value="timeloop" ${cron.mode == "timeloop" ? 'checked="checked"' : ''}/>
              定时循环</label></td>
          </tr>
          <tr class="border-top tr_time" style="display:none;">
            <td align="right">运行时间：</td>
            <td><input name="time" type="text" class="text small ignore" id="time" value="${gen:dateTime(cron.time, 'yyyy-MM-dd HH:mm:ss', config.timezoneid)}" size="20" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" />
              <label for="time" generated="true" class="ico-tips date-picker"></label></td>
          </tr>
          <tr class="border-top tr_loop" style="display:none;">
            <td align="right">间隔时间：</td>
            <td><input name="interval" type="text" class="text small ignore" id="interval" value="${cron.interval}" size="5" />
              分钟，最多运行：<input name="count" type="text" class="text small ignore" id="count" value="${cron.count}" size="5" />
              次</td>
          </tr>
          <tr class="border-top tr_timeloop" style="display:none;">
            <td align="right">按周设置：</td>
            <td><table border="0" cellspacing="0" cellpadding="0">
                <tr class="ignore">
                  <td><label><input name="weekday" type="checkbox" value="1" />
                    周日</label>&nbsp;
                    <label><input name="weekday" type="checkbox" value="2" />
                    周一</label>&nbsp;
                    <label><input name="weekday" type="checkbox" value="3" />
                    周二</label>&nbsp;
                    <label><input name="weekday" type="checkbox" value="4" />
                    周三</label>&nbsp;
                    <label><input name="weekday" type="checkbox" value="5" />
                    周四</label>&nbsp;
                    <label><input name="weekday" type="checkbox" value="6" />
                    周五</label>&nbsp;
                    <label><input name="weekday" type="checkbox" value="7" />
                    周六</label>&nbsp;
                    <label><input type="checkbox" id="weekday" for="weekday" />
                    全选</label>&nbsp;</td>
                  <td valign="top"></td>
                </tr>
              </table></td>
          </tr>
          <tr class="border-top tr_timeloop" style="display:none;">
            <td align="right" valign="top">按日设置：</td>
            <td><table border="0" cellspacing="0" cellpadding="0">
                <tr class="ignore">
                  <td><label><input name="day" type="checkbox" value="1" />
                    01</label>&nbsp;
                    <label><input name="day" type="checkbox" value="2" />
                    02</label>&nbsp;
                    <label><input name="day" type="checkbox" value="3" />
                    03</label>&nbsp;
                    <label><input name="day" type="checkbox" value="4" />
                    04</label>&nbsp;
                    <label><input name="day" type="checkbox" value="5" />
                    05</label>&nbsp;
                    <label><input name="day" type="checkbox" value="6" />
                    06</label>&nbsp;
                    <label><input name="day" type="checkbox" value="7" />
                    07</label>&nbsp;
                    <label><input name="day" type="checkbox" value="8" />
                    08</label>&nbsp;
                    <label><input name="day" type="checkbox" value="9" />
                    09</label>&nbsp;
                    <label><input name="day" type="checkbox" value="10" />
                    10</label>&nbsp;<br />
                    <label><input name="day" type="checkbox" value="11" />
                    11</label>&nbsp;
                    <label><input name="day" type="checkbox" value="12" />
                    12</label>&nbsp;
                    <label><input name="day" type="checkbox" value="13" />
                    13</label>&nbsp;
                    <label><input name="day" type="checkbox" value="14" />
                    14</label>&nbsp;
                    <label><input name="day" type="checkbox" value="15" />
                    15</label>&nbsp;
                    <label><input name="day" type="checkbox" value="16" />
                    16</label>&nbsp;
                    <label><input name="day" type="checkbox" value="17" />
                    17</label>&nbsp;
                    <label><input name="day" type="checkbox" value="18" />
                    18</label>&nbsp;
                    <label><input name="day" type="checkbox" value="19" />
                    19</label>&nbsp;
                    <label><input name="day" type="checkbox" value="20" />
                    20</label>&nbsp;<br />
                    <label><input name="day" type="checkbox" value="21" />
                    21</label>&nbsp;
                    <label><input name="day" type="checkbox" value="22" />
                    22</label>&nbsp;
                    <label><input name="day" type="checkbox" value="23" />
                    23</label>&nbsp;
                    <label><input name="day" type="checkbox" value="24" />
                    24</label>&nbsp;
                    <label><input name="day" type="checkbox" value="25" />
                    25</label>&nbsp;
                    <label><input name="day" type="checkbox" value="26" />
                    26</label>&nbsp;
                    <label><input name="day" type="checkbox" value="27" />
                    27</label>&nbsp;
                    <label><input name="day" type="checkbox" value="28" />
                    28</label>&nbsp;
                    <label><input name="day" type="checkbox" value="29" />
                    29</label>&nbsp;
                    <label><input name="day" type="checkbox" value="30" />
                    30</label>&nbsp;<br />
                    <label><input name="day" type="checkbox" value="31" />
                    31</label>&nbsp;
                    <label><input type="checkbox" id="day" for="day" />
                    全选</label>&nbsp;</td>
                  <td valign="top"></td>
                </tr>
              </table></td>
          </tr>
          <tr class="border-top tr_timeloop" style="display:none;">
            <td align="right" valign="top">按时设置：</td>
            <td><table border="0" cellspacing="0" cellpadding="0">
                <tr class="ignore">
                  <td><label><input name="hour" type="checkbox" value="0" />
                    00</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="1" />
                    01</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="2" />
                    02</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="3" />
                    03</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="4" />
                    04</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="5" />
                    05</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="6" />
                    06</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="7" />
                    07</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="8" />
                    08</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="9" />
                    09</label>&nbsp;<br />
                    <label><input name="hour" type="checkbox" value="10" />
                    10</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="11" />
                    11</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="12" />
                    12</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="13" />
                    13</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="14" />
                    14</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="15" />
                    15</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="16" />
                    16</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="17" />
                    17</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="18" />
                    18</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="19" />
                    19</label>&nbsp;<br />
                    <label><input name="hour" type="checkbox" value="20" />
                    20</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="21" />
                    21</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="22" />
                    22</label>&nbsp;
                    <label><input name="hour" type="checkbox" value="23" />
                    23</label>&nbsp;
                    <label><input type="checkbox" id="hour" for="hour" />
                    全选</label>&nbsp;</td>
                  <td valign="top"></td>
                </tr>
              </table></td>
          </tr>
          <tr class="border-top tr_timeloop" style="display:none;">
            <td align="right">按分设置：</td>
            <td><table border="0" cellspacing="0" cellpadding="0">
                <tr class="ignore">
                  <td><label><input name="minute" type="checkbox" value="0" />
                    00</label>&nbsp;
                    <label><input name="minute" type="checkbox" value="10" />
                    10</label>&nbsp;
                    <label><input name="minute" type="checkbox" value="30" />
                    30</label>&nbsp;
                    <label><input name="minute" type="checkbox" value="50" />
                    50</label>&nbsp;
                    <label><input type="checkbox" id="minute" for="minute" />
                    全选</label>&nbsp;</td>
                  <td valign="top"></td>
                </tr>
              </table></td>
          </tr>
          <tr class="border-top tr_loop tr_timeloop" style="display:none;">
            <td align="right">开始时间：</td>
            <td><input name="startTime" type="text" class="text small ignore" id="startTime" value="${gen:dateTime(cron.startTime, 'yyyy-MM-dd HH:mm:ss', config.timezoneid)}" size="20" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endTime\')||\'2080-12-12 00:00:00\'}'});" />
              <label for="startTime" generated="true" class="ico-tips date-picker"></label></td>
          </tr>
          <tr class="border-top tr_loop tr_timeloop" style="display:none;">
            <td align="right">结束时间：</td>
            <td><input name="endTime" type="text" class="text small ignore" id="endTime" value="${gen:dateTime(cron.endTime, 'yyyy-MM-dd HH:mm:ss', config.timezoneid)}" size="20" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startTime\')}'});" />
              <label for="endTime" generated="true" class="ico-tips date-picker"></label></td>
          </tr>
          <tr class="border-top">
            <td colspan="2" class="push txt-c"><input type="hidden" name="formHash" value="${formHash}"/>
              <input type="hidden" name="id" value="${cron.id}" />
              <input name="submit" class="button blue small" type="submit" value="确 定" />
              &nbsp;&nbsp;&nbsp;&nbsp;
              <input name="reset" class="button gray small" type="reset" value="取 消" /></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<!-- 必备插件 -->
<script type="text/javascript" src="${config.statie}js/jquery.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.form.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.grapes.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.timers.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.mousewheel.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.tablecolor.js"></script>
<!-- 日期插件 -->
<script type="text/javascript" src="${config.statie}js/datePicker/WdatePicker.js"></script>
<!-- 弹窗插件 -->
<script type="text/javascript" src="${config.statie}js/dialog/jquery.dialog.js?self=true"></script>
<script type="text/javascript" src="${config.statie}js/dialog/jquery.dialog.plugins.js"></script>
<!-- 表单验证插件 -->
<script type="text/javascript" src="${config.statie}js/validate/jquery.validate.js"></script>
<script type="text/javascript" src="${config.statie}js/validate/validate.expand.js"></script>
<script type="text/javascript" src="${config.statie}js/validate/messages_zh.js"></script>
<!-- UI界面必备 -->
<script type="text/javascript" src="${config.statie}ui/js/jspgen.js"></script>
<script type="text/javascript" src="${config.statie}ui/js/jspgen.ajax.js"></script>
<script type="text/javascript" src="${config.statie}ui/js/jspgen.ready.js"></script>
<!-- 当前页面 -->
<script type="text/javascript" src="${config.statie}ui/admin/js/cron-input.js"></script>
<script type="text/javascript">
// document.domain = "jspgen.com";

// 调用
$(document).ready(function(){
	// 赋值
	setMode();
	setItem('weekday', '${cron.weekday}');  setItem('day', '${cron.day}'); 
	setItem('hour', '${cron.hour}');  setItem('minute', '${cron.minute}');
	
	// 表单验证
	var $form = $('#form'), $reset = $('input:reset');
	var validate = $form.validate({
		rules: {
			name: {
				required: true
			},
			impl: {
				required: true
			}
		},
		messages: {
			name: {
				required: "任务名称不允许为空！"
			},
			impl: {
				required: "实现类路径不允许为空！"
			}
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit($.extend({
				success: function(result) {
					// {'status':false,'message':'message', 'store':{'id':'id'}}
					if (result) {
						if (result.status) {
							$dialog.success(result.message, function() {
								refleshFromTab(); removeTab();
							});
						}else{
							$dialog.error(result.message);
						}
					}
				}
			}, formOptions));
			
			// 阻止表单默认提交
			return false;
		}
	});
	$reset.bind('click', function () {
		validate.resetForm();
	});
	
	// 参数
	var varTr = '<tr class="ignore">';
		varTr += '<td align="left">参数名：<input name="key[]" type="text" class="text small ignore" value="" size="10" />&nbsp;&nbsp;&nbsp;&nbsp;';
		varTr += '参数值：<input name="value[]" type="text" class="text small ignore" value="" size="35" />&nbsp;&nbsp;&nbsp;&nbsp;';
		varTr += '<a href="javascript:void(0);" class="delete">删除</a></td>';
		varTr += '</tr>';
	// 增加
	$('.var').delegate('a.add', 'click', function () {
		var $temp = $(this).closest('table');
		$temp.append(varTr);
		//$('.table').tablecolor({one: "tr-bg1", two: "tr-bg2", hover: "tr-hover"});
	});
	// 删除
	$('.var').delegate('a.delete', 'click', function () {
		var $temp = $(this).closest('tr');
		$temp.remove();
	});
});
</script>
</body>
</html>
