<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>全网监控智能分析平台</title>
<script type="text/javascript" src="${ctx}/static/js/validation.js"></script>
<script language="javascript">
	$(document).ready(function() {
		/* <c:if test="${allProvince == true}">
			changeAll(true);
		</c:if>*/
		
		<c:if test="${allProvince != true}">
			<c:forEach items="${eWarningRule.provinceList}" var="province">
				$("input:checkbox[name='provinces'][value='${province.provinceId}']").attr('checked','true');
			</c:forEach>
		</c:if> 
		parent.document.all('eWarningRuleFrame').style.height= document.body.scrollHeight + "px";
		getModelByType();
	});

	function submitForm() {
		var url = '${ctx}/BaseManage/EWarningRuleManage/checkNameAndCode';
		var data = 'name=' + $('#name').val() + "&code=" + $('#code').val() + "&id=" + $('#ewarncrteruleId').val();
		if (validate()) {
			$.ajax({
	            type : 'POST',
	            url: url,
	            data:data,
	            success: function(data) {
	            	if(data == '1') {
	            		alert("规则名称已存在");
	            		$('#name').focus();
	            	} else if (data == '2') {
	            		alert("规则代码已存在");
	            		$('#code').focus();
	            	} else if (data == '0'){
						$('#detailForm').submit();
	            	}
	         	}
	     	});
		}
	}

	function validate() {
		if(!checkNameAndCode()) {
			return false;
		}
		if(!isNumber($('#correctRate'))) {
			return false;
		}
		if(!isNumber($('#cycleMinutes'))) {
			return false;
		}
		if(!checkRequired()) {
			return false;
		}
		if(!checkKpi()) {
			return false;
		}
		return true;
	}
	
	function changeAll(checked) {
		if(checked) {
			$(".province").attr("checked","checked");
	        $(".province").attr("disabled",true);
		} else {
			$(".province").attr("checked",false);
	        $(".province").attr("disabled",false);
		}
	}
	
	function changeHeight() {
		parent.document.all('eWarningRuleFrame').style.height= document.body.scrollHeight + "px";
	}
	
	function getModelByType() {
		//alert($("#dataModelType option:selected").val());
		//return false;
		$.ajax({
            type : 'POST',
            url: "${ctx}/BaseManage/EWarningRuleManage/getModelByType",
            data: "dataModelTypeId=" + $("#dataModelType option:selected").val(),
            success: function(data) {
            	//alert(data.length);
            	$('#dataModel').empty();
            	for(var i=0;i<data.length;i++) {
            		var option = new Option(data[i].dataModelName,data[i].dataModelId);
            		$('#dataModel').append(option);            		
            	}
            	<c:if test="${not empty eWarningRule.dataModel}">
	    			$("#dataModel").val('${eWarningRule.dataModel.dataModelId}');
	    		</c:if>
         	}
     	});
	}
</script>
</head>
<body>
	<div class="col-xs-12" style="padding-top: 20px;">
		<form id="detailForm" class="form-horizontal" role="form"
			action="${ctx}/BaseManage/EWarningRuleManage/submitEWarningRuleFrame" method="post">
			<input type="hidden" name="ewarncrteruleId" id="ewarncrteruleId" value="${eWarningRule.ewarncrteruleId}">
			<div class="form-group">
					<label class="col-sm-2 control-label">规则名称(<font color="red">必填</font>):</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="name" name="name" value="${eWarningRule.name}" maxlength="33">
				</div>
					<label class="col-sm-2 control-label">规则代码(<font color="red">必填</font>):</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="code" name="code" value="${eWarningRule.code}" maxlength="100">
				</div>
			</div>
			
			<div class="form-group">
					<label class="col-sm-2 control-label">预警消除规则:</label>
				<div class="col-xs-2">
					<select class="form-control" name="eWarningDropRule.eWarningDropRuleId" id="eWarningDropRuleId">
						<c:forEach items="${eWarningDropRuleList}" var="eWarningDropRule">
							<option value="${eWarningDropRule.eWarningDropRuleId}" 
								<c:if test="${eWarningDropRule.eWarningDropRuleId == eWarningRule.eWarningDropRule.eWarningDropRuleId}">selected</c:if> >${eWarningDropRule.name}</option>
						</c:forEach>
					</select>
				</div>
					<label class="col-sm-2 control-label">预警发生场景:</label>
				<div class="col-xs-2">
					<select class="form-control" name="eWarningSence.ewarnsenceId" id="ewarnsenceId">
						<c:forEach items="${eWarningSenceList}" var="eWarningSence">
							<option value="${eWarningSence.ewarnsenceId}"
								<c:if test="${eWarningSence.ewarnsenceId == eWarningRule.eWarningSence.ewarnsenceId}">selected</c:if>  >${eWarningSence.name}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">规则类型:</label>
				<div class="col-xs-2">
					<select class="form-control" name="ruleType" id="ruleType">
							<option value="1" <c:if test="${eWarningRule.ruleType == '1'}">selected</c:if>  >平台</option>
							<option value="2" <c:if test="${eWarningRule.ruleType == '2'}">selected</c:if>  >Capes</option>
							<option value="3" <c:if test="${eWarningRule.ruleType == '3'}">selected</c:if>  >网络流量</option>
					</select>
				</div>
				<label class="col-sm-2 control-label">准确率:</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="correctRate" name="correctRate" value="${eWarningRule.correctRate}" maxlength="10">
				</div>
				
			</div>
			
			<div class="form-group">
				<div><label class="col-sm-2 control-label">生效时间(<font color="red">必填</font>):</label></div>
				<div class="col-xs-2">
					<input type="input" title="生效时间" class="form-control Wdate required" id="validTime" name="validTimeStr" value="${eWarningRule.validTime}"
						onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:false,maxDate:'#F{$dp.$D(\'invalidTime\');}'})">
				</div>
				<label class="col-sm-2 control-label">失效时间(<font color="red">必填</font>):</label>
				<div class="col-xs-2">
					<input type="input" title="失效时间" class="form-control Wdate required" id="invalidTime" name="invalidTimeStr" value="${eWarningRule.validTime}"
						onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:false,minDate:'#F{$dp.$D(\'validTime\');}'})">
				</div>
			</div>
			
			<div class="form-group">
					<label class="col-sm-2 control-label">模型类型:</label>
				<div class="col-xs-2">
					<select class="form-control" name="dataModelType.dataModelTypeId" id="dataModelType" onchange="getModelByType()">
						<c:forEach items="${dataModelTypeList}" var="dataModelType">
							<option value="${dataModelType.dataModelTypeId}"
								<c:if test="${dataModelType.dataModelTypeId == eWarningRule.dataModelType.dataModelTypeId}">selected</c:if> >${dataModelType.dataModelTypeName}</option>
						</c:forEach> 
					</select>
				</div>
					<label class="col-sm-2 control-label">关联模型:</label>
				<div class="col-xs-2">
					<select class="form-control" name="dataModel.dataModelId" id="dataModel">
						
					</select>
				</div>
			</div>
			
			<div class="form-group">
					<label class="col-sm-2 control-label">时间间隔长度:</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="cycleMinutes" name="cycleMinutes" value="${eWarningRule.cycleMinutes}"  maxlength="10">
				</div>
					<label class="col-sm-2 control-label">统计时长:</label>
				<div class="col-xs-2">
					<select class="form-control" name="period.statisticstimeId" id="ewarningsenceId">
						<c:forEach items="${periodList}" var="period">
							<option value="${period.statisticstimeId}"
								<c:if test="${period.statisticstimeId == eWarningRule.period.statisticstimeId}">selected</c:if> >${period.name}</option>
						</c:forEach> 
					</select>
				</div>
			</div>
			
			<div class="form-group">
					<label class="col-sm-2 control-label">高于阀值等级次数:</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="thresholdhighStr" name="thresholdhighStr" value="${eWarningRule.thresholdhighStr}" maxlength="100">
				</div>
					<label class="col-sm-2 control-label">低于阀值等级次数:</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="thresholdunderStr" name="thresholdunderStr" value="${eWarningRule.thresholdunderStr}" maxlength="100">
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">是否可以手工关闭:</label>
				<div class="col-xs-2">
					<input type="checkbox" name="manucloseFlg" value="1" <c:if test="${eWarningRule.manucloseFlg == '1'}">checked</c:if> >
				</div>
			</div>
			
			<div class="form-group">
					<label class="col-sm-2 control-label">预警计算公式(<font color="red">必填</font>):</label>
				<div class="col-xs-5">
					<textarea id="calculateStr" name="calculateStr" title="预警计算公式" class="form-control input-large required" required="true" rows="6" maxlength="1333">${eWarningRule.calculateStr}</textarea>
				</div>
			</div>
			
			<div class="form-group">
					<label class="col-sm-2 control-label">变量计算公式:</label>
				<div class="col-xs-5">
					<textarea id="calculateResdata" name="calculateResdata" class="form-control input-large" rows="6" maxlength="1333">${eWarningRule.calculateResdata}</textarea>
				</div>
			</div>
			
			
			
			<tags:WARN_PROVINCE />

			<tags:WARN_KPI_NEW />
			
			 <div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" id="modelSubmit" class="btn btn-primary" onclick="saveForm('ewarncrteruleId');">确定</button>
					<!-- <button type="reset" class="btn btn-default" id="modelReset">清空</button> -->
					<button type="reset" class="btn btn-warning" id="modelBack" onclick="window.location.href='${ctx}/BaseManage/EWarningRuleManage/eWarningRuleListFrame'">返回</button>
				</div>
			</div>
		</form>
	</div>
</body>
</html>