<%@ 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" %>
	<%@include file="/WEB-INF/views/include/dialog.jsp" %>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/admin/exam-param/marker">评卷员列表</a></li>
		<li><a href="${ctx}/admin/exam-param/marker/form">添加评卷员</a></li>
		<li class="active"><a href="${ctx}/admin/exam-param/marker/assign">分配评卷员</a></li>
	</ul>
	<tags:message content="${message}"/>
	<form id="searchForm"  action="${ctx}/admin/exam-param/marker/assigned" method="post" class="breadcrumb form-search">
		<div>
			<label>科目：</label>
			<select id="subjectCode" name="subjectCode" class="" onchange="loadBlock()" style="width: 280px;">
				<option value="">请选择...</option>
				<c:forEach items="${subjectList }" var="subject">
					<option value="${subject.code }" <c:if test="${subject.code eq subjectCode }">selected="selected"</c:if>>${subject.code}-${subject.name }</option>
				</c:forEach>
			</select>
			<label>大题：</label>
			<span id="selectDiv"></span>
			&nbsp;<input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
		</div>
	</form>
	<ul class="nav nav-tabs">
		<li class="active"><a href="javascript:assigned();">已分配列表</a></li>
		<li><a href="javascript:toAssign();">未分配列表</a></li>
	</ul>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>科目</th>
				<th>大题</th>
				<th>评卷员</th>
				<th>代码</th>
				<th>密码</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${list}" var="obj">
			<tr>
				<td>${obj.subjectName}</td>
				<td>${obj.title}</td>
				<td>${obj.markerName }</td>
				<td>${obj.markerCode }</td>
				<td>${obj.markerPassword }</td>
				<td>
					<a href="javascript:void(0);" onclick="deleteMarker('${obj.markerId }')">删除</a>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${query}</div>
	<form id="delFrm" action="${ctx}/admin/exam-param/marker/delblockmarker" method="post">
		<input type="hidden" id="subject_code" name="subject_code">
		<input type="hidden" id="block_id" name="block_id">
		<input type="hidden" id="markerId" name="markerId">
	</form>
<script type="text/javascript">
var code = '${subjectCode}';
if(code.length>0){
	loadBlock();
}

function loadBlock(){
	var subjectCode = $("#subjectCode").val();
	var data = {
		subjectCode : subjectCode
	}
	var blockId = '${blockId}';
	var selectDiv = "<select id='blockId' name='blockId' class='input-small'>";
	selectDiv += "<option value=''>请选择...</option>";
	 $.post("${ctx}/admin/exam-param/marker/loadoption",data,function(result){
		 $(result).each(function(i,obj){
			 if(blockId.length>0){
				 if(blockId==obj.id){
					 selectDiv += "<option value='"+obj.id+"' selected>"+obj.title+"</option>";
				 }else{
					 selectDiv += "<option value='"+obj.id+"'>"+obj.title+"</option>";
				 }
			 }else{
				 selectDiv += "<option value='"+obj.id+"'>"+obj.title+"</option>";
			 }
		})
		selectDiv +="</select>";
		$("#selectDiv").html("");
		$("#selectDiv").html(selectDiv);
	  });
	 
}

function goSearch(){
	var subjectCode = $("#subjectCode").val();
	var blockId = $("#blockId").val();
	if(subjectCode.length==0){
		$.jBox.info("请先选择科目及大题，然后再查询");
		return false;
	}
	if(blockId.length==0){
		$.jBox.info("请先选择科目及大题，然后再查询");
		return false;
	}
	$("#searchForm").submit();
}
function assigned(){
	var subjectCode = $("#subjectCode").val();
	var blockId = $("#blockId").val();
	if(subjectCode.length==0){
		$.jBox.info("请先选择科目及大题，然后再查询");
		return false;
	}
	if(blockId.length==0){
		$.jBox.info("请先选择科目及大题，然后再查询");
		return false;
	}
	$("#searchForm").attr("action","${ctx}/admin/exam-param/marker/assigned");
	$("#searchForm").submit();
}
function toAssign(){
	var subjectCode = $("#subjectCode").val();
	var blockId = $("#blockId").val();
	if(subjectCode.length==0){
		$.jBox.info("请先选择科目及大题，然后再查询");
		return false;
	}
	if(blockId.length==0){
		$.jBox.info("请先选择科目及大题，然后再查询");
		return false;
	}
	$("#searchForm").attr("action","${ctx}/admin/exam-param/marker/toassign");
	$("#searchForm").submit();
}

function deleteMarker(markerId){
	 $.jBox.confirm("您确定要删除此评卷员吗？", "提示", function(v, h, f) {
	     if (v == "ok") {
	    	$("#subject_code").val($("#subjectCode").val());
    		$("#block_id").val($("#blockId").val());
    		$("#markerId").val(markerId);
    		$("#delFrm").submit(); 
	     }else{
	    }
	});
}
</script>	
</body>
</html>