<%@page import="org.activiti.engine.repository.ProcessDefinition"%>
<%@page import="org.activiti.engine.repository.Model"%>
<%@page import="com.blueland.bpm.engine.config.model.*"%>
<%@page import="com.blueland.bpm.common.page.*"%>
<%@page import="com.blueland.bpm.common.util.*"%>
<%@page import="com.blueland.bpm.manage.util.*"%>
<%@page import="java.util.*"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ 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="/pages/sysGlType/selectTypeTree.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}/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>
<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>

<script type="text/javascript">
		$(document).ready(function() {
			// 分页需要依赖的初始化动作
			window.simpleTable = new SimpleTable('procDefForm','${page.thisPageNumber}','${page.pageSize}','${pageRequest.sortColumns}');
			
		});
		function openDesignWindow(modelId,modelKey){
			if(modelId==""){
				return;
			}
			var url="<%=MyContants.BPM_PROCESS_MODELER_PATH%>";
			<%-- var url="<%=com.blueland.bpm.manage.util.MyContants.getContextJunction(request)+MyContants.BPM_PROCESS_MODELER_PATH%>"; --%>
			var appId = $("#appId").val();
			url=url+"?appId="+appId+"&key="+modelKey+"&formId=&modelId="+modelId+"&formName=&procDefKey="+modelKey;
			//alert(url);
			openWindow(url,'模型设计');
			
		}
		function publishProcess(url){	
			var pageNumber = ${page.thisPageNumber};
			postAjax(url,'发布成功!',true,true,"procDefForm",pageNumber);
		}
		function converToModel(url){
			postAjax(url,'操作成功!',false,true);
		}
		function deleteDeploy(url){	
			if(window.confirm("您确定删除流程定义及运行时的数据吗？")){
				setMask("main-container");
				$("#procDefForm").attr("action",url);
				document.getElementById("procDefForm").submit();
			}
		}
		function importProcessBpmnXml(){
			var url="${ctx}/pages/procDefModelMgr/deployProcessFile.jsp";
			showDiaLog(url,"导入流程模型",'600px','320px');
		}
		function importProcessConfigData(){
			var url="${ctx}/pages/procDefModelMgr/importProcessConfigData.jsp";
			showDiaLog(url,"导入流程",'600px','320px');
		}
		function getItemsProcDefId(){
			var chk_value =[]; 
			var procDefId="";
			$("input[name='items']:checkbox:checked").each(function(){ 
				chk_value.push($(this).val());
			})
			if(chk_value.length==0){
				alert("请选择一项流程定义数据！");
			}else{
				if(chk_value.length>1){
					alert("不能同时查看多条记录的流程图！");
					return false;
				}
				
				var items=chk_value[0].split("=");
				for(var i=0;i<items.length;i++){
					if(items[0]=="processDefinitionId"){
						procDefId=items[1];
					}
				}
				
			}
			return procDefId;
		}
		
		function exportProcessImage(){
			var procDefId=getItemsProcDefId();
			if(procDefId==""){
				return;
			}
			var url="${ctx}/procDefModelMgr/resource.do?resourceType=image&procDefId="+procDefId;
			showDiaLogList(url,'流程图');
					
		}
		
		function editProcess(modelId,procDefKey,name){
			//if(processStartIsshow=="RELEASE"&&window.confirm("此流程为发布状态,点击配置后流程将处于未发布状态,您确定配置流程吗？")){
				/* jQuery.ajax({ 
				     type: "POST", 
				     url: "${ctx}/procDefModelMgr/unReleaseProcess.do", 
				     data: {procDefId:processDefId},
				     success: function(resp)
					 {
							//alert(resp);
					 }
				 }); */
			//}
			//序列化表单  保存查询条件，页码则直接加在url之后，在后台存入session中
			//var queryparams = $("#procDefForm").serialize();
			var appId = "cpsmgr";
				//$("#appId").val();
			var url = "${ctx}/procDefModelMgr/index.do?appId="+appId+"&formName="+name+"&modelId="+modelId+"&key="+procDefKey+"&tenant="+appId+"&procDefKey="+procDefKey;
			/* window.location.href="${ctx}/procDefModelMgr/config.do?procDefId="+processDefId+"&"+queryparams+"&pageNumber="+${page.thisPageNumber}; */
			openWindow(url,'配置流程');
		}
		
		function exportProcessAllFile(isall){
			//判断是否选中全选
			var url = "";
			//if("checked"==checkbox){//全选
			if("0"==isall){//全选
				var totalCount = "${page.totalCount}";
				if("0"==totalCount){
					alert("当前没有符合要求的数据！！");
					return;
				}else{
					url="${ctx}/procDefModelMgr/exportProcessAllFile.do?resourceType=xml&exportall=0";
				}
			}else{//非全选
				var processDefIds = getItemsProcDefIds();
				if(""==processDefIds){
					return;
				}
				url="${ctx}/procDefModelMgr/exportProcessAllFile.do?resourceType=xml&procDefIds="+processDefIds+"&exportall=1";
			}
			window.open(url);
		}
		

		//获取选中的所有流程定义id值,返回的流程定义id数组
		function getItemsProcDefIds(){
			var chk_value =[]; 
			var procDefIds=new Array();
			$("input[name='items']:checkbox:checked").each(function(){ 
				chk_value.push($(this).val());
			});
			if(chk_value.length==0){
				alert("请选择流程定义数据！");
			}else{
				for(var n=0;n<chk_value.length;n++){
					var items=chk_value[n].split("=");
					if(items[0]=="processDefinitionId"){
						procDefIds.push(items[1]);
					}
				}
			}
			return procDefIds;
		}
		
		function processTypeNameOnDbClick(name, value) {
			$("#processTypeName").val(name);
			$("#processTypeId").val(value);
		}
		function createProcessModel(){
			var url="${ctx}/pages/procDefModelMgr/create.jsp";
			showDiaLog(url,"新建模型",'500px','300px');
		}
		
	</script>
</head>
<body>
	<%@ include file="/commons/messages.jsp"%>
	<form id="procDefForm" name="procDefForm"
		action="${ctx}/procDefModelMgr/list_dev.do" method="post"
		style="display: inline;">
		<input type="hidden" value="${appId}" id= "appId" name ="appId"/>
		<!-- <input value="${query.processTypeId}" id="processTypeId"
			name="processTypeId" maxlength="30" type="hidden" /> -->
		<div class="main-container" id="main-container">
			<div class="panel panel-primary">
				<div class="panel-heading">
				<h8>流程配置</h8>
				</div>
				<div class="panel-body" id="panel-body" style="padding:3px;">
					<div class="well well-sm" style="margin-bottom: 2px;">

						<table border="0" cellspacing="0" cellpadding="0"
							class="table-search">
							<tr>
								<td>流程定义KEY：</td>
								<td><input value="${query.processDefKey}"
									id="processDefKey" name="processDefKey" maxlength="30" /></td>
								<td>流程定义名称：</td>
								<td><input value="${query.processDefName}"
									id="processDefName" name="processDefName" maxlength="30" /></td>
								<td>发布状态：</td>
								<td><select name="processMgrState">
										<option value="">--请选择--</option>
											<option ${query.processMgrState=='RELEASE'?"selected":""}
												value="RELEASE">已发布</option>
											<option ${query.processMgrState=='UPDATE'?"selected":""}
												value="UPDATE">修订中</option>
											<option ${query.processMgrState=='UNRELEASE'?"selected":""}
												value="UNRELEASE">未发布</option>
								</select></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>
								<%-- <td>流程类型：</td>
								<td>
								
								<!-- <select name="processTypeId">
										<option value="">--请选择--</option>
										<c:forEach items="${sysGlTypes}" var="item">
											<option ${query.processTypeId==item.typeId?"selected":""}
												value="${item.typeId}">${item.typeName}</option>
										</c:forEach>
								</select> -->
								
								<input
									<c:choose>
										<c:when test="${not empty query.processTypeName}">
											value="${query.processTypeName}"
										</c:when>
										<c:otherwise>
											value="请选择"
										</c:otherwise>
									</c:choose>
									name="processTypeName" id="processTypeName" readonly
									onclick="showMenu('processTypeName','',''); return false;" /> 
									<input
									type="hidden" name="processTypeId" id="processTypeId"
									preValue="${query.processTypeId}"
									value="${query.processTypeId}" />
							
									<a class="blue" href="javascript:void(0);">											
										<i class="ace-icon fa fa-search bigger-130" 
									onclick="showMenu('processTypeName','',''); return false;"/> 									
									</i></a>
								</td> --%>
							</tr>
							<%-- <tr>
								<td>可见状态：</td>
								<td><select name="processStartIsshow">
										<option value="">--请选择--</option>
										<c:forEach items="${query.processStartIsshowMap}" var="item">
											<option ${query.processStartIsshow==item.key?"selected":""}
												value="${item.key }">${item.value}</option>
										</c:forEach>
								</select></td>
								<td>发布状态：</td>
								<td><select name="processMgrState">
										<option value="">--请选择--</option>
											<option ${query.processMgrState=='RELEASE'?"selected":""}
												value="RELEASE">已发布</option>
											<option ${query.processMgrState=='UPDATE'?"selected":""}
												value="UPDATE">修订中</option>
											<option ${query.processMgrState=='UNRELEASE'?"selected":""}
												value="UNRELEASE">未发布</option>
								</select></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>
								<!-- 
								<td>创建时间：</td>
								<td><input value="" id="deploymentTime"
									name="deploymentTime" maxlength="30"
									onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" /></td>
								 -->
							</tr> --%>
						
							<tr>
								<td colspan="7">
									<!-- 
									<button type="button" onclick="importProcessBpmnXml();"
										class="btn btn-xs btn-success">导入流程模型</button>
									 -->
									<!-- <button type="button" onclick="importProcessConfigData();"
										class="btn btn-xs btn-success">导入流程配置</button> -->
								   <!--  <button type="button" onclick="createProcessModel();"
										class="btn btn-xs btn-success">新建模型
										<i class="ace-icon fa fa-plus bigger-110"></i></button> -->
									<button type="button" onclick="exportProcessImage();"
										class="btn btn-xs btn btn-primary">查看流程图
										<i class="ace-icon fa fa-search-plus bigger-110"></i></button>
									<button type="button" onclick="importProcessConfigData();"
										class="btn btn-xs btn-success">导入流程
										<i class="ace-icon fa fa-cloud-upload bigger-110"></i></button>
									<button type="button" onclick="exportProcessAllFile('1');"
										class="btn btn-xs btn-yellow">导出选中流程
										<i class="ace-icon fa fa-cloud-download bigger-110"></i></button>
									<button type="button" onclick="exportProcessAllFile('0');"
										class="btn btn-xs btn-danger">导出全部流程
										<i class="ace-icon fa fa-cloud-download bigger-110"></i></button>
									<a href="${ctx}/procDefModelMgr/export.do" class="btn btn-xs btn-orange">
									导出流程清单 <i class="ace-icon fa fa-cloud-download bigger-110"></i>
									</a>	
								</td>
							</tr>

						</table>
					</div>
					
					<div class="row">
						<div class="col-xs-12">
							<div class="table-responsive">
								<table id="sample-table-1"
									class="table table-striped table-bordered table-hover">
									<thead>

										<tr>
											<th style="width: 25px;">
												<!-- <input type="checkbox" id="selectAll"
												onclick="setAllCheckboxState('items',this.checked)"> -->
											</th>
											<!-- 排序时为th增加sortColumn即可,new SimpleTable('sortColumns')会为tableHeader自动增加排序功能; -->
											<th >流程定义KEY</th>
											<th style="width: 60px;">版本号</th>
											<th sortColumn="procDefName" style="width: 150px">流程定义名称</th>
											<!-- <th style="width: 150px;">流程类型</th> -->
											<th sortColumn="deployTime" style="width: 150px;">创建时间</th>
											<th sortColumn="procDefVersion" style="width: 60px;">状态</th>
											<th sortColumn="processStartIsshow" style="width: 70px;">是否可见</th>
											<th style="width: 70px;">操作</th>
										</tr>
									</thead>
									<tbody>
										<c:forEach items="${page.result}" var="item" varStatus="status">
											<tr class="${status.count % 2 == 0 ? 'odd' : 'even'}">
												<td><input type="checkbox" name="items" id="items"
													value="processDefinitionId=${item.processDefId}"></td>
												<td class="td" title="${fn:split(item.processDefId,":")[0]}&nbsp;">${fn:split(item.processDefId,":")[0]}&nbsp;</td>
												<td align="center" class="td" title="${fn:split(item.processDefId,":")[1]}&nbsp;">${fn:split(item.processDefId,":")[1]}&nbsp;</td>
												<td class="td" title="${item.processDefName}&nbsp;">${item.processDefName}&nbsp;</td>
												<%-- <td>${item.processTypeName}&nbsp;</td> --%>
												
												<td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
												<td>
													<c:choose>
														<c:when test="${item.processMgrState=='RELEASE'}">
															<span class="label label-success">已发布</span>
														</c:when>
														<c:when test="${item.processMgrState=='UPDATE'}">
															<span class="label label-yellow">修订中</span>
														</c:when>
														<c:otherwise><span class="label label-danger">未发布</span></c:otherwise>
													</c:choose>
												</td>
												<td align="center">
													<c:choose>
														<c:when test="${item.processStartIsshow=='Y'}">
															可见
														</c:when>
														<c:otherwise>
															不可见
														</c:otherwise>
													</c:choose>
												</td>
												<td>
													<div class="btn-group">
														<button data-toggle="dropdown"
															class="btn btn-info btn-sm dropdown-toggle">
															配置 <span class="ace-icon fa fa-caret-down icon-on-right"></span>
														</button>
														<ul
															class="dropdown-menu dropdown-info dropdown-menu-right">
															<%-- <li><a href="javascript:void(0);"
															onclick="openDesignWindow('${ item.modelId }','${fn:split(item.processDefId,':')[0]}')">
															设计模型</a></li> --%>
															<li style="list-style: none;"><a
																onclick="publishProcess('${ctx}/procDefModelMgr/releaseProcess.do?procDefId=${item.processDefId}');"
																href="javascript:void(0);">发布流程</a></li>
															<li style="list-style: none;"><a
																onclick="editProcess('${ item.modelId }','${fn:split(item.processDefId,':')[0]}','${item.processDefName}')"
																href="javascript:void(0);">配置流程</a></li>
															<%-- <li style="list-style: none;"><a href="javascript:void(0);"
																onclick="converToModel('${ctx}/procDefModelMgr/convert-to-model.do?procDefId=${item.processDefId}');">转换成模型</a>
															</li> --%>
															<!-- 
															<li><a
																href="${ctx}/procDefModelMgr/exportProcessAllFile.do?resourceType=xml&procDefId=${item.processDefId}"
																target="_blank">导出流程</a></li>
															<li>
															<li><a
																href="${ctx}/procDefModelMgr/exportProcessResource.do?resourceType=xml&procDefId=${item.processDefId}"
																target="_blank">导出流程模型</a></li>
															<li><a
																href="${ctx}/procDefModelMgr/exportProcessConfigData.do?procDefId=${item.processDefId}"
																target="_blank">导出流程配置</a></li>
															 -->
																<li style="list-style: none;"><a href="javascript:void(0)"
																	onclick="showDiaLog('${ctx}/procDefModelMgr/editProcessFile.do?procDefId=${item.processDefId}','修改流程XML','1024px','600px');">修改流程XML</a>
																</li>
														
															<li style="list-style: none;"><a href="javascript:void(0)"
																onclick="showDiaLog('${ctx}/procDefModelMgr/getHistoryProcessDefModel.do?procDefId=${item.processDefId}','流程历史版本&nbsp;&nbsp;&nbsp;&nbsp;当前流程定义名称：${item.processDefName}','1024px','600px');">流程历史版本</a>
															</li>
															<!-- <li><a href="javascript:void(0)"
																onclick="deleteDeploy('${ctx}/procDefModelMgr/delete.do?procDefId=${item.processDefId}&deploymentId=${item.deploymentId}&cascode=true');">删除流程</a>
															</li> -->

														</ul>
													</div>
													<!-- /.btn-group -->
												</td>
											</tr>
										</c:forEach>
									</tbody>
								</table>
								<simpletable:pageToolbar page="${page}">
								</simpletable:pageToolbar>
							</div>
							<!-- /.table-responsive -->
						</div>
						<!-- /span -->
					</div>
				</div>
			</div>

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

