<%@ 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"%>
<base href="<%=basePath%>">
<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>
<script>
	var javaEditor;
	$(document).ready(function() {
		 javaEditor = CodeMirror.fromTextArea(document.getElementById("script"), {
			  lineNumbers: true,
			  matchBrackets: true,
			  //indentWithTabs: true,
			 // styleActiveLine: true,
			  theme:"eclipse",
			 // smartIndent: true,
			 // autofocus: true,
			  mode: "text/x-java"
		});
		$("#submitButton").click(function() {
			//用jquery中的ajax方法，向服务器提交请求 
			//setMask("main-container");
			$("#script").val(javaEditor.getValue());
			jQuery.ajax({
				type : "POST",
				url : "${ctx}/actInfo/otherTask/editScriptTask.do",
				data : $('#myform').serialize(),
				success : function(resp) {
					alert(resp);
					art.dialog.close();
				}
			});
		});
		
	});
	
	
	function validate(){
		var ruleScript=javaEditor.getValue();;
		if(ruleScript==""){
			alert("脚本内容不允许为空,请您重新输入！");
			return ;
		}
		var url="${ctx}/actInfo/activityRule/validate.do?ruleScript="+ruleScript;
		showDiaLog(url, '验证脚本', '600px', '300px');
	}
</script>
<title>脚本编辑</title>
</head>
<body class="white-page">
	<form action="${ctx}/actInfo/otherTask/editScriptTask.do" method="post"
		id="myform">
		<div class="main-container" id="main-container">
			<div class="panel panel-primary">

				<div class="panel-body">
					<table class='table table-bordered form-table' border="0" cellspacing="0"
						cellpadding="0" id="myTable">
						<!-- 存放隐藏域的区域 -->
						<input type="hidden" name="activityDefId"
							value="${activityInfoConfig.activityDefId}" />
						<input type="hidden" name="activityDefName"
							value="${activityInfoConfig.activityDefName}" />
						<input type="hidden" name="processDefId"
							value="${activityInfoConfig.processDefId}" />
						<input type="hidden" name="processDefName"
							value="${activityInfoConfig.processDefName}" />
						<input type="hidden" name="scriptFormat" value="groovy" />
						<!-- 存放隐藏域的区域 -->
						<input type="hidden" id="id" name="id" value="${scriptTask.id}" />
						<!-- 存放表单的区域 -->
						<tr>
							<td width="20%">环节ID<font color="red">*</font>：
							</td>
							<td><input  type="text" name="name"
								value="${scriptTask.id}" id="name" /></td>
						</tr>
						<tr>
							<td>环节名称<font color="red">*</font>：
							</td>
							<td><input style="width: 300px;" type="text" name="name"
								value="${scriptTask.name}" id="name" /></td>
						</tr>
						<tr>
							<td>脚本内容<font color="red">*</font>：
							</td>
							<td><a href="javascript:void(0);" onclick="validate();">验证脚本</a>
								<br /> <textarea name="script" id="script">${scriptTask.script}</textarea> <br />这个脚本需要使用返回语句(return)返回布尔值，返回true流程将跳转到指定的节点。</td>
						</tr>
						<tr>
							<td>备注：</td>
							<td><textarea style="width: 600px; height: 80px"
									name="documentation" id="documentation"></textarea></td>
						</tr>
					</table>
					<div class="col-md-offset-1 col-md-9" style="text-align: center;">
						<button id="submitButton" class="btn btn-sm btn-primary"
							name="submitButton" type="button">
							<span class="icon_save">保存</span>
							<i class="ace-icon fa fa-save bigger-110"></i>
						</button>
						<button type="button" class="btn btn-sm btn-primary"
							onclick="art.dialog.close()">
							<span class="icon_back">关闭</span>
						</button>

					</div>
				</div>
			</div>
		</div>
	</form>
</body>
</html>