<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../admin/common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../../admin/common/top.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>网上阅卷系统</title>
</head>
<body>
	<div class="container-fluid">
		<div class="row-fluid">
			<c:if test="${exam!=null}">
				<div class="span3">
					<p class="text-success">${exam.name}</p>
				</div>
				<div class="span6">
					科目选择： <select id="subject-select" data-exam-id="${exam.id}">
						<option value="">请选择</option>
						<c:forEach var="subject" items="${subjectList}">
							<option value="${subject.classTypes}">${subject.name}</option>
						</c:forEach>
					</select>
					<input class="btn btn-primary" value="刷新" id="refresh-button"/>
				</div>
			</c:if>
		</div>
		<div class="row-fluid">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th>ID</th>
						<th>标题</th>
						<th>任务总量</th>
						<th>任务总量(redis)</th>
						<th>队列数量</th>
						<th>队列数量(redis)</th>
						<th>已评数量</th>
						<th>已评数量(redis)</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="block-table" data-exam-id="">
				</tbody>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
	$('#subject-select').change(function(){
		var value= $(this).val();
		var examId = $(this).attr('data-exam-id');
		$('#refresh-button').removeClass('disabled');
		$('#block-table').empty();
		$('#block-table').attr('data-exam-id', examId);
		if(value!=''){
			$.post('${ctx}/monitor/mark/'+examId+'/'+value+'.json', function(list){
				if(list.length>0){
					for(var i in list){
						var warning = false;
						var row = '';
						row = row + '<td>'+list[i].id+'</td>';
						row = row + '<td>'+list[i].title+'</td>';
						row = row + '<td>'+list[i].totalCount+'</td>';
						row = row + '<td>'+list[i].totalCountRedis+'</td>';
						row = row + '<td>'+list[i].queueCount+'</td>';
						row = row + '<td>'+list[i].queueCountRedis+'</td>';
						row = row + '<td>'+list[i].markedCount+'</td>';
						row = row + '<td>'+list[i].markedCountRedis+'</td>';
						row = row + '<td>';
						if(list[i].queueCount>0 && list[i].queueCountRedis==0){
							row = row + '<input value="释放" class="release-button btn btn-primary"/>';
							warning = true;
						}
						if(list[i].totalCount!=list[i].totalCountRedis || list[i].markedCount!=list[i].markedCountRedis){
							row = row + '<input value="校正" class="correct-button btn btn-primary"/>';
							warning = true;
						}
						row = row + '</td></tr>';
						if(warning){
							row = '<tr class="warning" data-block-id="'+list[i].id+'">' + row;
						}else if (list[i].totalCount==list[i].markedCount){
							row = '<tr class="success" data-block-id="'+list[i].id+'">' + row;
						}else{
							row = '<tr class="info" data-block-id="'+list[i].id+'">' + row;
						}
						$('#block-table').append(row);
					}
				}
			});
		}
	});

	$('#refresh-button').live('click', function(){
		$(this).addClass('disabled');
		$('#subject-select').trigger('change');
	});

	$('.release-button').live('click', function(){
		$(this).addClass('disabled');
		var examId = $(this).parent().parent().parent().attr('data-exam-id');
		var blockId = $(this).parent().parent().attr('data-block-id');
		$.post('${ctx}/monitor/mark/'+examId+'/'+blockId+'/release.json', function(result){
			alert(result+'个任务已释放');
			$('#subject-select').trigger('change');
		});
	});

	$('.correct-button').live('click', function(){
		$(this).addClass('disabled');
		var examId = $(this).parent().parent().parent().attr('data-exam-id');
		var blockId = $(this).parent().parent().attr('data-block-id');
		$.post('${ctx}/monitor/mark/'+examId+'/'+blockId+'/correct.json', function(result){
			$('#subject-select').trigger('change');
		});
	});
});
</script>
</html>