<%@ 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/header.jsp"%>
	<%@ include file="../../leftMenu/exam-admin.jsp"%>
	<div data-options="region:'center',title:'首页 - 【考试管理】 - 评卷员管理'">
		<div>
			<div id="score-search-div">
				<form class="form-inline" action="${ctx}/admin/exam/score" method="post">
					<span class="help-inline">科目：</span> 
					<select name="subjectId" class="span2">
						<c:forEach var="subject" items="${subjectList}">
							<option value="${subject.id}"
								<c:if test="${subjectId!=null && subjectId==subject.id}">selected</c:if>>${subject.name}</option>
						</c:forEach>
					</select> 
					<span class="help-inline">文理科：</span> 
					<select name="classTypeValue" class="span2">
						<c:forEach var="classType" items="${classTypeList}">
							<option value="${classType.value}"
								<c:if test="${classTypeValue!=null && classTypeValue==classType.value}">selected</c:if>>${classType.name}</option>
						</c:forEach>
					</select>
					<span class="help-inline">准考证号：</span>
					<input type="text" name="studentCode" class="input-small" value="<c:if test="${studentCode!=null}">${studentCode}</c:if>">
					<button type="submit" class="btn">
						<i class="icon-search"></i> 查询
					</button>
				</form>
			</div>
			
			<c:if test="${subjectId!=''&&classTypeValue!=''&&studentCode!=''}">
				<c:if test="${score.score!=null}">
				    <div class="btn-group" style="margin: 10px;"><i class="btn" style="cursor: default;">总分</i><i class="btn btn-info totalScore-text" style="cursor: default;">${score.score}</i></div>
				</c:if>
			<div class="border" data-options="region:'center'">
				<div class="table-container col6" id="scoreDetail-list-div">
					<div class="tab-header">
						<i class="list-text"><strong>题号</strong></i> 
						<i class="list-text"><strong>大题号</strong></i> 
						<i class="list-text"><strong>小题号</strong></i> 
						<i class="list-text"><strong>分数</strong></i>
						<p class="list-edit">
							<strong>操作</strong>
						</p>
					</div>
					<c:forEach items="${scoreDetailList}" var="scoreDetail">
						<div class="tab-list scoreDetail-list" data-value="${scoreDetail.mainNumber}-${scoreDetail.subNumber}">
							<i class="list-text questionNumber-text">${scoreDetail.questionNumber}</i> 
							<i class="list-text mainNumber-text">${scoreDetail.mainNumber}</i>
							<i class="list-text subNumber-text">${scoreDetail.subNumber}</i>
							<i class="list-text score-text">${scoreDetail.score}</i>
							<p class="list-edit" <c:if test="${flag}">style="display:none"</c:if>>
								<a class="btn btn-primary edit-button">修改</a> 
							</p>
						</div>
						<div class="tab-edit scoreDetail-edit-list" data-value="${scoreDetail.mainNumber}-${scoreDetail.subNumber}" style="display: none">
							<i class="list-text">
								<input class="input-small uneditable-input questionNumber-input" type="text" value="${scoreDetail.questionNumber}" disabled />
							</i> 
							<i class="list-text">
								<input class="input-small uneditable-input mainNumber-input" type="text" value="${scoreDetail.mainNumber}" disabled /> 
							</i> 
							<i class="list-text">
								<input class="input-small uneditable-input subNumber-input" type="text" value="${scoreDetail.subNumber}" disabled /> 
							</i> 
							<i class="list-text">
								<input class="input-small score-input" type="text">
							</i>
							<p class="list-edit">
								<a class="btn btn-success save-button">保存</a> 
								<a class="btn cancel-button">取消</a>
							</p>
						</div>
					</c:forEach>				
					</div>
				</div>
			</c:if>
		</div>
	</div>
</body>
<script type="text/javascript">

$(document).ready(function() {
	$('.edit-button').live("click", function(){
		var scoreDetailDiv = $(this).parent().parent();
		var scoreDetail = {
				studentCode:'${score.studentCode}',
				examId:'${score.examId}',
				subjectId:'${score.subjectId}',
				schoolId:'${score.schoolId}',
				classType:'${score.classType}',
				questionNumber:scoreDetailDiv.find('.questionNumber-text').html(),
				mainNumber:scoreDetailDiv.find('.mainNumber-text').html(),
				subNumber:scoreDetailDiv.find('.subNumber-text').html(),
				score:scoreDetailDiv.find('.score-text').html()
		};
		var editDiv = $('.scoreDetail-edit-list[data-value="'+scoreDetail.mainNumber+'-'+scoreDetail.subNumber+'"]');
		editDiv.find('.score-input').val(scoreDetail.score);
		scoreDetailDiv.hide();
		editDiv.show();
	});
	
	$('.save-button').live("click", function(){
		var editDiv = $(this).parent().parent();
		var main_num=editDiv.find('.mainNumber-input').val();
		var sub_num=editDiv.find('.subNumber-input').val();
		var scoreDetailDiv = $('.scoreDetail-list[data-value="'+main_num+'-'+sub_num+'"]');
		
		var score_old=scoreDetailDiv.find('.score-text').html();
		var score_new=editDiv.find('.score-input').val();
		
		var score_total=$('.totalScore-text').html();
		score_total=parseFloat(score_total)+parseFloat(score_new)-parseFloat(score_old);
		var scoreDetail = {
				totalScore:score_total,
				studentCode:'${score.studentCode}',
				examId:'${score.examId}',
				subjectId:'${score.subjectId}',
				schoolId:'${score.schoolId}',
				classType:'${score.classType}',
				questionNumber:editDiv.find('.questionNumber-input').val(),
				mainNumber:editDiv.find('.mainNumber-input').val(),
				subNumber:editDiv.find('.subNumber-input').val(),
				score:editDiv.find('.score-input').val()
		}
		if(scoreDetail.score==''){
			alert("分数不能为空！");
			return;
		}
		$.post('${ctx}/admin/exam/score/update-score.json', scoreDetail, function(obj){
			if(obj.success){
				alert("修改成功");
				//var scoreDetailDiv = $('.scoreDetail-list[data-value="'+scoreDetail.mainNumber+'-'+scoreDetail.subNumber+'"]');
				scoreDetailDiv.find('.questionNumber-text').html(scoreDetail.questionNumber);
				scoreDetailDiv.find('.mainNumber-text').html(scoreDetail.mainNumber);
				scoreDetailDiv.find('.subNumber-text').html(scoreDetail.subNumber);
				scoreDetailDiv.find('.score-text').html(scoreDetail.score);
				
				$('.totalScore-text').html(score_total);
				editDiv.hide();
				scoreDetailDiv.show();
			}else{
				alert(obj.message);
			}
		});	
	});
	
	$('.cancel-button').live("click", function(){
		var id=$(this).parent().parent().attr('data-value');
		$('.scoreDetail-list[data-value="'+id+'"]').show();
		$(this).parent().parent().hide();
	});
});
</script>
</html>