<%@ 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 class="border mr-t" data-options="region:'center'">
			<c:if test="${! empty list}">	
				<ul class="nav nav-tabs" id="myTab">
				  <c:forEach items="${list }" var="examPaper" varStatus="status">
				  	<li <c:if test="${status.count==0 }">class="active"</c:if>><a id="tab-${examPaper.id }" href="#home${examPaper.id }">${examPaper.subjectName }</a></li>
				  </c:forEach>	
	            </ul>
	            <div class="tab-content">
	            	<c:forEach items="${list }" var="examPaper" varStatus="status">
	            		<div class="tab-pane active" id="home${examPaper.id }">
	            			<table class="table table-bordered table-hover ">
							  <thead>
							  	<tr>
							      <th>题号</th>
							      <th>是否客观题</th>
							      <th>分数</th>
							      <th>答案</th>
							      <th>知识点</th>
							      <th>题型</th>
							      <th>难度</th>
							    </tr>
							  </thead>
							  <tbody id="paperDetail${examPaper.id }">
							  </tbody>
							</table>
	            		</div>
	            	</c:forEach>
	            </div>
	    	</c:if>
		</div>
	</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
	$('#myTab a:first').tab('show');
	var temp = $('#myTab a:first').attr("id").split("-");
	var paperId = temp[1];
	getDetail(paperId);
});
$('#myTab a').click(function (e) {
  e.preventDefault();
  $(this).tab('show');
  var temp = $(this).attr("id").split("-");
  var paperId = temp[1];
	getDetail(paperId);
 
});

function getDetail(paperId){
	 var data = {
			 paperId:paperId
	  };
	  var url='${ctx}/admin/analysis/subject/getdetail.json';
	  $.ajax( {
	  url : url,
	  type : "POST", 
	  data: data,
	  success : function(val) {
		  $("#paperDetail"+paperId).html("");
		  $("#paperDetail"+paperId).parent().next().remove();
		  var str = "";
		  for(var i=0;i<val.length;i++){
			  str += "<tr>";
			  str += "<td>"+val[i].questionNumber+"</td>";
			  if(val[i].objective){
				  str += "<td>是</td>";
			  }else{
				  str += "<td>否</td>";
			  }
			  
			  str += "<td>"+val[i].totalScore+"</td>";
			  if(val[i].objective){
				  str += "<td>"+val[i].answer+"</td>";
			  }else{
				  str += "<td>-</td>";
			  }
			  
			  str += "<td><input type='hidden' id='key"+paperId+"' value='"+val[i].id+"'><input type='text' id='knowledge"+paperId+"' class='input-middle' value='"+val[i].knowledges+"'/></td>";
			  str += "<td><input type='text' id='questionType"+paperId+"' class='input-medium' value='"+val[i].questionType+"'/></td>";
			  str += "<td><select id='difficult"+paperId+"'  class='span1'>";
			  				if(val[i].difficulty==0.1){
			  					str +="<option value='0.1' selected>0.1</option>";
			  				}else{
			  					str +="<option value='0.1'>0.1</option>";
			  				}
							if(val[i].difficulty==0.2){
								str +="<option value='0.2' selected>0.2</option>";
							}else{
								str +="<option value='0.2'>0.2</option>";
							}
							if(val[i].difficulty==0.3){
								str +="<option value='0.3' selected>0.3</option>";
							}else{
								str +="<option value='0.3'>0.3</option>";
							}
							if(val[i].difficulty==0.4){
								str +="<option value='0.4' selected>0.4</option>";
							}else{
								str +="<option value='0.4'>0.4</option>";
							}
							if(val[i].difficulty==0.5){
								str +="<option value='0.5' selected>0.5</option>";
							}else{
								str +="<option value='0.5'>0.5</option>";
							}
							if(val[i].difficulty==0.6){
								str +="<option value='0.6' selected>0.6</option>";
							}else{
								str +="<option value='0.6'>0.6</option>";
							}
							if(val[i].difficulty==0.7){
								str +="<option value='0.7' selected>0.7</option>";
							}else{
								str +="<option value='0.7'>0.7</option>";
							}
							if(val[i].difficulty==0.8){
								str +="<option value='0.8' selected>0.8</option>";
							}else{
								str +="<option value='0.8'>0.8</option>";
							}
							if(val[i].difficulty==0.9){
								str +="<option value='0.9' selected>0.9</option>";
							}else{
								str +="<option value='0.9'>0.9</option>";
							}
							if(val[i].difficulty==1.0){
								str +="<option value='1.0' selected>1.0</option>";
							}else{
								str +="<option value='1.0'>1.0</option>";
							}
			  				
			  				+"</select></td>";
			  str += "</tr>";
		  }
		  $("#paperDetail"+paperId).html(str);
		  $("#paperDetail"+paperId).parent().after("<button class='btn btn-primary' onclick='save("+paperId+")'>保存</button>");
	  },
		error:function(e){
	  	alert('通信发生错误，稍等片刻再重新提交！');
	  }
	  })
}

function save(paperId){
	var data = [];
	$("#paperDetail"+paperId+" tr" ).each(function(){
		var tds = $(this).find("td");
		var questionNumber = $(tds[0]).html();
		var id  = $(this).find("#key"+paperId).val();
		var knowledge = $(this).find("#knowledge"+paperId).val();
		var questionType = $(this).find("#questionType"+paperId).val();
		var difficult = $(this).find("#difficult"+paperId).val();
		var obj = {};
		obj.id = id;
		obj.paperId=paperId;
		obj.questionNumber=questionNumber,
		obj.knowledges=knowledge;
		obj.questionType=questionType;
		obj.difficulty=difficult;
		data.push(obj);
	});
	
	 var url='${ctx}/admin/analysis/subject/savedetail.json';
	 $.ajax( {
	    url : url,
	    type : "POST", 
	    dataType:"json",
	    contentType:'application/json;charset=UTF-8',
	    data:JSON.stringify(data),
	    success : function(val) {
	    	alert("保存成功！");
	    	getDetail(paperId);
	    },
		error:function(e){
	  	alert('通信发生错误，稍等片刻再重新提交！');
	  }
	  })
}
</script>
</html>
