<%@ 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}">
			changeAllProvince(true);
		</c:if>*/
		
		<c:if test="${allProvince != true}">
			<c:forEach items="${hWarningRule.provinceList}" var="province">
				$("input:checkbox[name='provinces'][value='${province.provinceId}']").attr('checked','true');
			</c:forEach>
		</c:if> 

		
		/* <c:if test="${allDataSource == true}">
			changeAllDataSource(true);
		</c:if>
		
		<c:if test="${allBusiness == true}">
			changeAllBusiness(true);
		</c:if>
		
		<c:if test="${allKpi == true}">
			changeAllKpi(true);
		</c:if> */
		parent.document.all('hWarningRuleFrame').style.height= document.body.scrollHeight + "px";
		getModelByType();
	});

	function submitForm() {
		var url = '${ctx}/BaseManage/HWarningRuleManage/checkNameAndCode';
		var data = 'name=' + $('#name').val() + "&code=" + $('#code').val() + "&id=" + $('#hwarningruleId').val();
		checkAndSubmit(url, data);
	}

	function validate() {
		if(!checkNameAndCode()) {
			return false;
		}
		if(!isNumber($('#correctRate'))) {
			return false;
		}
		if(!isFloat($('#threshold1Value'), 37)) {
			return false;
		}
		if(!isFloat($('#threshold2Value'), 37)) {
			return false;
		}
		if(!isFloat($('#threshold3Value'), 37)) {
			return false;
		}
		if(!isFloat($('#threshold4Value'), 37)) {
			return false;
		}
		if(!isFloat($('#threshold5Value'), 37)) {
			return false;
		}
		if(!checkKpi()) {
			return false;
		}
		return true;
	}
	
	function changeHeight() {
		parent.document.all('hWarningRuleFrame').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 hWarningRule.dataModel}">
	    			$("#dataModel").val('${hWarningRule.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/HWarningRuleManage/submitHWarningRuleFrame" method="post">
			<input type="hidden" id="hwarningruleId" name="hwarningruleId" value="${hWarningRule.hwarningruleId}">
			<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="${hWarningRule.name}">
				</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="${hWarningRule.code}">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">隐患发生场景</label>
				<div class="col-xs-2">
					<select class="form-control" name="hWarningSence.hwarningsenceId" id="hwarningsenceId">
						<c:forEach items="${hWarningSenceList}" var="hWarningSence">
							<option value="${hWarningSence.hwarningsenceId}"
								<c:if test="${hWarningSence.hwarningsenceId == hWarningRule.hWarningSence.hwarningsenceId}">selected</c:if>>${hWarningSence.name}</option>
						</c:forEach>
					</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="${hWarningRule.correctRate}" maxlength="10">
				</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 Wdate" id="validbeginTime" name="validbeginTimeStr"
						value="${hWarningRule.validbeginTime}"
						onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:false,maxDate:'#F{$dp.$D(\'validendTime\');}'})">
				</div>
				<label class="col-sm-2 control-label">失效时间</label>
				<div class="col-xs-2">
					<input type="input" class="form-control Wdate" id="validendTime" name="validendTimeStr"
						value="${hWarningRule.validendTime}"
						onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:false,minDate:'#F{$dp.$D(\'validbeginTime\');}'})">
				</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="threshold1Value" name="threshold1Value"
						value="${hWarningRule.threshold1Value}" maxlength="43">
				</div>
				<label class="col-sm-2 control-label">阀值二</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="threshold2Value" name="threshold2Value"
						value="${hWarningRule.threshold2Value}" maxlength="43">
				</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="threshold3Value" name="threshold3Value"
						value="${hWarningRule.threshold3Value}" maxlength="43">
				</div>
				<label class="col-sm-2 control-label">阀值四</label>
				<div class="col-xs-2">
					<input type="input" class="form-control" id="threshold4Value" name="threshold4Value"
						value="${hWarningRule.threshold4Value}" maxlength="43">
				</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="threshold5Value" name="threshold5Value"
						value="${hWarningRule.threshold5Value}" maxlength="43">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">隐患描述</label>
				<div class="col-xs-6">
					<textarea id="calculateStr" name="hwarningDesc" class="form-control input-large" rows="6" maxlength="33">${hWarningRule.hwarningDesc}</textarea>
				</div>
			</div>

			<tags:WARN_PROVINCE />

			<tags:WARN_KPI_NEW />

			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-5">
					<button type="button" id="modelSubmit" class="btn btn-primary" onclick="saveForm('hwarningruleId');">确定</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/HWarningRuleManage/hWarningRuleListFrame'">返回</button>
				</div>
			</div>
		</form>
	</div>
</body>
</html>