<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/taglib/c.tld" prefix="c"%>
<%@ include file="../../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../../common/top.jsp"%>
</head>
<body class="easyui-layout">
	<%@ include file="../../common/topicheader.jsp"%>
	<%@ include file="../../common/topicmenu-w.jsp"%>
	<div data-options="region:'center',title:'首页 -<a href=>【收尾检查】</a>-列表'">
          <div class="subjcethead-cont row-fluid" style="margin-top: 10px;margin-left: 10px;">
              <div class="span11">
                  <div class="subjcethead-cont-right-content">
                         <table class="table table-bordered table-hover">
                          <thead>
                            <tr>
                              <th style="text-align: center;">仲裁卷</th>
                              <th style="text-align: center;">问题卷</th>
                              <th style="text-align: center;">打回卷</th>
                              <th style="text-align: center;">未评卷</th>
                              <th style="text-align: center;">正在评卷数</th>
                            </tr>
                          </thead>
                          <tbody>
	                        <tr>
								<td style="text-align: center;">${arbitrationCount }</td>
								<td style="text-align: center;">${problemCount }</td>
								<td style="text-align: center;">${backCount }<c:if test="${backCount>0 }">&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-small btn-primary" type="button" onclick="viewBackInfo()">详情</button></c:if></td>
								<td style="text-align: center;">${toMarkCount }</td>
								<td style="text-align: center;">${currentCount }<c:if test="${currentCount>0 }">&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-small btn-primary" type="button" onclick="flush()">清空缓存</button></c:if></td>
							</tr>
                          </tbody>
                        </table>
                        <table id="backList" class="table table-bordered table-hover" style="display: none;">
                          <thead>
                            <tr>
                              <th style="text-align: center;">序号</th>
                              <th style="text-align: center;">评卷员</th>
                              <th style="text-align: center;">数量</th>
                              <th style="text-align: center;">操作</th>
                            </tr>
                          </thead>
                          <tbody id="backDetail">
                          </tbody>
                        </table>
                  </div>
                  <c:if test="${arbitrationCount==0 && problemCount==0 && backCount==0 && toMarkCount==0 && markSubjectStatus==1}"><button class="btn btn-primary" type="button" onclick="endedMark()">结束评卷</button></c:if>
              </div>
          </div>
    </div>
</body>
<script type="text/javascript">
var s;
$(document).ready(function() {
	var url='${ctx}/topicmarker/ending/getmarkers.json';
    $.ajax( {
    url : url,
    type : "POST", 
    data: null,
    success : function(val) {
    	s ='<p class="popover-list">';
    	for(var i=0;i<val.length;i++){
    		if(i!=0 &&(i%4)==0){
    			s+='<a href="javascript:void(0)" onclick="getMarkerId(this,'+val[i].id+')">'+val[i].name+'</a></br>';
    		}else{
    			s+='<a href="javascript:void(0)" onclick="getMarkerId(this,'+val[i].id+')">'+val[i].name+'</a>';
    		}
    	}
    	s+='</p>';
    	s+='<p class="popover-button">';
    	s+='<button class="btn" type="button" onclick="cancel()">取消</button>';
    	s+='<button class="btn btn-success" type="button" onclick="save()">保存</button>';
		s+='</p>';
    },
	error:function(e){
    	alert('通信发生错误，稍等片刻再重新提交！');
    }
    })
})

function viewBackInfo(){
	$("#backList").show();
	var url='${ctx}/topicmarker/ending/getmarkerbacklist.json';
    $.ajax( {
    url : url,
    type : "POST", 
    data: null,
    success : function(val) {
    	$("#backDetail").html("");
    	var str="";
    	for(var i=0;i<val.length;i++){
    		str+="<tr>";
    		str+="<td>"+parseInt((i+1))+"</td>";
    		str+="<td>"+val[i].name+"</td>";
    		str+="<td>"+val[i].backCount+"</td>";
    		str+="<td style='text-align: center;'><button id='assignButton' class='btn btn-small btn-info' onclick='assignMarker(this,"+val[i].id+")'>重新指定评卷员</button></td>";
    		str+="</tr>";
    	}
    	$("#backDetail").html(str);
    },
	error:function(e){
    	alert('通信发生错误，稍等片刻再重新提交！');
    }
    })
}
var oldMarkerId = 0;
function assignMarker(obj,markerId){
	oldMarkerId = markerId;
	var options={
			trigger:"click",
			placement:"left",
			html:true,
			title:"评卷员列表",
			content:s
	};
	$(obj).popover(options);
}
var newMarkerId = 0;
function getMarkerId(obj,markerId){
	$(obj).parent().find("a").each(function(){
		$(this).removeClass("curr");
	})
	$(obj).addClass("curr");
	newMarkerId = markerId;
}
function cancel(){
	$("#assignButton").popover('hide');
}
function save(){
	if(newMarkerId==0){
		alert('请选择一位新的评卷员');
		return false;
	}else{
		var data = {
				newMarkerId : newMarkerId,
				oldMarkerId : oldMarkerId
		}
		var url='${ctx}/topicmarker/ending/assign.json';
	    $.ajax( {
	    url : url,
	    type : "POST", 
	    data: data,
	    success : function(val) {
	    	$("#assignButton").popover('hide');
	    	alert("保存成功");
	    },
		error:function(e){
	    	alert('通信发生错误，稍等片刻再重新提交！');
	    }
	    })
	}
}
function endedMark(){
	var url='${ctx}/topicmarker/ending/getscansubjectstatus.json';
    $.ajax( {
    url : url,
    type : "POST", 
    data: null,
    success : function(val) {
    	if(val==0){
    		alert('当前科目还没结束扫描！');
    		return false;
    	}else if(val==1){
    		if(confirm("请确保所有评卷员都已评卷结束")){
    			var url='${ctx}/topicmarker/ending/endedmark.json';
    		    $.ajax( {
    		    url : url,
    		    type : "POST", 
    		    data: null,
    		    success : function(val) {
    		    	window.location.href="${ctx}/topicmarker/ending/ending-view";
    		    },
    			error:function(e){
    		    	alert('通信发生错误，稍等片刻再重新提交！');
    		    }
    		    })
    		}
    		
    	}else{
    		alert('当前科目已结束评卷！');
    		return false;
    	}
    },
	error:function(e){
    	alert('通信发生错误，稍等片刻再重新提交！');
    }
    })
	
}
function flush(){
    if(confirm("请确保所有评卷员都已停止评卷")){
		var url='${ctx}/topicmarker/ending/clear.json';
	    $.ajax( {
		    url : url,
		    type : "POST", 
		    data: null,
		    success : function(val) {
		    	window.location.href="${ctx}/topicmarker/ending/ending-view";
		    },
			error:function(e){
		    	alert('通信发生错误，稍等片刻再重新提交！');
		    }
    	})
    }
}
</script>
</html>
