<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>试题列表</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<style type="text/css">.sort{color:#0663A2;cursor:pointer;}</style>
	<script type="text/javascript">
	//js中Enter键类似Tab键的功能
	function handleEnter (field, event) {
	    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	    if (keyCode == 13) {
	        var i;
	        for (i = 0; i < field.form.elements.length; i++)
	            if (field == field.form.elements[i])
	            break;
	            i = (i + 1) % field.form.elements.length;
	            field.form.elements[i].focus();
	            return false;
	    }
	    else
	    return true;
	}
	   </script>
</head>
<body>
	<form>
		<div style="margin-top:20px;margin-left:10px;">
			<input type="button" value="提交" class="btn btn-primary" onclick="save('${subjectCode}','${examSubjectPaperId}','${objective}');"/>
			<a href="${ctx}/admin/exam-param/subjectPaper/examQuestionTypeEdit?subjectCode=${subjectCode}" class="btn btn-primary">返回</a>
		</div>
		
	<table id="contentTable" class="table table-striped table-bordered table-condensed" style="margin-top:20px;">
		<caption align="center">${subjectCode}-${subjectName}</caption> 
		<thead>
			<tr>
				<th>标题</th>
				<th>大题号</th>
				<th>小题号</th>
				<th>间隔分</th>
				<th>满分</th>
				<th>答案</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${ExamSubjectPaperDTOList}" var="ExamSubjectPaperDTO">
			<tr>
				<td>${ExamSubjectPaperDTO.title}</td>
				<td>${ExamSubjectPaperDTO.mainNumber}</td>
				<td>${ExamSubjectPaperDTO.subNumber}</td>
				<td>${ExamSubjectPaperDTO.intervalScore}</td>
				<td>
					<input onkeypress="return handleEnter(this,event)" class="${ExamSubjectPaperDTO.scoreClass}" <c:if test="${ExamSubjectPaperDTO.subNumber>ExamSubjectPaperDTO.count}">readonly</c:if>  value="${ExamSubjectPaperDTO.socre}" style="width:60px;"/>
				</td>
				<td>
					<input onkeypress="return handleEnter(this,event)" class="${ExamSubjectPaperDTO.answerClass}" <c:if test="${ExamSubjectPaperDTO.subNumber>ExamSubjectPaperDTO.count}">readonly</c:if> <c:if test="${ExamSubjectPaperDTO.objective =='0'}">readonly</c:if> value="${ExamSubjectPaperDTO.answer}" style="width:60px;" />
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	
	</form>
<script type="text/javascript">
	function save(code,id,objective){
		var url = "${ctx}/admin/exam-param/subjectPaper/detailSave";
		var inputCount = $("table input").length;
		var dataJson = {};
		var dataJsonTemp = [];
		for(var i =1;i<=inputCount/2;i++){
			var tempData = {};
			tempData.subNumber = i;
			tempData.answer = $(".answer"+i).val();
			tempData.score = $(".score"+i).val();
			dataJsonTemp.push(tempData);
		}
		dataJson.data = dataJsonTemp;
		dataJson.subjectCode = code;
		dataJson.examSubjectPaperId = id;
		dataJson.objective = objective;
		var jsonString = JSON.stringify(dataJson);
		$.post(url,{jsonString:jsonString},function(obj){
			jBox.tip(obj.msg);
			if(obj.success){
				window.location.href = "${ctx}/admin/exam-param/subjectPaper/examQuestionTypeEdit?subjectCode=" +code;
			}
		});
	}
</script>	
</body>
</html>