  <%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.blueland.bpm.engine.config.model.*" %>
<%@ include file="/commons/taglibs.jsp"%>
<jsp:include page="/commons/userOrgTree.jsp" flush="false" />
<%
	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>

	function createActUser(retValus,retNames){
		if(""!=retValus){
			var arr = retValus.split("#");
			retValus = arr[1];
		}
		$("#mandataryUserName").val(retNames);
		$("#mandataryUserId").val(retValus);
	}
	
	function processDefNameOnDbClick(name,id){
		$("#processDefName").val(name);
		$("#processDefId").val(id);
	}
	
	function mandataryUserNameOnDbClick(name,id){
		$("#mandataryUserName").val(name);
		$("#mandataryUserId").val(id);
	}
	function processDefSel(){
		var deputeType = $('input:radio[name="deputeType"]:checked').val();
		if(deputeType=="local"){
			$("#processDefName").attr("datatype","*");
			$("#processDefName").attr("value","请您选择流程定义！");
			
			$("#processDefName").val($("#curSelProcessSName").val());
			$("#processDefId").val($("#curSelProcessSId").val());
			
			$("#processDefName").show();
			$("#processDefNameButton").show();
		}else{
			$("#processDefName").removeAttr("datatype");
			$("#processDefName").removeAttr("value");
			
			$("#processDefName").val("");
			$("#processDefId").val("");
			
			$("#processDefName").hide();
			$("#processDefNameButton").hide();
		}
	}
	
	$(function(){
		processDefSel();		
	})
	
	function checkBeforeSubmit(){
		var mandataryUserId = $("#mandataryUserId").val();
		if(null == mandataryUserId || ""==mandataryUserId){
			alert("请您选择被委托人员！");
			$("#mandataryUserName").focus();
			return false;
		}
		var startTimeString = $("#startTimeString").val();
// 		if(null == startTimeString || ""==startTimeString){
// 			alert("请您选择起始时间！");
// 			$("#startTimeString").focus();
// 			return false;
// 		}
// 		var endTimeString = $("#endTimeString").val();
// 		if(null == endTimeString || ""==endTimeString){
// 			alert("请您选择结束时间！");
// 			$("#endTimeString").focus();
// 			return false;
// 		}
		var processDefId = $("#processDefId").val();
		var deputeType = $('input:radio[name="deputeType"]:checked').val();
		if(deputeType=='local'){
			
			if(null==processDefId || ""==processDefId){
				alert("请您选择流程定义！");
				$("#processDefName").focus();
				return false;
			}
		}
		
		return true;
	}
	
	function saveDepute(){
		var ischeck = checkBeforeSubmit();
		if(ischeck){
			$.post('${ctx}/depute/update.do',
					$('#editForm').serialize(),
			function(result){
				if(result.success){
					alert("保存成功！");
					art.dialog.opener.location.reload();
				}else{
					alert("保存失败！");
				}
			});
		}
	}
	//日历图标模拟日历文本框点击事件
	$(function(){
		var startTimeString = document.getElementById("startTimeString");
		var startTime = document.getElementById("startTime");
		var endTimeString = document.getElementById("endTimeString");
		var endTime = document.getElementById("endTime");
		//通用方法
		startTime.onclick = function() {
		   if (/msie/i.test(navigator.userAgent)) //IE
		   {
			   startTimeString.fireEvent("onclick");
		   } else {
		      var e = document.createEvent('MouseEvent');
		      e.initEvent('click', false, false);
		      startTimeString.dispatchEvent(e);
		   }
		}
		//通用方法
		endTime.onclick = function() {
		   if (/msie/i.test(navigator.userAgent)) //IE
		   {
			   endTimeString.fireEvent("onclick");
		   } else {
		      var e = document.createEvent('MouseEvent');
		      e.initEvent('click', false, false);
		      endTimeString.dispatchEvent(e);
		   }
		}
	})
</script>
<title>委托代办编辑</title>
</head>
<body style="font-size: 13px;" class="white-page">
	<form action="${ctx}/depute/update.do" method="post" id="editForm">
	<input type="hidden" name="deputeUserId" value="${bpm_login_session_user.userId}" id="deputeUserId" />
		<input type="hidden" id="curSelProcessSName" value="${depute.processDefName}"/>
		<input type="hidden" id="curSelProcessSId" value="${depute.processDefId}"/>
		
		<input type="hidden" name="deputeId" value="${depute.deputeId}"/>
		<input type="hidden" name="deputeUserName" value="${bpm_login_session_user.userName}" id="deputeUserName" />
		<input type="hidden" name="deputeStatus" value="Y" id="deputeStatus" />
		<input type="hidden" name="appId" value="${application.appId}" id="appId" />
		<input type="hidden" name="appName" value="${application.appName}" id="appName" />
		<div class="main-container" id="main-container">
			<div class="panel panel-primary">
				<div class="panel-body">
					<table class='table table-bordered' border="0" cellspacing="0"
						cellpadding="0" id="myTable">
				<!-- 存放表单的区域 -->
				<tr>
					<td>委托类型<font color="red">*</font>：</td>
					<td>
						<input type="radio" name="deputeType" value="golal" 
						${depute.deputeType=='golal'?'checked':''}
						id="deputeType" class="othfld" onclick="processDefSel();"/>全局
						<input type="radio" onclick="processDefSel();"
						${depute.deputeType=='local'?'checked':''}
						name="deputeType" value="local" id="deputeTypeProcess" class="othfld"/>按流程
						&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="text"  class="othfld" onclick="showMenu('processDefName','2043000153','','USER'); return false;"
						name="processDefName" id="processDefName" 
						value="${depute.processDefName}"
						datatype="*1-12" "/>
						<input type="hidden" name="processDefId" value="${depute.processDefId}" id="processDefId" />
						<a class="blue" id="processDefNameButton" href="javascript:void(0);">											
							<i class="ace-icon fa fa-search bigger-130" 
								onclick="showMenu('processDefName','2043000153','','USER');return false;">
							</i>
						</a>
					</td>
				</tr>
				
				<tr>
					<td>被委托人<font color="red">*</font>：</td>
					<td><input  type="text" name="mandataryUserName" 
					onclick="showUserOrg('mandataryUserName','${userId}','','USER'); return false;"
					value="${depute.mandataryUserName}" id="mandataryUserName"
					datatype="*1-12" nullmsg="请选择被委托人！"/>					
					<input type="hidden" name="mandataryUserId" value="${depute.mandataryUserId}" id="mandataryUserId" />	
						<a class="blue" href="javascript:void(0);">											
							<i class="ace-icon fa fa-search bigger-130" 
								onclick="showUserOrg('mandataryUserName','${userId}','','USER'); return false;">
							</i>							
						</a>				
					</td>
				</tr>
				<!-- 				
				<tr>
					<td>起止时间<font color="red">*</font>：</td>
					<td>
						从
						<input  type="text" id="startTimeString" name="startTimeString" readOnly
						value="${depute.startTimeString}" datatype="*1-12" nullmsg="请选择起始时间！"/>
						<a id="startTime" class="blue" href="javascript:;"><i class="fa fa-calendar bigger-130"></i></a>&nbsp;&nbsp;
						至
						<input  type="text" 
						onclick="WdatePicker({dateFmt:'<%=Depute.FORMAT_END_TIME%>',minDate:'#F{$dp.$D(\'startTimeString\')}'})"
						id="endTimeString" name="endTimeString"
						value="${depute.endTimeString}"
						datatype="*1-12" nullmsg="请选择结束时间！"/>
						<a id="endTime" class="blue" href="javascript:;">
							<i class="fa fa-calendar bigger-130"></i>
						</a>
					</td>
				</tr>
				 -->
				<tr>
					<td width="20%">委&nbsp;托&nbsp; 人<font color="red">*</font>：</td>
					<td>${bpm_login_session_user.userName}</td>
				</tr>
			</table>
			<div class="col-md-offset-1 col-md-9" style="text-align: center;margin-top: 20px;">
						<button id="submitButton" name="submitButton" class="btn btn-sm btn-primary" 
						type="button"
						onclick="saveDepute();">
							<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>
							<i class="ace-icon fa fa-times bigger-110"></i>
						</button>
					</div>
				</div>
			</div>
		</div>
	</form>
	<jsp:include page="../procDefMgr/procDefTree.jsp" flush="false" />
</body>
</html>