  <%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.blueland.bpm.engine.config.model.*" %>
<%@ include file="/commons/taglibs.jsp"%>
<%
	String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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">
<%@ include file="/commons/meta.jsp"%>
<link rel="stylesheet" href="${ctx}/resource/js/plugins/codemirror/codemirror.css">
<link rel="stylesheet" href="${ctx}/resource/js/plugins/codemirror/eclipse.css">
<style>
.CodeMirror {
  /* Set height, width, borders, and global font properties here */
  font-family: monospace;
  height: 180px;
}
</style>
<script src="${ctx}/resource/js/plugins/codemirror/codemirror.js"></script>
<script src="${ctx}/resource/js/plugins/codemirror/clike.js"></script>
<base href="<%=basePath%>">
<title>流程环节规则表新增</title>
<script>
	var demo;
	var ischeck = true;
	var javaEditor;
	$(document).ready(function() {
		 javaEditor = CodeMirror.fromTextArea(document.getElementById("ruleScript"), {
			  lineNumbers: true,
			  matchBrackets: true,
			  //indentWithTabs: true,
			 // styleActiveLine: true,
			  theme:"eclipse",
			 // smartIndent: true,
			 // autofocus: true,
			  mode: "text/x-java"
		});
		 
		 demo = $("#myForm").Validform({
			 tiptype:function(msg,o,cssctl){
				var b = true;
				//msg：提示信息;
				//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
				//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
				if(o.type==3){
					if(msg.indexOf("statusText")<0){
					//排除掉提交完成后返回的状态字符串
						alert(msg);
						ischeck = false;
						b = false;
						return b;
					}
				}
				return b;
			},
			ajaxPost:true,
			beforeSubmit:function(curform){
				return false;
			}
		 });

	});
	function editActivityRule(ruleId){
		var url="${ctx}/actInfo/activityFinishRule/getActivityRule.do?ruleId="+ruleId;
		$.post(url,function(result){
			   var jsonObject = eval(result);
			   $.each(jsonObject, function(name, value) {
		        	if(name=="ruleScript"){
		        		javaEditor.setValue(value);
		        	}else{
				   		var inputObj=$("#"+name);
				   		if(inputObj.attr("type")!="hidden"||name=="ruleId"){
		        			inputObj.val(value);
				   		}
		        	}
		       });
		});
	}
	function update(){
		if($("#ruleId").val()==""){
			alert("该规则没有在数据库中,请点击规则列表后再进行更新！");
			return;
		}
		var ruleScript = javaEditor.getValue();
		if(""==ruleScript){
			alert("验证脚本不能为空！");
			return ;
		}
		demo.ajaxPost();
		if(ischeck){//如果通过验证
			document.getElementById("myForm").action="${ctx}/actInfo/activityFinishRule/update.do";
			document.getElementById("myForm").submit();	
		}
	}
	function create(){
		var ruleScript = javaEditor.getValue();
		if(""==ruleScript){
			alert("验证脚本不能为空！");
			return ;
		}
		demo.ajaxPost();
		if(ischeck){//如果通过验证 
			document.getElementById("myForm").action="${ctx}/actInfo/activityFinishRule/save.do";
			document.getElementById("myForm").submit();
		}
	}
	
	function validate(){
		var ruleScript=javaEditor.getValue();;
		if(ruleScript==""){
			alert("规则脚本不允许为空,请您重新输入！");
			return ;
		}
		var url="${ctx}/actInfo/activityFinishRule/validate.do?ruleScript="+ruleScript;
		showDiaLog(url,'验证规则脚本','600px','300px');
	}

</script>
</head>
<body class="white-page">
	
	<form id="myForm" action="${ctx}/actInfo/activityFinishRule/save.do" method="post">
			
			<div class="main-container" id="main-container">
			<div class="panel panel-primary">
				<div class="panel-body">
					<div class="well well-sm">
							<button id="addButton" name="submitButton" type="button" onclick="create();" class="btn btn-xs btn-success">
				新  增
				<i class="ace-icon fa fa-plus bigger-110"></i>
			</button>
			<button id="updateButton" name="submitButton" type="button" onclick="update();" class="btn btn-xs btn-success">
				更  新
				<i class="ace-icon fa fa-pencil bigger-110"></i>
			</button>
			<button type="button" onclick="art.dialog.close();" class="btn btn-xs btn-danger">
				关  闭
				<i class="ace-icon fa fa-times bigger-110"></i>
			</button>
					</div>
					
					<table class='table table-bordered form-table' border="0" cellspacing="0"
						cellpadding="0" id="myTable">
				<input  type="hidden" name="ruleType" value="${activityRule.ruleType}" id="ruleType"/>		
				<input  type="hidden" name="ruleId" value="${activityRule.ruleId}" id="ruleId"/>
				<input  type="hidden" name="procDefId" value="${activityRule.procDefId}" id="procDefId"/>
				<input  type="hidden" name="sourceActId" value="${activityRule.sourceActId}" id="sourceActId"/>
				<input  type="hidden" name="sourceActName" value="${activityRule.sourceActName}" id="sourceActName"/>
				<input  type="hidden" name="targetActId" value="${activityRule.targetActId}" id="targetActId"/>
				<input  type="hidden" name="targetActName" value="${activityRule.targetActName}" id="targetActName"/>
				<!-- 存放表单的区域 -->
				<tr>
					<td>当前环节<font color="red">*</font>：</td>
					<td colspan="3">${activityRule.sourceActName}</td>
				</tr>
				<tr>
					<td>规则名称<font color="red">*</font>：</td>
					<td colspan="3"><input style="width: 250px" type="text" name="ruleName" value="${activityRule.ruleName}" id="ruleName"
					nullmsg="请填写规则名称"  datatype="*"/></td>
				</tr>
				<tr>
					<td>规则脚本<font color="red">*</font>：</td>
					<td  colspan="3">
						<!-- <a href="javascript:void(0);" onclick="">常用脚本</a>&nbsp;&nbsp;-->
						<a href="javascript:void(0);" onclick="validate();">验证脚本</a>
						<br/>
						<textarea   name="ruleScript"  id="ruleScript" style="width: 700px;height: 50px">${activityRule.ruleScript}</textarea>
						<br/>
						环节跳转规则通过groovy脚本定义流程转向，开发人员通过控制脚本返回一个布尔值，返回值为true时流程将流向目标环节。
					</td>
				</tr>
				<tr>
					<td>规则描述：</td>
					<td  colspan="3"><textarea style="width: 700px;height: 50px"  name="ruleRemark" id="ruleRemark">${activityRule.ruleRemark}</textarea></td>
				</tr>
			</table>
			
			<IFRAME style="width:100%;height:180px;" scrolling="auto" src="${ctx}/actInfo/activityFinishRule/list.do?procDefId=${activityRule.procDefId}&sourceActId=${activityRule.sourceActId}&targetActId=${activityRule.targetActId}"  frameBorder="0" id="rightFrame"  name="rightFrame"   allowTransparency="true"></IFRAME> 
		</div>
			</div>
		</div>
	</form>
	
</body>
</html>

