<%@page import="com.qmth.qrzk.repository.utils.ParamUtils"%>
<%@page import="com.qmth.qrzk.repository.utils.Consts"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<c:set var="skeletonStatus" value="<%=Consts.SkeletonStatus.dicMap%>" scope="request"/>
<c:set var="defaultSkeletonToApproveStatus" value="<%=Consts.SkeletonStatus.TOAPPROVE%>" scope="request"/>
<!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>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />
<link href="${ctx}/resources/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/css/style.css" rel="stylesheet" type="text/css" />
<%@ include file="../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/validator.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/uploadHandlers.js"></script>
<title>任务详情-${task.taskNo}</title>
<style>
.taskInfoTable
{
	border-collapse:collapse;
	border-spacing:10px 50px;
}
.taskInfoTable th
{
	border: 1px solid  #f2d89d;
    padding:5px;
	font-size:14px;
	background-color: #faeec7;
	text-align: right;
}
.taskInfoTable td
{
    border: 1px solid  #f2d89d;
    padding:5px;
}
.taskFlowTable
{
	border-collapse:collapse;
	border-spacing:10px 50px;
}
.taskFlowTable th
{
	border: 1px solid  #f2d89d;
    padding:5px;
	font-size:14px;
	background-color: #faeec7;
	text-align: center;
}
.taskFlowTable td
{
    border: 1px solid  #f2d89d;
    padding:5px;
}
.myMargin3{
	margin-right: 20px;
}
.myMargin4{
	margin-left: 20px;
}
label {
	display: inline;
}
textarea{
	resize: none;
	width: 270px;
	height: 100px;
}
</style>
</head>
<body>
 <%@ include file="../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../common/sub_menu.jsp"%>
        <div class="page" id="page" >
        <div class="page-header" >待处理任务列表</div>
        <div class="page-body">
        	<div class="ui_step">
			    <ul class="wrap" id="processUl"><!--ul结构修改，删除了多余的ul-->
			        <li class="first<c:if test="${task.status=='TO_CREATE_SKEL'}"> cur</c:if>">创建细目表</li>
			        <li class="<c:if test="${task.status=='TO_AUDIT_SKEL'}">cur</c:if>">审核细目表</li>
			        <li class="<c:if test="${task.status=='GENERATE_PAPER'}">cur</c:if>">组卷</li>
			        <li class="<c:if test="${task.status=='TYPESET'}">cur</c:if>">预排版</li>
			        <li class="<c:if test="${task.status=='TO_AUDIT_PAPER'}">cur</c:if>">试卷审核</li>
			        <li class="<c:if test="${task.status=='TO_CHECK_PAPER'}">cur</c:if>">试卷校对</li>
			        <li class="<c:if test="${task.status=='FINAL_TYPESET'}">cur</c:if>">终排版</li>
			        <li class="<c:if test="${task.status=='TO_ARCHIVE'}">cur</c:if>">归档</li>
			        <li class="<c:if test="${task.status=='ARCHIVED'}">cur </c:if>last">完成</li>
			    </ul>
			</div>
			
				<table class="table table-bordered" style="width:100%">
        			<tr>
        				<c:if test="${sessionScope.web_session_user.id != task.typesetter}">
        				<th style="width: 84px;">细目表：</th>
        				<td style="width: 160px;text-align: center;">
        					<c:if test="${task.paperSkeleton == null}"><span>未创建</span>
        						<c:if test="${web_session_user.id == task.propositionTeacherBean.id}">
        							<button class="btn btn-small btn-primary" id="createSkelBtn">创建</button>
        						</c:if>
       						</c:if>
        					<c:if test="${task.paperSkeleton != null}"><button class="btn btn-small" id="viewSkelBtn">查看</button></c:if>
       						<c:if test="${web_session_user.id == task.curDealer && (task.status=='TO_CREATE_SKEL') && task.paperSkeleton != null}">
	        					<button class="btn btn-small btn-primary myMargin4" id="submitSkelToAudit">提交审核</button>
	        				</c:if>
	        				<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.status=='TO_AUDIT_SKEL'}">
		        				<button class="btn btn-small btn-primary myMargin4" id="openAuditWin">审核细目表</button>
        					</c:if>
        				</td>
        				</c:if>
        			
        				<th style="width: 84px;">试卷：</th>
        				<td style="padding-left: 20px;">
        					<c:if test="${task.pagerConstruct == null}"><span>未创建</span>
        						<c:if test="${task.status=='GENERATE_PAPER' && web_session_user.id == task.propositionTeacherBean.id}">
        							<button class="btn btn-small btn-primary" id="viewPaperBtn">创建</button>
       							</c:if>
       						</c:if>
       						
        					<c:if test="${task.pagerConstruct != null}">
        						<c:if test="${web_session_user.id != task.typesetter }">
		       						<button class="btn btn-small myMargin3" id="difficultyEstimateTable">试卷及格分数预估表 </button>
        						</c:if>
        						<c:if test="${task.status=='GENERATE_PAPER' && web_session_user.id == task.propositionTeacherBean.id}">
        							<button class="btn btn-small btn-primary myMargin3" id="viewPaperBtn">组卷</button>
       							</c:if>
       							
        						<c:if test="${task.status!='GENERATE_PAPER' && web_session_user.id == task.propositionTeacherBean.id}">
        							<button class="btn btn-small myMargin3" id="viewPaperBtn">查看</button>
        							<button class="btn btn-small myMargin3" style="display: none;" id="generatePaperWordBtn" title="按照最新的试题信息生成Word试卷">生成Word试卷</button>
       							</c:if>
       							
	        					<c:if test="${sessionScope.web_session_user.id != task.typesetter && sessionScope.web_session_user.id != task.propositionTeacherBean.id}">
		        					<button class="btn btn-small myMargin3" id="viewPaperBtn">查看</button>
			        				<button class="btn btn-small myMargin3" style="display: none;" id="generatePaperWordBtn" title="按照最新的试题信息生成Word试卷">生成Word试卷</button>
	        					</c:if>
       						</c:if>
        					<c:if test="${task.pagerConstruct.lastPaperWord != null && (task.pagerConstruct.lastPaperWord - 0) > 0}">
        						<button class="btn btn-small myMargin3" id="downloadPaperWordBtn">下载最新试卷</button>
        					</c:if>
        					<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.pagerConstruct.lastPaperWord != null && (task.pagerConstruct.lastPaperWord - 0) > 0}">
        						<button class="btn btn-small myMargin3" id="uploadPaperWordBtn">上传试卷</button>
        					</c:if>
        					
        					<c:if test="${task.pagerConstruct.lastAnswerWord != null && (task.pagerConstruct.lastAnswerWord - 0) > 0}">
        						<button class="btn btn-small myMargin3" id="downloadAnswerWordBtn">下载最新答案</button>
        					</c:if>
        					<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.pagerConstruct.lastAnswerWord != null && (task.pagerConstruct.lastAnswerWord - 0) > 0}">
        						<button class="btn btn-small myMargin3" id="uploadAnswerWordBtn">上传答案</button>
        					</c:if>
        					
        					<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.status=='GENERATE_PAPER'}">
	        					<button class="btn btn-small btn-primary myMargin3" id="submitPaperToTypeset">提交试卷</button>
	        				</c:if>
	        				
	        				<c:if test="${sessionScope.web_session_user.id == task.curDealer && (task.status=='TYPESET' || task.status=='FINAL_TYPESET')}">
	        					<button class="btn btn-small btn-primary myMargin3" id="submitPaperToAudit">提交试卷</button>
	        				</c:if>
	        				<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.status=='TO_AUDIT_PAPER'}">
	        					<button class="btn btn-small btn-primary myMargin3" id="openAuditWin">提交试卷审核结果</button>
	        				</c:if>
	        				<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.status=='TO_CHECK_PAPER'}">
	        					<button class="btn btn-small btn-primary myMargin3" id="openAuditWin">提交试卷校对结果</button>
	        				</c:if>
	        				<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.status=='TO_ARCHIVE'}">
	        					<button class="btn btn-small btn-primary myMargin3" id="openArchiveWin">归档</button>
	        				</c:if>
	        				
        				</td>
        			</tr>
        		</table>
			
        		<table class="table table-bordered">
        			<tr>
        				<th style="width: 84px;">试卷编号：</th>
        				<td>
        					${task.taskNo}
        					<input name="taskNo" id="taskNo" type="hidden" value="<c:out value='${task.taskNo}'/>"/>
        				</td>
        				<th>状态：</th>
        				<td style="width:120px;">${task.statusName}</td>
        				<th style="width:110px;">当前处理人：</th>
        				<td style="width:90px;"><b>${task.curDealerBean.name}</b></td>
        				<th style="width:110px;">计划开始日期：</th>
        				<td style="width:130px;">${fn:dateToShortStr(task.planStartTime)}</td>
        				<th style="width:110px;">计划结束日期：</th>
        				<td style="width:130px;">${fn:dateToShortStr(task.planEndTime)}</td>
        			</tr>
        			<tr style="color:#aaa;">
        				<th>命题教师1：</th>
        				<td>${task.propositionTeacherBean.name} &nbsp;&nbsp;
        					<c:if test="${sessionScope.web_session_user.id == task.primarySecretaryBean.id && task.pagerConstruct != null}">
        						<button id="viewTeacherAssessmentBtn">评价</button>
       						</c:if>
        				</td>
        				<th>命题教师2：</th>
        				<td>${task.auditTeacherBean.name}</td>
        				<th>学科秘书：</th>
        				<td>${task.primarySecretaryBean.name}</td>
        				<%--<th>学科秘书2：</th>--%>
        				<%--<td>${task.assistantSecretaryBean.name}</td>--%>
        				<th>排版员：</th>
        				<td>${task.typesetterBean.name}</td>
        			</tr>
        		</table>
        		
        		
        		
        		<table class="table table-bordered" style="margin-top: 20px; color:#aaa;">
        			<tr>
        				<th style="width: 84px;">课程信息：</th>
        				<td>${task.course.code} - ${task.course.name}</td>
        			</tr>
        			<tr>
        				<th>教材信息：</th>
        				<td>ISBN:${task.book.code} ；教材名称：${task.book.name}； 编者：${task.book.editor}；
							出版社：${task.book.press}； 版次：${task.book.version}；</td>
        			</tr>
        		</table>
        		
			<div style="margin-top: 20px;margin-bottom: 20px;">
				 <div class="record">
				 	<b>试卷流程跟踪：</b>
					<c:forEach items="${task.flows}" var="flow" varStatus="u">
						<p>${fn:dateToLongStr(flow.createdTime)} &nbsp;&nbsp;${flow.createdByBean.name} &nbsp;&nbsp;${flow.operName}; <c:if test="${flow.remark != null && flow.remark != ''}">&nbsp;&nbsp;备注：<span<c:if test="${fn:contains(flow.operName, '驳回')}"> style="font-weight: bold;color:red;"</c:if>>${flow.remark}</span></c:if></p>
					</c:forEach>
				</div>
			
				<div class="bs-docs-example record-tab">
		            <ul id="myTab" class="nav nav-tabs">
		              <li class="active"><a href="#home" data-toggle="tab"><strong>试卷版本跟踪</strong></a></li>
		              <li class=""><a href="#profile" data-toggle="tab"><strong>标答版本跟踪</strong></a></li>
		            </ul>
		            <div id="myTabContent" class="tab-content">
		              <div class="tab-pane fade active in" id="myTabContent_0">
		                <table class="table table-bordered">
		                    <thead>
		                      <tr>
		                        <th>上传时间</th>
		                        <th>上传者</th>
		                        <th>名称</th>
		                      </tr>
		                    </thead>
		                    <c:forEach items="${task.pagerConstruct.paperWordHistories}" var="history">
		                      <tr>
		                        <td style="width: 150px;">${fn:dateToLongStr(history.createdTime)}</td>
		                        <td>${history.createdByBean.name}</td>
		                        <td><a href="${ctx}/attachment/download/${history.attId}" target="_blank" style="text-decoration: underline;">${history.att.originalName}</a></td>
		                      </tr>
		                    </c:forEach>
		                </table>
		              </div>
		              <div class="tab-pane fade" id="myTabContent_1">
		                <table class="table table-bordered">
		                    <thead>
		                      <tr>
		                        <th>上传时间</th>
		                        <th>上传者</th>
		                        <th>名称</th>
		                      </tr>
		                    </thead>
		                    <c:forEach items="${task.pagerConstruct.answerWordHistories}" var="history">
		                      <tr>
		                        <td style="width: 150px;">${fn:dateToLongStr(history.createdTime)}</td>
		                        <td>${history.createdByBean.name}</td>
		                        <td><a href="${ctx}/attachment/download/${history.attId}" target="_blank" style="text-decoration: underline;">${history.att.originalName}</a></td>
		                      </tr>
		                    </c:forEach>
		                </table>
		              </div>
		            </div>
				</div>
			</div>
        </div>
    </div>
    
<!-- 隐藏功能区Begin -->
<div style="display: none;">
	<div id="normalSubmitDiv" title="选择下一个处理人" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:450px;height:310px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;margin-top: 10px;">
        	<form action="#" id="formForNormalSubmit">
        		<input type="hidden" name="taskId" value="${task.id}"/>
				<table cellpadding="5">
					<tr>
						<td nowrap="nowrap" valign="top">下一个处理人</td>
						<td>
							<select name="nextDealer"><c:forEach items="${task.nextDealers}" var="dealer"><option value="${dealer.id}" <c:if test="${dealer.id==task.defaultNextDealer}">selected="selected"</c:if>>${dealer.name}</option></c:forEach></select>
						</td>
					</tr>
					<tr>
						<td nowrap="nowrap" valign="top">备注</td>
						<td>
							<textarea rows="5" cols="50" name="remark" id="remarkForNormalSubmit"></textarea>
							<div id="countForNormalSubmit"></div>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<button class="btn myMargin3" id="saveNormalSubmitBtn">确定</button>
							<button class="btn" id="cancelNormalSubmitBtn">取消</button>
						</td>
					</tr>
				</table>
            </form>
        </div>
    </div>
    
    <div>
	    <form id="downloadForm" action="#">
	    </form>
    </div>
    
	<div id="uploadPaperDiv" title="上传Word试卷" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:400px;height:190px;padding:10px;overflow: hidden;">
		<table cellpadding="5" width="380px;">
			<tr>
				<td id="swfUploadTd"><span id="spanPaperButtonPlaceholder"></span></td>
			</tr>
			<tr>
				<td style="height: 50px;vertical-align: middle;">
					<span id="uploadedPaperFileName"></span>
					<input type="hidden" id="uploadedPaperAttId"/>
				</td>
			</tr>
			<tr>
				<td align="center">
					<button class="btn myMargin3" id="confirmUploadedPaper" disabled="disabled">确定</button>
					<button class="btn" id="cancelUploadedPaper">取消</button>
				</td>
			</tr>
		</table>
	</div>
	
	<div id="uploadAnswerDiv" title="上传Word答案" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:400px;height:190px;padding:10px;overflow: hidden;">
		<table cellpadding="5" width="380px;">
			<tr>
				<td><span id="spanAnswerButtonPlaceholder"></span></td>
			</tr>
			<tr>
				<td style="height: 50px;vertical-align: middle;">
					<span id="uploadedAnswerFileName"></span>
					<input type="hidden" id="uploadedAnswerAttId"/>
				</td>
			</tr>
			<tr>
				<td align="center">
					<button class="btn myMargin3" id="confirmUploadedAnswer" disabled="disabled">确定</button>
					<button class="btn" id="cancelUploadedAnswer">取消</button>
				</td>
			</tr>
		</table>
	</div>
	
	<div id="auditDiv" title="提交审核结果" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:450px;height:340px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;margin-top: 10px;">
        	<form action="#" id="formForAudit">
        		<input type="hidden" name="taskId" value="${task.id}"/>
				<table cellpadding="5">
					<tr>
						<td nowrap="nowrap">审核结果</td>
						<td>
							<input type="radio" name="auditResult" id="approved" value="2" checked="checked"/><label for="approved" class="myMargin3">通过</label>
							<input type="radio" name="auditResult" id="rejected" value="4"/><label for="rejected">驳回</label>
						</td>
					</tr>
					<tr>
						<td nowrap="nowrap" valign="top">下一个处理人</td>
						<td>
							<span id="nextDealersSpan" style="display: none;"><select name="nextDealer"><c:forEach items="${task.nextDealers}" var="dealer"><option value="${dealer.id}" <c:if test="${dealer.id==task.defaultNextDealer}">selected="selected"</c:if>>${dealer.name}</option></c:forEach></select></span>
							<span id="preDealersSpan" style="display: none;"><select name="nextDealer"><c:forEach items="${task.preDealers}" var="dealer"><option value="${dealer.id}">${dealer.name}</option></c:forEach></select></span>
						</td>
					</tr>
					<tr>
						<td nowrap="nowrap" valign="top">审核意见</td>
						<td>
							<textarea rows="5" cols="50" name="remark" id="remarkForAudit"></textarea>
							<div id="countForAudit"></div>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<button class="btn myMargin3" id="saveAuditBtn">确定</button>
							<button class="btn" id="cancelAuditBtn">取消</button>
						</td>
					</tr>
				</table>
            </form>
        </div>
    </div>
    
	<div id="archiveDiv" title="归档" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:380px;height:270px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;margin-top: 10px;">
        	<form action="#" id="formForArchive">
        		<input type="hidden" name="taskId" value="${task.id}"/>
				<table cellpadding="5">
					<tr>
						<td nowrap="nowrap" valign="top">备注</td>
						<td>
							<textarea name="remark" id="remarkForArchive"></textarea>
							<div id="countForArchive"></div>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<button class="btn myMargin3" id="saveArchiveBtn">确定</button>
							<button class="btn" id="cancelArchiveBtn">取消</button>
						</td>
					</tr>
				</table>
            </form>
        </div>
    </div>
</div>
<!-- 隐藏功能区End -->
</body>
</html>
<script language="javascript">
var confirmMsg = "您确定提交吗？";
$(document).ready(function(){
	{//初始化审核意见输入框字符数控制
		$("#remarkForNormalSubmit").keydown(function(){
	    	calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
	    });
	    $("#remarkForNormalSubmit").keyup(function(){
	    	calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
	    });
	    $("#remarkForNormalSubmit").keypress(function(){
	    	calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
	    });
	    

		$("#remarkForAudit").keydown(function(){
			calculate_byte(200,'remarkForAudit','countForAudit');
	    });
	    $("#remarkForAudit").keyup(function(){
	    	calculate_byte(200,'remarkForAudit','countForAudit');
	    });
	    $("#remarkForAudit").keypress(function(){
	    	calculate_byte(200,'remarkForAudit','countForAudit');
	    });

	    
		$("#remarkForArchive").keydown(function(){
			calculate_byte(200,'remarkForArchive','countForArchive');
	    });
	    $("#remarkForArchive").keyup(function(){
	    	calculate_byte(200,'remarkForArchive','countForArchive');
	    });
	    $("#remarkForArchive").keypress(function(){
	    	calculate_byte(200,'remarkForArchive','countForArchive');
	    });
	}
	
	{
		$("#processUl").children("li").each(function(){
			if($(this).hasClass("cur")){
				$(this).prev().addClass("previous");
				return false;
			}else{
				$(this).addClass("finished");
			}
		});
	}
	
	{
		$("#myTab").children("li").each(function(index){
			$(this).click(function(){
				//alert($(this).attr("class"));
				$("#myTab").children("li").each(function(index){
					$("#myTabContent_" + index).removeClass("active");
					$("#myTabContent_" + index).removeClass("in");
					$(this).removeClass("active");
				});
				$(this).addClass("active");
				$("#myTabContent_" + index).addClass("active");
				$("#myTabContent_" + index).addClass("in");
			});
		});
	}
	
	$("#createSkelBtn").click(function(){
		var name = encodeURIComponent($('#taskNo').val());
		window.open("${ctx}/paperSkeleton/redirect/paperSkeleton?taskId=${task.id}&courseId=${task.course.id}&courseCode=${task.course.code}&bookId=${task.book.id}&name="+name,"skel_win_${task.id}");
	});
	
	$("#difficultyEstimateTable").click(function(){
		var name = encodeURIComponent($('#taskNo').val());
		window.open("${ctx}/zujuan/viewDifficultyEstimateTable/${task.pagerConstruct.id}","skel_difficulty_win_${task.id}");
	});
	
	$("#viewSkelBtn").click(function(){
		window.open("${ctx}/paperSkeleton/viewskeletondetail/${task.paperSkeleton.id}","skel_win_${task.id}");
	});
	
	$("#submitSkelToAudit").click(function(){
		<c:if test="${task.paperSkeleton == null}">
		$.messager.alert('提示', "未创建细目表，不能提交，请先创建细目表!", 'error');
		</c:if>
		<c:if test="${task.paperSkeleton != null}">
		calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
		$('#normalSubmitDiv').window('open');
		</c:if>
	});
	
	$("#saveNormalSubmitBtn").click(function(){
		$.messager.confirm("操作提示", confirmMsg, function (data) {
	        if (data) {
	        	$(document).mask('正在处理，请稍等...');
	        	var param = $('#formForNormalSubmit').serialize();
	        	$.post('${ctx}/taskCenter/normalSubmit',param,function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				reloadWin();
	    			}
	    		});
	        }
	    });
		return false;
	});
	
	$("#cancelNormalSubmitBtn").click(function(){
    	$('#normalSubmitDiv').window('close');
		return false;
    });
	
	$("#viewPaperBtn").click(function(){
		window.open("${ctx}/zujuan/manualAdd?taskId=${task.id}","paper_win_${task.id}");
		reloadWinSlow();
	});
	
	$("#submitPaperToTypeset").click(function(){
		<c:if test="${task.pagerConstruct == null}">
		$.messager.alert('提示', "未创建试卷，不能提交，请先创建试卷!", 'error');
		</c:if>
		<c:if test="${task.pagerConstruct != null}">
		$.ajax({
    		type : "POST",
    		url : "${ctx}/zujuan/countBlankQuesNum/${task.pagerConstruct.id}",
    		data : {},
    		success : function(res) {
    			var blankQuesNum = res.blankQuesNum - 0;
    			if(blankQuesNum > 0){
    				$.messager.alert('提示', "当前试卷里面还有" + blankQuesNum + "道空题，请组完卷后再提交!", 'error');
    			}else{
    				calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
    				$('#normalSubmitDiv').window('open');
    			}
    		}
    	});
		</c:if>
	});
	
	$("#generatePaperWordBtn").click(function(){
		$(document).mask('正在生成试卷，请稍等...');
    	$.ajax({
    		type : "POST",
    		url : "${ctx}/zujuan/previewPaper/${task.pagerConstruct.id}",
    		data : {}, 
    		success : function(res) {
    			$(document).unmask();
    			if(res.flag=='success'){
    				$("#downloadForm").attr("action","${ctx}/attachment/download/" + res.att.id);
    				$("#downloadForm").submit();
    			}else{
    				$.messager.alert('提示', "生成试卷失败，请刷新后操作!", 'error');
    			}
    		}
    	});
	});
	
	$("#downloadPaperWordBtn").click(function(){
		var fileName = encodeURIComponent($('#taskNo').val() + "试卷_" + formatToNormalDateStr2((new Date()).getTime()));
		window.open("${ctx}/attachment/download/${task.pagerConstruct.lastPaperWord}?fileName=" + fileName);
	});
	
	$("#downloadAnswerWordBtn").click(function(){
		var fileName = encodeURIComponent($('#taskNo').val() + "答案_" + formatToNormalDateStr2((new Date()).getTime()));
		window.open("${ctx}/attachment/download/${task.pagerConstruct.lastAnswerWord}?fileName=" + fileName);
	});

	{//加载SwfUpload上传组件
		loadPaperSwfUpload();
		loadAnswerSwfUpload();
	}
	
	$("#uploadPaperWordBtn").click(function(){
		$("#uploadedPaperFileName").text("");
		$("#uploadedPaperAttId").val("");
		$("#confirmUploadedPaper").attr("disabled",true);
		$("#uploadPaperDiv").window('open'); 
	});
	
	$("#confirmUploadedPaper").click(function(){
		if($("#uploadedPaperAttId").val() == ""){
			$.messager.alert('提示', '请先上传Word试卷！', 'error');
			return false;
		}
		$.messager.confirm("操作提示", "您确定要覆盖最新的Word试卷吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在提交数据，请稍等...');
				var param = {
							"taskId":"${task.id}",
							"paperId":"${task.pagerConstruct.id}",
							"attId":$("#uploadedPaperAttId").val(),
							"wordType":"PAPER"
						};
				$.post('${ctx}/taskCenter/submitCurWord',param,function(res){
					$(document).unmask();
					if(res.flag=='failed'){
			           $.messager.alert('提示', res.msg, 'error', function () {
			        	   //do nothing
			           });
			           return false;
					}else{
						reloadWin();
					}
				});
	        }
		});
    });
	
	$("#cancelUploadedPaper").click(function(){
    	$('#uploadPaperDiv').window('close');
		return false;
    });
	
	$("#uploadAnswerWordBtn").click(function(){
		$("#uploadedAnswerFileName").text("");
		$("#uploadedAnswerAttId").val("");
		$("#confirmUploadedAnswer").attr("disabled",true);
		$("#uploadAnswerDiv").window('open'); 
	});
	
	$("#confirmUploadedAnswer").click(function(){
		if($("#uploadedAnswerAttId").val() == ""){
			$.messager.alert('提示', '请先上传Word答案！', 'error');
			return false;
		}
		$.messager.confirm("操作提示", "您确定要覆盖最新的Word答案吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在提交数据，请稍等...');
				var param = {
							"taskId":"${task.id}",
							"paperId":"${task.pagerConstruct.id}",
							"attId":$("#uploadedAnswerAttId").val(),
							"wordType":"ANSWER"
						};
				$.post('${ctx}/taskCenter/submitCurWord',param,function(res){
					$(document).unmask();
					if(res.flag=='failed'){
			           $.messager.alert('提示', res.msg, 'error', function () {
			        	   //do nothing
			           });
			           return false;
					}else{
						reloadWin();
					}
				});
	        }
		});
    });
	
	$("#cancelUploadedAnswer").click(function(){
    	$('#uploadAnswerDiv').window('close');
		return false;
    });
	
	$("#submitPaperToAudit").click(function(){
		$.ajax({
    		type : "POST",
    		url : "${ctx}/zujuan/countBlankQuesNum/${task.pagerConstruct.id}",
    		data : {},
    		success : function(res) {
    			var blankQuesNum = res.blankQuesNum - 0;
    			if(blankQuesNum > 0){
    				$.messager.alert('提示', "当前试卷里面还有" + blankQuesNum + "道空题，请组完卷后再提交!", 'error');
    			}else{
    		    	confirmMsg = "您确定要提交吗？（提交前请确认是否已经上传了排版后的Word试卷及答案）";
    				calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
    				$('#normalSubmitDiv').window('open');
    			}
    		}
    	});
	});
	
	$("#openAuditWin").click(function(){
		<c:if test="${task.pagerConstruct == null}">
			calculate_byte(200,'remarkForAudit','countForAudit');
			if($("#approved").attr("checked")){
				$("#nextDealersSpan").show();
				$("#nextDealersSpan").find("select").attr("disabled",false);
				$("#preDealersSpan").hide();
				$("#preDealersSpan").find("select").attr("disabled",true);
			}else{
				$("#nextDealersSpan").hide();
				$("#nextDealersSpan").find("select").attr("disabled",true);
				$("#preDealersSpan").show();
				$("#preDealersSpan").find("select").attr("disabled",false);
			}
			$('#auditDiv').window('open');
		</c:if>
		<c:if test="${task.pagerConstruct != null}">
		$.ajax({
    		type : "POST",
    		url : "${ctx}/zujuan/countBlankQuesNum/${task.pagerConstruct.id}",
    		data : {},
    		success : function(res) {
    			var blankQuesNum = res.blankQuesNum - 0;
    			if(blankQuesNum > 0){
    				$.messager.alert('提示', "当前试卷里面还有" + blankQuesNum + "道空题，请组完卷后再提交!", 'error');
    			}else{
    				calculate_byte(200,'remarkForAudit','countForAudit');
    				if($("#approved").attr("checked")){
    					$("#nextDealersSpan").show();
    					$("#nextDealersSpan").find("select").attr("disabled",false);
    					$("#preDealersSpan").hide();
    					$("#preDealersSpan").find("select").attr("disabled",true);
    				}else{
    					$("#nextDealersSpan").hide();
    					$("#nextDealersSpan").find("select").attr("disabled",true);
    					$("#preDealersSpan").show();
    					$("#preDealersSpan").find("select").attr("disabled",false);
    				}
    				$('#auditDiv').window('open');
    			}
    		}
    	});
		</c:if>
	});
	
	$("[name=auditResult]").click(function(){
		if($("#approved").attr("checked")){
			$("#nextDealersSpan").show();
			$("#nextDealersSpan").find("select").attr("disabled",false);
			$("#preDealersSpan").hide();
			$("#preDealersSpan").find("select").attr("disabled",true);
		}else{
			$("#nextDealersSpan").hide();
			$("#nextDealersSpan").find("select").attr("disabled",true);
			$("#preDealersSpan").show();
			$("#preDealersSpan").find("select").attr("disabled",false);
		}
	});
	
	$("#saveAuditBtn").click(function(){
		$.messager.confirm("操作提示", "您确定要提交审核结果吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在提交，请稍等...');
	        	var param = $('#formForAudit').serialize();
	        	$.post('${ctx}/taskCenter/saveAuditResult',param,function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				reloadWin();
	    			}
	    		});
	        }
	    });
		return false;
	});
	
	$("#cancelAuditBtn").click(function(){
    	$('#auditDiv').window('close');
		return false;
    });
	
	$("#openArchiveWin").click(function(){
		$.ajax({
    		type : "POST",
    		url : "${ctx}/zujuan/countBlankQuesNum/${task.pagerConstruct.id}",
    		data : {},
    		success : function(res) {
    			var blankQuesNum = res.blankQuesNum - 0;
    			if(blankQuesNum > 0){
    				$.messager.alert('提示', "当前试卷里面还有" + blankQuesNum + "道空题，请组完卷后再提交!", 'error');
    			}else{
    				calculate_byte(200,'remarkForArchive','countForArchive');
    				$('#archiveDiv').window('open');
    			}
    		}
    	});
	});
	
	$("#saveArchiveBtn").click(function(){
		$.messager.confirm("操作提示", "您确定要归档此任务吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在提交，请稍等...');
	        	var param = $('#formForArchive').serialize();
	        	$.post('${ctx}/taskCenter/saveArchiveResult',param,function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				reloadWin();
	    			}
	    		});
	        }
	    });
		return false;
	});
	
	$("#cancelArchiveBtn").click(function(){
    	$('#archiveDiv').window('close');
		return false;
    });
	
	$("#viewTeacherAssessmentBtn").click(function(){
		window.open("${ctx}/teacherAssessment/view/${task.id}/${task.propositionTeacherBean.id}","teacher_assessment_win_${task.id}");
	})
});

function reloadWinSlow(){
	window.setTimeout(function(){window.location.reload();},1000);
}

function loadPaperSwfUpload() {
	new SWFUpload({
		 upload_url :"${ctx}/attachment/upload",
		 post_params: {"userId":"${sessionScope.web_session_user.id}"},
		 use_query_string : false,
		  
		// File Upload Settings
		file_size_limit : "50 MB",	// 50MB
		
		file_types : "<%=(ParamUtils.NeedCheckWordVersion?"*.docx":"*.doc;*.docx")%>",
		file_types_description : "Word文档",
		file_upload_limit 	:	0,

		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadPaperSuccess,
		upload_complete_handler : uploadComplete,
		
		// Button Settings
		button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
		button_placeholder_id : "spanPaperButtonPlaceholder",
		button_width: 180,
		button_height: 18,
		button_text : '<span class="button">点击这里上传Word试卷<span class="buttonSmall"></span></span>',
		button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12px; } .buttonSmall { font-size: 10px; color: #ff0000;}',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
		
		
		// Flash Settings
		flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',

		custom_settings : {
			upload_target : "importDivFileProgressContainer"
		},
		// Debug Settings
		debug: false //是否显示调试窗口
	});
};

function uploadPaperSuccess(file, serverData) {
	$(document).unmask();
	serverData=eval('(' + serverData + ')');
	if(serverData.flag=='success'){
		$("#uploadedPaperFileName").text("已上传文件：" + serverData.att.originalName);
		$("#uploadedPaperAttId").val(serverData.att.id);
		var param = {
				"paperId":"${task.pagerConstruct.id}",
				"attId":serverData.att.id,
				"wordType":"PAPER"
		};
		$.post('${ctx}/taskCenter/checkWordVersion',param,function(res){
			$(document).unmask();
			if(res.flag=='failed'){
	           $.messager.alert('提示', res.msg, 'error', function () {
	        	   //do nothing
	           });
	           return false;
			}else{
				if(res.checkResult){
					$("#confirmUploadedPaper").attr("disabled",false);
				}else{
					$("#confirmUploadedPaper").attr("disabled",true);
					$.messager.alert('提示', "版本校验不通过，您上传的Word试卷不是基于最新Word试卷进行编辑的，请下载最新Word试卷进行编辑后上传", 'error');
				}
			}
		});
	}else{
		$.messager.alert('提示',serverData.msg,'error');
	}
}

function loadAnswerSwfUpload() {
	new SWFUpload({
		 upload_url :"${ctx}/attachment/upload",
		 post_params: {"userId":"${sessionScope.web_session_user.id}"},
		 use_query_string : false,
		  
		// File Upload Settings
		file_size_limit : "50 MB",	// 50MB
		file_types : "<%=(ParamUtils.NeedCheckWordVersion?"*.docx":"*.doc;*.docx")%>",
		file_types_description : "Word文档",
		file_upload_limit 	:	0,

		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadAnswerSuccess,
		upload_complete_handler : uploadComplete,
		
		// Button Settings
		button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
		button_placeholder_id : "spanAnswerButtonPlaceholder",
		button_width: 180,
		button_height: 18,
		button_text : '<span class="button">点击这里上传Word答案<span class="buttonSmall"></span></span>',
		button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12px; } .buttonSmall { font-size: 10px; color: #ff0000;}',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
		
		
		// Flash Settings
		flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',

		custom_settings : {
			upload_target : "importDivFileProgressContainer"
		},
		// Debug Settings
		debug: false //是否显示调试窗口
	});
};

function uploadAnswerSuccess(file, serverData) {
	$(document).unmask();
	serverData=eval('(' + serverData + ')');
	if(serverData.flag=='success'){
		$("#uploadedAnswerFileName").text("已上传文件：" + serverData.att.originalName);
		$("#uploadedAnswerAttId").val(serverData.att.id);
		var param = {
				"paperId":"${task.pagerConstruct.id}",
				"attId":serverData.att.id,
				"wordType":"ANSWER"
		};
		$.post('${ctx}/taskCenter/checkWordVersion',param,function(res){
			$(document).unmask();
			if(res.flag=='failed'){
	           $.messager.alert('提示', res.msg, 'error', function () {
	        	   //do nothing
	           });
	           return false;
			}else{
				if(res.checkResult){
					$("#confirmUploadedAnswer").attr("disabled",false);
				}else{
					$("#confirmUploadedAnswer").attr("disabled",true);
					$.messager.alert('提示', "版本校验不通过，您上传的Word答案不是基于最新Word答案进行编辑的，请下载最新Word答案进行编辑后上传", 'error');
				}
			}
		});
	}else{
		$.messager.alert('提示',serverData.msg,'error');
	}
}
</script>
