<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@page import="com.blueland.bpm.engine.util.WorkFlowContants"%>
<%
	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"%>
<meta http-equiv="Cache-Control" content="no-store" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
	$(document).ready(function() {

	});

	function saveReceiver() {
		var isMultiInstance = false;
		var count = $("#nextActUserSel option").length;
		var nextActUserIdsStr = "";
		for (var i = 0; i < count; i++) {
			var tempNextActUserIdsStr = $("#nextActUserSel").get(0).options[i].value;
			if (tempNextActUserIdsStr == "")
				continue;
			nextActUserIdsStr += tempNextActUserIdsStr;
			if (i != count - 1)
				nextActUserIdsStr += ",";
		}
		if (nextActUserIdsStr == "") {
			alert("下一环节办理人员不能为空!");
			return false;
		} else if (!isMultiInstance && count > 1) {
			alert("下一环节只允许选择一位办理人员！");
			return false;
		}
		if (confirm("您确认重新分配人员吗?")) {
			var taskId = "${activityInstanceModel.actInstId}";
			$.post('${ctx}/taskMgr/taskTransfer.do', {"receivers":nextActUserIdsStr,"taskId":taskId},
					function (resp, textStatus){
						alert(resp);
							if (resp != "操作成功!") {
								art.dialog.opener.location.reload();
								art.dialog.close();
							}
					}
			);
		}
	}

	function addNextActivityUser() {
		var treeNodeId = $(window.frames["actUserTreeFrame"].document).find(
				"#treeNodeId").attr("value");
		var treeNodeName = $(window.frames["actUserTreeFrame"].document).find(
				"#treeNodeName").attr("value");
		var treeNodeType = $(window.frames["actUserTreeFrame"].document).find(
				"#treeNodeType").attr("value");

		var count = $("#nextActUserSel option").length;
		var index = 0;
		//过滤空格
		if (treeNodeId == "" && treeNodeId.length == 0 || treeNodeType == 'ORG'
				|| treeNodeType == 'DEPT') {
			return;
		}

		var isMultiInstance = false;
		for (var i = 0; i < count; i++) {
			//不重复添加							
			if ($("#nextActUserSel").get(0).options[i].value == treeNodeId) {
				index++;
				break;
			}
		}
		if (index > 0) {
			return;
		}
		if (isMultiInstance) {
			$("#nextActUserSel").append(
					"<option value="+treeNodeId+">" + treeNodeName
							+ "</option>");
		} else {
			$("#nextActUserSel").empty();
			$("#nextActUserSel").append(
					"<option value="+treeNodeId+">" + treeNodeName
							+ "</option>");
		}
	}

	function removeNextActivityUser() {
		$('#nextActUserSel option:selected').remove();
	}
</script>
</head>
<body>
	<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 align="left" colspan="5">
											<b>当前流程名称：${activityInstanceModel.procTitle}，环节名称：${activityInstanceModel.actDefName}，执行人：${activityInstanceModel.receiver}</b>
									</td>
								</tr>
					<tr style="background: #EDF4FC">
						<td colspan="4" style="border-bottom-color: #FFFFFF">
							<table>
								<tr>
									<td align="left">
										<h5 align="left" style="margin-left: 0px;">
											<b>待选用户</b>
										</h5>
									</td>
									<td></td>
									<td>
										<h5 align="left" style="margin-left: 0px">
											<b>已选用户</b>
										</h5>
									</td>
									<td></td>
								</tr>
								<tr>

									<td
										style="height: 250px; background-color: #FFFFFF; width: 180px; border: 1px solid #C6D3DB;">
										<IFRAME align="top" style="width: 300px; height: 100%;"
											scrolling="auto" src="${ctx}/pages/taskMgr/userTree.jsp"
											frameBorder="0" id="actUserTreeFrame"
											allowTransparency="true"></IFRAME>
									</td>
									<td valign="middle"
										style="width: 50px; height: 50px; vertical-align: top;text-align: center;"">
										<button type="button" id="addNextActUserBtn"
											onclick="addNextActivityUser()"
											class="btn btn-xs btn-primary" 	style="margin-top: 60px">>></button>
										
											<button type="button" id="removeNextActUserBtn"
												onclick="removeNextActivityUser()"
												class="btn btn-xs btn-primary" style="margin-top: 10px">>></button>
									</td>
									<td style="width: 150px; height: 250px; vertical-align: top;">
										<select id='nextActUserSel' multiple="multiple"
										style='border: none; WIDTH: 100%; HEIGHT: 100%' size='4'
										tabindex='3' onclick="removeNextActivityUser();" />
									</td>
									<td align="left" valign="top"
										style="width: 50px; height: 50px; vertical-align: top;">
										&nbsp;
										<button type="button" id="nextExecuteBtn"
											onclick="saveReceiver()" class="btn btn-sm btn-primary"
											style="margin-top: 66px">保存
											<i class="ace-icon fa fa-save bigger-110"></i></button>
									</td>
								</tr>
							</table>

						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>

</body>
</html>