<%@ 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>
<title>启明网上阅卷系统</title>
<link rel="stylesheet" type="text/css" href="${ctx}/static/mark/style/bootstrap.css">
<link rel="stylesheet" type="text/css" href="${ctx}/static/mark/style/mark.css"/>
<link rel="stylesheet" type="text/css" href="${ctx}/static/mark/js/jqueryalert/jquery.alerts.css"/>
<script type="text/javascript" src="${ctx}/static/mark/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${ctx}/static/mark/js/json2.js"></script>
<script type="text/javascript" src="${ctx}/static/mark/js/interface.js"></script>
<script type="text/javascript" src="${ctx}/static/mark/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${ctx}/static/mark/js/jqueryalert/jquery.alerts.js"></script>
<script type="text/javascript" src="${ctx}/static/plugin/swfobject.js"></script>
<script type="text/javascript" src="${ctx}/static/plugin/swfplugin.js"></script>
</head>
<body>
<script type="text/javascript">
	var $ = jQuery;
	$(document).ready(function() {
		$('#layer1').Draggable({
			zIndex : 20,
			ghosting : false,
			opacity : 0.7,
			handle : '#layer1_handle'
		});
		$("#layer1").show();

	});
</script>
	<div class="navbar">
		<div class="navbar-inner">
			<div class="container">
				<div class="nav-collapse collapse navbar-responsive-collapse">
					<ul class="nav nav-title">姓名：${subjectHeader.name }&nbsp;&nbsp;科组长</ul>
					<ul class="nav pull-right">
						<li><a href="#">评分标准</a></li>
						<li><a href="${ctx }/subjectheader/arbitration">返回</a></li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<div class="row-fluid mr-t">
		<div class="span9" style="z-index:-99999">
			<div id="viewer" class="viewer iviewer_cursor" ></div>
		</div>
		<div class="span3">
    		<table class="table table-bordered table-hover">
              <thead>
                <tr>
                  <th>序号</th>
                  <th>密号</th>
                  <th>分值列表</th>
                  <th>评卷员</th>
                </tr>
              </thead>
              <tbody>
              <c:if test="${arbitrationLibrary.type.value==1 }">
              	<c:forEach items="${arbitrationLibrary.tryHistoryList }" var="tryHistory" varStatus="status">
              	<tr onclick="showNumber(this,'${tryHistory.scoreList }')" >
              	<input type="hidden" id="history_id" name="history_id" value="${tryHistory.id }"/>
                  <td>${status.count }</td>
                  <td>${arbitrationLibrary.secretNo }</td>
                  <td>${tryHistory.scoreList }</td>
                  <td>${tryHistory.marker.name }</td>
                </tr>
              </c:forEach>
              </c:if>
              <c:if test="${arbitrationLibrary.type.value==2 }">
              	<c:forEach items="${arbitrationLibrary.formallyHistoryList }" var="formallyHistory" varStatus="status">
              	<tr onclick="showNumber(this,'${formallyHistory.scoreList }')" >
              	<input type="hidden" id="history_id" name="history_id" value="${formallyHistory.id }"/>
                  <td>${status.count }</td>
                  <td>${arbitrationLibrary.secretNo }</td>
                  <td>${formallyHistory.scoreList }</td>
                  <td>${formallyHistory.marker.name }</td>
                </tr>
              </c:forEach>
              </c:if>
              </tbody>
            </table>               
    	</div>
		    <div id="layer1" class="mark">
		        <div id="layer1_handle" class="mark-title">可移动</div>
		        <div id="layer1_content">
		          <div class="mark-content">
		              <p class="title">${arbitrationLibrary.subjectiveBlock.title}</p>
		                <ul id="markBlock">
		                <c:forEach items="${arbitrationLibrary.subjectiveBlock.markStepList}" var="step" varStatus="status">
	                 		<c:if test="${empty step.markLevelList}">
	                 			<li>
			                 		<em>${status.count}.</em>
			                 		<c:forEach items="${step.scoreArray}" var="score">
				                 		<a href="#" onclick="mark(this,${score})">${score}</a>
			                 		</c:forEach>
		                 		</li>
	                 		</c:if>
		                 		<c:if test="${!empty step.markLevelList}">
		                 			<li>
			                 			<em>${status.count}.</em>
			                 			<span class="rank">
			                 			<c:forEach items="${step.markLevelList}" var="level" varStatus="levelStatus">
			                 				<a id="leveScorelList${level.min}-${level.max}" href="#" onclick="level(this,${levelStatus.count})">${level.name}</a>
			                 				<i id="levelScore${levelStatus.count}" class="fine" style="display: none;">
				                 				<c:forEach items="${level.scoreList }" var="lelvelScore">
				                 					<a href="#" onclick="levelMark(this,${lelvelScore})">${lelvelScore }</a>
				                 				</c:forEach>
			                 				</i>
			                 			</c:forEach>
			                 			<span class="temp"></span>
			                 			</span>
			                 		</li>
		                 		</c:if>
		                 	
		                 </c:forEach>
		                 <li  class="mr-l">合计：<i class="text-error"><strong id="count">0分</strong></i></li>
		                </ul>
		                <p class="bottom">
		                	<button class="btn btn-small btn-primary mr1" type="button" onclick="saveMark()">给分</button>
		                	<button class="btn btn-small btn-primary mr1" type="button">全卷</button>
		                </p>
		             </div>
		        </div>
		     </div>
		</div>
		<form id="markFrm" action="${ctx}/subjectheader/arbitration/mark" method="post">
			<input type="hidden" id="libraryId" name="libraryId" value="${arbitrationLibrary.id}"/>
			<input type="hidden" id="spent" name="spent" value="${startTime}"/>
			<input type="hidden" id="type" name="type" value="${arbitrationLibrary.type.value}"/>
			<input type="hidden" id="totalScore" name="totalScore" value=""/>
			<input type="hidden" id="scoreList" name="scoreList" value=""/>
		</form>
<script type="text/javascript">
var currentConfig = '';
var urls = [];
<c:forEach var="url" items="${arbitrationLibrary.pictureUrls}">
urls.push('${url}'.replace(/[\[\]\"]/g, ''));
</c:forEach>
var config = '${arbitrationLibrary.pictureConfig}';
$(document).ready(function(){
	$(".rank").each(function(){
		var rank = $(this);
		rank.find('i').appendTo(rank.find('.temp'));
	});
	initImageViewPluginDefault("${ctx}/static/plugin/", "viewer");
});
//构造string endWith()方法
String.prototype.endWith=function(s){
  if(s==null||s==""||this.length==0||s.length>this.length)
     return false;
  if(this.substring(this.length-s.length)==s)
     return true;
  else
     return false;
  return true;
}
String.prototype.startWith=function(s){
  if(s==null||s==""||this.length==0||s.length>this.length)
   return false;
  if(this.substr(0,s.length)==s)
     return true;
  else
     return false;
  return true;
}

function creationComplete(){
	refreshPictureConfig();
	if(currentConfig!=undefined && currentConfig!=''){
		getSwfObject('ImageViewer').setJson(currentConfig);
	}
}
	 
function loadComplete(){
}
	 
function refreshPictureConfig(){
	if(urls!=undefined && urls.length>0 && config!=undefined && config!=''){
		var imgServer="${imageServer}";
		for(var i=0;i<urls.length;i++){
			eval('config=config.replace(/\\{'+i+'\\}/, "'+(imgServer+urls[i])+'")');
		} 
		currentConfig=config;
	}
}
 
var count=parseFloat("0") ;
function mark(obj,score){
	$(obj).parent().find("a").each(function(){
		if($(this).hasClass("curr")){
			$(this).removeClass("curr");
		    count-=parseFloat($(this).html());
		}
		if(parseFloat($(this).html())==score){
			$(obj).addClass("curr");
			count+=parseFloat($(obj).html());
		}
	  });
	
	$("#count").html(count+"分");
}
function levelMark(obj,score){
	$(obj).parent().parent().find("a").each(function(){
		if($(this).hasClass("curr")){
			$(this).removeClass("curr");
		    count-=parseFloat($(this).html());
		}
		if(parseFloat($(this).html())==score){
			$(obj).addClass("curr");
			count+=parseFloat($(obj).html());
		}
	  });
	
	$("#count").html(count+"分");
}
function level(obj,index){
	$(obj).siblings("a").each(function(){
		if($(this).hasClass("curr")){
			$(this).removeClass("curr");
		}
	  });
	$(obj).addClass("curr");
	$("[id^=levelScore]").hide();
	$("#levelScore"+index).show(); 
	
}
var key_code="";
$(document).keyup(function(e){
	 if(e.which==48||e.which==96){
		key_code += "0";
	}else if(e.which==49||e.which==97){
		key_code += "1";
	}else if(e.which==50||e.which==98){
		key_code += "2";
	}else if(e.which==51||e.which==99){
		key_code += "3";
	}else if(e.which==52||e.which==100){
		key_code += "4";
	}else if(e.which==53||e.which==101){
		key_code += "5";
	}else if(e.which==54||e.which==102){
		key_code += "6";
	}else if(e.which==55||e.which==103){
		key_code += "7";
	}else if(e.which==56||e.which==104){
		key_code += "8";
	}else if(e.which==57||e.which==105){
		key_code += "9";
	}else if(e.which==110||e.which==190){
		key_code += ".";
	}else if(e.which==13){
		if(key_code=="."){
			key_code="0.5";
		}else if(key_code.toString().endWith(".")){
			key_code+="5";
		}else{
			key_code=key_code;
		}
		var score = parseFloat(key_code);
		var index =-1;
		var block = $("#markBlock").find("li");
		for(var i=0;i<block.length;i++){
			var a = $(block[i]).find("a");
			for(var j=0;j<a.length;j++){
				if($(a[j]).hasClass("curr")){
					index = i;
				}
			}
		} 
		if((index+2)==block.length){
			saveMark();
		}else{
			$(block[index+1]).find("a").each(function(){
				var s1= $(this);
				if(s1.html()==score ){
					mark(s1,score);
					if(s1.parent().parent().hasClass("temp")){
						$("[id^=levelScore]").hide();
						s1.parent().show();
						
						s1.parent().parent().parent().find("[id^=leveScorelList]").each(function(){
							var s2 = $(this);
							var s = s2.attr("id");
							var str = s.substr(14,s.length);
							var strs= new Array(); 
							strs=str.split("-"); 
							if(parseFloat(score)>=parseFloat(strs[0])&& parseFloat(score)<=parseFloat(strs[1])){
								s2.addClass("curr");
							}
						});
					}
				}
			});
		}
		
		
		
		key_code="";
	}else{
		key_code="";
	}
}); 

function saveMark(){
	var index =0;
	var block = $("#markBlock").find("li");
	for(var i=0;i<block.length;i++){
		
		if($(block[i]).find(".fine").length>0){
			$(block[i]).find(".fine").each(function(){
				var is = $(this);
				is.find("a").each(function (){
					var as = $(this);
					if(as.hasClass("curr")){
						index++;
					}
				});
			});
		}else{
			if($(block[i]).find(".curr").length>0){
				index++;
			}
		}
	} 
	if((index+1)< block.length){
		alert("还有步骤没有给分");
		return false;
	}else{
		$("#totalScore").val(count);
		
		var block = $("#markBlock").find("li");
		var list = "";
		for(var i=0;i<block.length;i++){
			
			if($(block[i]).find(".fine").length>0){
				$(block[i]).find(".fine").each(function(){
					var is = $(this);
					is.find("a").each(function (){
						var as = $(this);
						if(as.hasClass("curr")){
							list +=as.html()+","
						}
					});
				});
			}else{
				$(block[i]).find("a").each(function(){
					var a = $(this);
					if(a.hasClass("curr")){
						list += a.html()+",";
					}
				});
			}
		}
		if(list.length>0){
			list = list.substring(0,list.length-1);
		}
		$("#scoreList").val(list);
		$("#markFrm").submit();
	}
}

function showNumber(obj,scoreList){
	count=parseFloat("0") ;
	var tbody = $(obj).parent();
	$(tbody).find("tr").each(function(){
		$(this).removeClass("active");
	});
	
	$("[id^=levelScore]").hide();
	
	$(obj).addClass("active");
	var scores = scoreList.split(",");
	var lis = $("#markBlock").find("li");
	for(var i=0;i<lis.length;i++){
		var li = $(lis[i]);
		if(li.find("span[class='temp']").length>0){
			li.find(".fine").each(function(){
				var is = $(this);
				is.find("a").each(function(){
					var a = $(this);
					a.removeClass("curr");
					if(parseFloat(a.html())==parseFloat(scores[i])){
						a.addClass("curr");
						a.parent().show();
						
						a.parent().parent().parent().find("[id^=leveScorelList]").each(function(){
							var s2 = $(this);
							var s = s2.attr("id");
							var str = s.substr(14,s.length);
							var strs= new Array(); 
							strs=str.split("-"); 
							if(parseFloat(a.html())>=parseFloat(strs[0])&& parseFloat(a.html())<=parseFloat(strs[1])){
								s2.siblings("a").removeClass("curr");
								s2.addClass("curr");
							}
						});
						
						count += parseFloat(scores[i]);
					}
				});
			});
		}else{
			li.find("a").removeClass("curr");
			li.find("a").each(function(){
				if(parseFloat($(this).html())==parseFloat(scores[i])){
					mark($(this),scores[i]);
				}
			});
		}
	}
}
</script>
</body>
</html>
