<%@page
	import="com.blueland.bpm.engine.core.model.ProcessDefinitionModel"%>
<%@page import="com.blueland.bpm.engine.config.model.ProcessInfoConfig"%>
<%@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"%>
<%
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">
function changeImage(procDefId){
	var url ="${ctx}/procDefModelMgr/getProcessImageWidthAndHeight.do";
	//获取图片的宽高
	 $.ajax({
            url : url,
            data:{"procDefId":procDefId},
            type : "POST",
            dataType: "json", 
            success : function (data){
            	var imageWidth=parseInt(data.imageWidth)+20;
            	var imageHeight=parseInt(data.imageHeight)+30;
            	
            	$("#processImage").attr("style","padding-left: 30px; display: inline; float: left; margin:20px auto 0;position: relative;background:url('${ctx}/procDefModelMgr/resource.do?resourceType=image&procDefId="+procDefId
            			+"')  no-repeat;width:"+imageWidth+"px; height:"+
            			imageHeight+"px;");
            	$("#versionnumber").text(data.version);		
            }
        });
}

function deleteDeploy(url,procDefId,deploymentId,cascode){
if(window.confirm("删除流程会级联删除该流程定义和运行数据，请谨慎操作！为了避免误操作，在删除操作的同时会要求您导出流程作为备份！")){
		
		var downloadUrl="${ctx}/procDefMgr/exportProcessAllFile.do?resourceType=xml&procDefIds="+procDefId+"&exportall=1";
		var winObj =  window.open(downloadUrl);
		var loop = setInterval(function() {
		      if(winObj.closed) {
		         clearInterval(loop);
		         setMask("main-container");
					$.ajax({
						   url : url,
						   data:{"procDefId":procDefId,"deploymentId":deploymentId,"cascode":cascode},
				           type : "POST",
				           dataType: "json", 
				           success : function (data){
				        	   //alert(data);
				        	   if(data.success){
				        		   alert("删除成功");
				        		   var procDefId1 = data.returnProcDefId;
				        		   if("" != procDefId1){
				        			   $("#procDefId").val(procDefId1);
					        		   $("#historyForm").submit();
				        		   }else{
				        		   		var win = art.dialog.open.origin;  
										$("#procDefForm", win.document).submit();  
				        		   }
				        	   }else{
				        		   alert("删除失败，原因是:"+data.reason);
				        	   }
				           }
					});
		      }

		}, 3000);
	}
	
}

function exportProcessAllFile(processDefIds){
	var url="${ctx}/procDefModelMgr/exportProcessAllFile.do?resourceType=xml&procDefIds="+processDefIds+"&exportall=1";
	window.open(url);
}

	</script>
</head>
<body>
<%@ include file="/commons/messages.jsp"%>
<form id="historyForm" name="historyForm"
		action="${ctx}/procDefModelMgr/getHistoryProcessDefModel.do" method="post"
		style="display: inline;">
	<input type="hidden" name="procDefId" id="procDefId"/>	
	<div class="main-container" id="main-container">
		<div class="panel panel-primary">
			<div class="panel-body" id="panel-body" style="padding:3px;">
				<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>流程定义版本号</th>
										<th>最后更新时间</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach  items="${result}" var="item"
										varStatus="status">
									
										<tr class="${status.count % 2 == 0 ? 'odd' : 'even'}">
											<td><a href="javascript:void(0);" onclick="changeImage('${item.procDefId}');">${item.version}</a></td>
		    								<td><fmt:formatDate value="${item.pdCreateTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
											<td>
											<a href="javascript:void(0);" onclick="deleteDeploy('${ctx}/procDefModelMgr/history/delete.do','${item.procDefId}','${item.deploymentId}','true');">删除流程</a>&nbsp;&nbsp;
											<c:if test="${ebpmAdmin}">
											<a href="javascript:void(0)" onclick="showDiaLog('${ctx}/procDefModelMgr/editProcessFile.do?procDefId=${item.procDefId}','修改流程XML','1024px','600px');">修改流程XML</a>&nbsp;&nbsp;
											<a onclick="showDiaLog('${ctx}/procDefModelMgr/config.do?procDefId=${item.procDefId}','配置','1224px','600px');" href="javascript:void(0);">配置流程</a>
											<a href="javascript:void(0)" onclick="exportProcessAllFile('${item.procDefId}');">导出流程</a>&nbsp;&nbsp;
											
											</c:if>
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id=con >
		<span></span>
		<ul id=tags>
			  <li class="selectTag">当前版本<span id="versionnumber">${result[0].version}</span>的流程图如下：</li>
		</ul>
		<div id=tagContent>
			<div class="tagContent selectTag" id="tagContent0" >
				<div id="processImage" style="padding-left: 30px; display: inline; float: left; margin:20px auto 0;position: relative;background:url('${ctx}/procDefModelMgr/resource.do?resourceType=image&procDefId=${result[0].procDefId}')  no-repeat;width:${imageWidth+20}px; height:${imageHeight+30}px;">
				</div>
			</div>
		</div>
	</div>
	</div>
	
	</form>
</body>
</html>

