<%@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 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">
		$(document).ready(function() {
			// 分页需要依赖的初始化动作
			window.simpleTable = new SimpleTable('procDefForm','${page.thisPageNumber}','${page.pageSize}','${pageRequest.sortColumns}');
		});
		function deployModel(url,tempModelId,type){
			if(type==0){
				if(!window.confirm("您确定部署并覆盖最新版本的流程吗？")){
					return;
				}
			}else if(type==1){
				if(!window.confirm("您确定部署新版本的流程吗？")){
					return;
				}
			}
			setMask("main-container");
			$.post(url,{'modelId':tempModelId},function(result){
				   alert(result);
				   if(result.indexOf("部署成功")!=-1){
						window.location.reload();
				   }
				   $("#main-container").unmask();
			});
		}
		function importProcessBpmnXml(){
			var url="${ctx}/pages/procModelMgr/importBpmnFile.jsp";
			showDiaLog(url,"导入流程模型",'500px','300px');
		}
		
	
		function deleteModel(url){
			if(window.confirm("您确定删除该流程模型吗？")){
				setMask("main-container");
				$("#procDefForm").attr("action",url);
				document.getElementById("procDefForm").submit();
			}
		}
		function createProcessModel(){
			var url="${ctx}/pages/procModelMgr/create.jsp";
			showDiaLog(url,"新建模型",'500px','300px');
		}
		
		function copyProcessModel(url){
			showDiaLog(url,"复制模型",'500px','300px');
		}
	
		function getItemsModelId(){
			var chk_value =[]; 
			var procDefId="";
			$("input[name='items']:checkbox:checked").each(function(){ 
				chk_value.push($(this).val());
			})
			if(chk_value.length==0){
				alert("请选择一项流程定义数据！");
			}else{
				var items=chk_value[0].split("=");
				for(var i=0;i<items.length;i++){
					if(items[0]=="processDefinitionId"){
						procDefId=items[1];
					}
				}
				
			}
			return procDefId;
		}
		function exportProcessBpmnXml(){
			var procDefId=getItemsModelId();
			if(procDefId==""){
				return;
			}
			var url="<${ctx}/procDefMgr/resource.do?resourceType=xml&procDefId="+procDefId;
			showDiaLog(url,'流程模型');
		}
		function exportProcessImage(){
			var procDefId=getItemsModelId();
			if(procDefId==""){
				return;
			}
			var url="<${ctx}/procDefMgr/resource.do?resourceType=image&procDefId="+procDefId;
			showDiaLog(url,'流程图');
		}
		function openDesignWindow(modelId,modelKey){
			if(modelId==""){
				return;
			}
			
			try{
				jQuery.ajax({
					url : "${ctx}/processInfo/syncProcessDefToModel.do?modelKey="+modelKey,
					type : "GET",
					success : function(resp) {
					}
				});
			}catch(e){}
			var url="<%=MyContants.BPM_PROCESS_MODELER_PATH%>";
			//alert(url+'?id='+modelId,'在线设计');
			openWindow(url+'?id='+modelId,'在线设计');
			
		}
	</script>
</head>
<body id="content">
	<%@ include file="/commons/messages.jsp"%>
	<form id="procDefForm" name="procDefForm" action="${ctx}/procModelMgr/list.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" 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 width="15%">模型KEY：</td>
								<td><input value="${modelKey}" id="modelKey"
									name="modelKey"/></td>
								<td>模型名称：</td>
								<td><input value="${modelName}" id="modelName"
									name="modelName"/></td>
								
								<td><button type="submit" id="process"
										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="${query.roleId}" id="roleId"
									name="roleId" maxlength="30" /></td>
								 -->
							</tr>

							<tr>
								<td colspan="7">
									<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="importProcessBpmnXml();"
										class="btn btn-xs btn-success">导入流程模型</button> --> 
								</td>
							</tr>
						</table>
					</div>
					<div class="row">
						<div class="col-xs-12">
							<div class="table-responsive" id="content">
								<table id="sample-table-1"
									class="table table-striped table-bordered table-hover">
									<thead>

										<tr>

											<!-- 排序时为th增加sortColumn即可,new SimpleTable('sortColumns')会为tableHeader自动增加排序功能; <th></th>-->
											
											<th width="25%">模型KEY</th>
											<th width="40%">模型名称</th>
											<th  style="width: 90px;">创建时间</th>
											<th  style="width: 90px;">更新时间</th>
											<th width="80px">状态</th>
											<th width="80px">操作</th>
										</tr>
									</thead>
									<tbody>		
										<c:forEach items="${page.result}" var="model" varStatus="status">
										
										<tr class="${ ((i + 1) % 2 == 0 ? 'odd' : 'even') }">
											<input type="hidden" name="items"
												value="modelId=${ model.id }">
							
											<td>${ model.key }&nbsp;</td>
											<td>${ model.name }&nbsp;</td>
											<td><fmt:formatDate pattern="yyyy-MM-dd" 
                                                value="${ model.createTime }" />&nbsp;</td>
											<td><fmt:formatDate pattern="yyyy-MM-dd" 
                                                value="${ model.lastUpdateTime }" />&nbsp;</td>
											<td>
							                <c:choose>
												<c:when test="${model.modelState=='RELEASE'}">
													<span class="label label-success">已部署</span>
												</c:when>
												<c:otherwise>
												    <span class="label label-danger">未部署</span>
												</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('${ model.id }','${ model.key }');">
															设计模型</a></li>
														<li><a href="javascript:void(0);"
															onclick="deployModel('${ctx}/procModelMgr/deploy.do','${ model.id }',1);">
															部署流程(生成新版本)</a></li>
														<li><a href="javascript:void(0);"
															onclick="deployModel('${ctx}/procModelMgr/deployCascodeUpdate.do','${ model.id }',0);">部署流程(覆盖最新版本)</a></li>
														<li><a href="javascript:void(0);"
															onclick="copyProcessModel('${ctx}/procModelMgr/copyView.do?modelId=${ model.id }');">复制模型</a></li>
														<!-- <li><a href="${ctx}/procModelMgr/export.do?modelId=${ model.id }" target="_blank">导出模型</a></li>-->
														<li><a href="javascript:void(0)"
															onclick="deleteModel('${ctx}/procModelMgr/delete.do?modelId=${ model.id }');">删除模型</a></li>
													</ul>
												</div>
											</td>
										</tr>
									</c:forEach>
									</tbody>
								</table>
								<simpletable:pageToolbar page="${page}">
								</simpletable:pageToolbar>
							</div>
							<!-- /.table-responsive -->
						</div>
						<!-- /span -->
					</div>
				</div>
			</div>

		</div>
	</form>


</body>

</html>