<%@page import="org.activiti.engine.history.HistoricProcessInstance"%>
<%@page import="com.blueland.bpm.common.page.*,com.blueland.bpm.identity.model.User,org.activiti.engine.history.HistoricProcessInstance,org.activiti.engine.history.HistoricTaskInstance,org.activiti.engine.task.Comment,com.blueland.bpm.engine.util.WorkFlowContants"%>
<%@page import="com.blueland.bpm.common.util.*,com.blueland.bpm.engine.core.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"%>
<!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" style="overflow-y: auto;overflow-x auto;">
<head>
	<%@ include file="/commons/trace-meta.jsp"%>
	<link href="${ctx }/resource/js/plugins/jquery.qtip.css" rel="stylesheet" type="text/css" media="screen" />
	<script src="${ctx }/resource/js/plugins/easyTemplate.js" type="text/javascript"></script>
	<script src="${ctx }/resource/js/plugins/jquery.qtip.js" type="text/javascript"></script>

	<title>流程日志</title>
	<script type="text/javascript">
		$(document).ready(function(){
			$.each($(".qTipmessage"), function() {
				var obj = $(this);
				var msg =obj.attr('msg');
				onQtip(obj,msg);

			});
		});


		function onQtip(obj,msg){
			var y = -15;
			var x = -15;
			if(obj.offset().top+170> $(window).height()){
				y = -180;
			}
			obj.qtip({
				content : {
					text : msg
				},
				title : {
					text : "审批意见"
				},
				position : {
					my: 'top right',
					at: 'bottom center',
					target : 'event',
					adjust : {
						x : x,
						y : y
					}
				},
				show : {
					effect : function(offset) {
						$(this).slideDown(200);
					}
				},
				hide : {
					event : 'mouseleave',
					fixed : true,
					delay : 200
				},
				style: {
					width: 300,
					height: 150
				}
			});
		}
		function flushFlowLog(processInstanceId){
			document.getElementById("flowLogSub").src="${ctx}/workflow/trace/detailLog.do?processInstanceId="+processInstanceId;
		}

		$(function(){
			try{
				$("#headingSpan",window.parent.document).html("<b>流程标题：</b>${procTitle}，<b>流程状态：</b>${curProcessInstance.procState==1?'运行中':(curProcessInstance.procState==5?'已结束':'已作废')}，<b>流程定义名称：</b>${curProcessInstance.processDefinitionName}");
			}catch(e){}
		})

		function searchText(){
			var text=$("#searchText").val();
			$("tbody").textSearch(text);
		}
		function dingweiDaiban(){
			try{
				$('#lasttr').siblings().removeClass('table-striped');
				$('#lasttr').css("background-color", "").siblings().css("background-color", "");
				$('#lasttr').css("background-color", "#FFFF00");
				$("html,body").animate({scrollTop:$("#lasttr").offset().top},1000);
			}catch(e){}
		}

		function showSubActivityDetal(topId){
			$("tr[groupid="+topId+"]").each(function(){
				//alert(topId);
				$(this).show();
			});
		}

	</script>
</head>
<body class="white-page">

<div class="main-container" id="main-container">
	<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-bordered table-hover">
						<!-- <input name="searchText"  id="searchText" type="text"/>&nbsp;&nbsp;
						<button type="button" class="btn btn-xs btn-primary" onclick="searchText();">

									搜索关键字
									<i class="ace-icon fa fa-search bigger-110"></i>
						</button>
						&nbsp;&nbsp;<a href="javascript:void(0);" onclick="dingweiDaiban()">定位待办</a> -->
						<thead>
						<tr>
							<th style="width: 150px;">处理环节</th>
							<th style="width: 150px;">处理人</th>
							<th style="width: 150px;">处理时间</th>
							<th style="width: 150px;">处理意见</th>

							<th style="width: 150px;">接收环节</th>
							<th style="width: 150px;">接收人</th>
						</tr>
						</thead>
						<tbody>
						<%
							Map<String, Object> hisTaskLog = (Map) request
									.getAttribute("hisTaskLog");
							HistoricProcessInstance historicProcessInstance = (HistoricProcessInstance) hisTaskLog
									.get("curProcessInstance");
							String finishStr = "未结束";
							if (historicProcessInstance != null
									&& historicProcessInstance.getEndTime() != null) {
								finishStr = "已结束";
							}
							List<ProcessLogModel> processDetailLogs = (List<ProcessLogModel>) hisTaskLog
									.get("processDetailLogs");
							int i=0;
							for (ProcessLogModel processDetailLog : processDetailLogs) {
								HistoricTaskInstance historicTaskInstance = processDetailLog
										.getHistoricTaskInstance();
								Comment comment = processDetailLog.getComment();

						%>
						<tr <%if(i==processDetailLogs.size()-1){out.print("id=lasttr");} %> <%if(StringUtils.isNotBlank(historicTaskInstance.getDescription())&&historicTaskInstance.getDescription().equals("multitask")){out.print("style='display:none'"); out.print("groupid="+historicTaskInstance.getTopExecutionId());} %>>
							<td style="border-right:0"><%=StringUtils.replaceNull(historicTaskInstance.getPreTaskDefName())%></td>
							<td>
								<%=processDetailLog.getSendUserName()!=null?processDetailLog.getSendUserName()+"("+StringUtils.replaceNull(processDetailLog.getSendOrgName())+")":""%>
							</td>
							<td><%=DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss",
									historicTaskInstance.getStartTime())%></td>
							<%
								String fullCommentMsg = (comment!=null&&comment.getFullMessage()!=null? comment.getFullMessage() : "");
								if(!StringUtils.isEmpty(historicTaskInstance.getDeleteReason())&&"cancel_process".equals(historicTaskInstance.getActionType())){
									String cancelCommentMsg="当前流程已作废";
									fullCommentMsg=StringUtils.isEmpty(fullCommentMsg)?cancelCommentMsg:(cancelCommentMsg+",意见为:"+fullCommentMsg);
								}
								int length = fullCommentMsg.length();
								String shortCommentMsg=fullCommentMsg;
								if(length>21){
									shortCommentMsg=shortCommentMsg.substring(0,21);
								}
							%>

							<c:set var="set" value="<%=length %>" />
							<c:choose>
								<c:when test="${set>21}">
									<td class="qTipmessage" style="white-space: nowrap;text-overflow: ellipsis;overflow: hidden;" msg="<%=fullCommentMsg%>">
										<%if(StringUtils.isNotBlank(processDetailLog.getMultiCommentMsg())){ %>
										<span class="help-button qTipmessage" data-rel="popover" data-trigger="hover" data-placement="left" data-content="More details." title="<%=processDetailLog.getMultiCommentMsg()%>" data-original-title="Popover on hover">转</span>
										<%} %>
										<a href="javascript:void(0);" style="text-decoration:none;"><%=shortCommentMsg%></a>
									</td>
								</c:when>
								<c:otherwise>
									<td><%if(StringUtils.isNotBlank(processDetailLog.getMultiCommentMsg())){ %>
										<span class="help-button qTipmessage" data-rel="popover" data-trigger="hover" data-placement="left" data-content="More details." title="<%=processDetailLog.getMultiCommentMsg()%>" data-original-title="Popover on hover">转</span>
										<%} %><%=fullCommentMsg%></td>
								</c:otherwise>
							</c:choose>

							<td title="流程操作类型：<%=com.blueland.bpm.engine.util.WorkFlowContants.ACTION_TYPE_MAP.get(historicTaskInstance.getActionType())%>"><%=StringUtils.replaceNull(historicTaskInstance.getName())%></td>
							<td>

								<%=processDetailLog.getReiceiveUserName()!=null?processDetailLog.getReiceiveUserName()+"("+StringUtils.replaceNull(processDetailLog.getReceiveOrgName())+")":""%>
								<%if(processDetailLog.getOwnerName()!=null&&!"".equals(processDetailLog.getOwnerName())){%>
								<span class="help-button" data-rel="popover" data-trigger="hover" data-placement="left" data-content="More details." title="当前环节由<%=processDetailLog.getOwnerName()%>【委托】给<%=processDetailLog.getReiceiveUserName()%>处理" data-original-title="Popover on hover">委</span>
								<%}%>
							</td>
						</tr>
						<%i++;} %>
						</tbody>
					</table>
				</div>
			</div>
			<!-- /.table-responsive -->
		</div>
		<!-- /span -->
	</div>
</div>
</body>
</html>