<%@page import="org.activiti.engine.repository.ProcessDefinition" %>
<%@page import="com.blueland.bpm.engine.core.model.*" %>
<%@page import="org.activiti.engine.repository.Deployment" %>
<%@page import="com.blueland.bpm.engine.config.model.*" %>
<%@page import="com.blueland.bpm.common.page.*" %>
<%@page import="com.blueland.bpm.common.util.*"%>
<%@page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib tagdir="/WEB-INF/tags/simpletable" prefix="simpletable"%>
<%@ 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">
<head>
	<%@ include file="/commons/meta.jsp" %>
	<base href="<%=basePath%>">
	<title>流程任务迁移管理</title>
	<link href="${ctx_js_plugins}/simpletable/simpletable.css" type="text/css" rel="stylesheet">
	<script type="text/javascript" src="${ctx_js_plugins}/simpletable/simpletable.js"></script>
	<link href="${ctx}/resource/js/plugins/loadmask/jquery.loadmask.css" rel="stylesheet" type="text/css" />
	<script type='text/javascript' src='${ctx}/resource/js/plugins/loadmask/jquery.loadmask.js'></script> 

	<script type="text/javascript" >
		$(document).ready(function() {
			// 分页需要依赖的初始化动作
			window.simpleTable = new SimpleTable('queryForm','${page.thisPageNumber}','${page.pageSize}','${pageRequest.sortColumns}');
// 			if(${dataType==0}){
// 				$("#qbqyBtn").attr("disabled", false);
// 			}else{
// 				$("#qbqyBtn").attr("disabled", true);
// 			}
		});
		function assigneeNameOnDbClick(name, value) {
			$("#assigneeName").val(name);
			$("#assignee").val(value);
		}
		function transferUserNameOnDbClick(name, value) {
			$("#transferUserName").val(name);
			$("#transferUserId").val(value);
		}
		function taskTransfer(myUrl,transferDatatype){
			//alert(myUrl);
			var chk_value =[]; 
			if(transferDatatype=="0"){
				$("input[name='taskIds']:checkbox:checked").each(function(){ 
					chk_value.push($(this).val());
				})
				if(chk_value.length==0){
					alert("请选择一条流程数据！");
					return;
				}
			}
			if($("#transferUserId").val()==""){
				alert("迁移的目标人员不能为空！");
				return;
			}
			if(transferDatatype=="1"&&$("#assignee").val()==""){
				alert("选择全部待办迁移时任务执行人不能为空！");
				return;
			}
			$("#transferDatatype").val(transferDatatype);
			if (confirm("您确认要将该用户的待办数据做迁移吗？")) {
				setMask("main-container");
				jQuery.ajax({
					url: myUrl,
					data: $('#queryForm',document).serialize(),
					type: "POST",
					success: function(resp)
					{
						alert(resp);
						if(resp=='操作成功'){
							document.getElementById("queryForm").submit();
						}
					}
				});
			}
		}
		
		function changeRadio(btn){
			try{
				$("#transferUserName").val(null);
				$("#transferUserId").val(null);
				$("#assigneeName").val(null);
				$("#assignee").val(null);
			}catch(e){}
			document.getElementById("queryForm").submit();
		}
		
	</script>
</head>
<body>
	<%@ include file="/commons/messages.jsp" %>
	<form id="queryForm" name="queryForm" action="${ctx}/taskMgr/taskTransferList.do" method="post" style="display: inline;">
			<div class="main-container" id="main-container">
		<div class="panel panel-primary">
			<div class="panel-heading">
				<h8>流程待办迁移</h8>
			</div>
			<div class="panel-body">
				<div class="form-group well well-sm" style="margin-bottom: 2px;">

				<table border="0" cellspacing="0" cellpadding="0"
					class="table-search">
					<tr>
						<input value="" type="hidden" id="transferDatatype" name="transferDatatype"/>
						<c:if test="${dataType==0 }">
						<td>任务执行人：</td>		
						<td>
							<input value="${assigneeName}" id="assigneeName" name="assigneeName" maxlength="30" onclick="showUserOrg('assigneeName','43','','USER'); return false;" readonly />
							<input value="${assignee}" type="hidden" id="assignee" name="assignee" maxlength="30"  />
						</td>
						<td>
						<button type="submit" class="btn btn-xs btn-primary">
									查&nbsp;&nbsp;询
									<i class="ace-icon fa fa-search bigger-110"></i>
							</button>
						</td>
						</c:if>
						<td>迁移的目标人员：</td>		
						<td>
							<input value="${transferUserId}" type="hidden" id="transferUserId" name="transferUserId" maxlength="30"  />
							<input value="${transferUserName}" id="transferUserName" name="transferUserName" maxlength="30"  onclick="showUserOrg('transferUserName','43','','USER'); return false;" readonly/>
						</td>
						<td>
							<c:if test="${dataType==0 }">
							<button id="qbqyBtn" type="button" onclick="taskTransfer('${ctx}/taskMgr/taskTransfer.do','1');" class="btn btn-xs btn-success">
									全部待办迁移
									<i class="ace-icon fa fa-stack-exchange bigger-110"></i>
							</button>
							</c:if>
							<button type="button" onclick="taskTransfer('${ctx}/taskMgr/taskTransfer.do','0');" class="btn btn-xs btn-success">
									选择待办迁移
									<i class="ace-icon fa fa-exchange bigger-110"></i>
							</button>
						</td>
					</tr>	
					<tr>
						<td colspan="5">
							<div>
							<input type="radio" style="margin:0px;height:10px;width: 10px" value="1" name="dataType" id="dataType" checked ${dataType==1?'checked':'' } onchange="changeRadio(this);"/>
							组织机构ID无法匹配数据&nbsp;&nbsp;
							<input type="radio" style="margin:0px;height:10px;width: 10px" value="0" name="dataType" id="dataType" ${dataType==0?'checked':'' } onchange="changeRadio(this);"/>
							正常数据&nbsp;&nbsp;</div>
						</td>
					</tr>
					
				</table>
			</div>
			<div class="row">
					<div class="col-xs-12">
						<div class="table-responsive">
							<div style="width: 100%;overflow: auto;">
							<table  style=" width: inherit;max-width: 600%;table-layout: fixed;" id="sample-table-1"
								class="table table-striped table-bordered table-hover">
								<thead>
				  <tr>
					  <!-- 排序时为th增加sortColumn即可,new SimpleTable('sortColumns')会为tableHeader自动增加排序功能; -->
					  <th style="width: 20px"><input type="checkbox"
								  onclick="setAllCheckboxState('taskIds',this.checked)"></th>
					  <th style="width: 150px;">流程定义名称</th>
					  <th >流程标题</th>
					  <th >当前环节</th>
					  <th >执行人(老组织机构)</th>
					  <c:if test="${dataType==0}">
						  <th >发送人</th>
					  </c:if>
					  <c:if test="${dataType!=0}">
						  <th >执行人(新组织机构)</th>
					  </c:if>
					  <th style="width: 150px">接收时间</th>


				  </tr>
		</thead>
<tbody>
		  
				   <%
				   Page mypage=(Page)request.getAttribute("page");
				   List<ActivityInstanceModel> tasks=mypage.getResult();
			  				   	
			  				   	  	  	
			  				   	  	  		if(tasks!=null){
			  				   	  	  		for(int i=0;i<tasks.size();i++){
			  				   	  	  	ActivityInstanceModel task=(ActivityInstanceModel)tasks.get(i);
			  				   	  	  	
			  				   %>
				 <tr class="<%=((i+1)%2== 0 ? "odd" : "even") %>">
					<td><input type="checkbox"  id="taskIds"  name="taskIds" value="<%=task.getActInstId()%>"></td>
					<td class="td" title="<%=task.getProcDefName()%>">
						<%=task.getProcDefName()%>&nbsp;
					</td>
					<td class="td" title="<%=task.getProcTitle()%>">
						<a href="javascript:void(0);" onclick="openProcessTrackPage('${ctx}','<%=task.getProcInstId()%>');">
						<%=task.getProcTitle()%>&nbsp;
						</a>
					</td>
					<td class="td" title="	<%=task.getActDefName()%>&nbsp;">
						<%=task.getActDefName()%>&nbsp;
					</td>
					<td class="td" title="<%if(null!=task.getReceiverUserName()){ %>
							<%=task.getReceiverUserName() %>(<%=task.getReceiverUserId()!=null?task.getReceiverUserId():""%>)【<%=task.getReceiverOrgName() %>(<%=task.getReceiverOrgId() %>)】
						<%}else{ %>
							<%=task.getReceiverUserId()!=null?task.getReceiverUserId():""%>
						<%} %>">
						<%if(null!=task.getReceiverUserName()){ %>
							<%=task.getReceiverUserName() %>(<%=task.getReceiverUserId()!=null?task.getReceiverUserId():""%>)【<%=task.getReceiverOrgName() %>(<%=task.getReceiverOrgId() %>)】
						<%}else{ %>
							<%=task.getReceiverUserId()!=null?task.getReceiverUserId():""%>
						<%} %>
					&nbsp;</td>
					<c:if test="${dataType==0}">
					<td class="td" title="<%if(null!=task.getSendUserName()){ %>
							<%=task.getSendUserName()!=null?task.getSendUserName():""%>(<%=task.getSendUserId()!=null?task.getSendUserId():""%>)【<%=task.getSenderOrgName() %>】
						<%}else{ %>
							<%=task.getSendUserId()!=null?task.getSendUserId():""%>
						<%} %>">
						<%if(null!=task.getSendUserName()){ %>
							<%=task.getSendUserName()!=null?task.getSendUserName():""%>(<%=task.getSendUserId()!=null?task.getSendUserId():""%>)【<%=task.getSenderOrgName() %>】
						<%}else{ %>
							<%=task.getSendUserId()!=null?task.getSendUserId():""%>
						<%} %>
					</td>
					</c:if>
					<c:if test="${dataType!=0}">
					<td class="td" title="	<%=task.getSenderOrgName()%><%if(task.getSenderOrgId()!=null){ %>(<%=task.getSenderOrgId()%>)<%} %>">
							<%=task.getSenderOrgName()%><%if(task.getSenderOrgId()!=null){ %>(<%=task.getSenderOrgId()%>)<%} %>
					</td>
					</c:if>
					<td>
						<%=DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss",task.getCreateTime())%>&nbsp;
					</td>
				  </tr>		  
			  	  <%}} %>
				</tbody>
				</table>
							</div>
				<c:if test="${dataType==0 }">
				<simpletable:pageToolbar page="${page}">
				</simpletable:pageToolbar>
				</c:if>
			</div>
						<!-- /.table-responsive -->
					</div>
					<!-- /span -->
				</div>
			</div>
		</div>

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

