<%@ 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 id="importBox" class="hide">
		<form id="importForm" action="${ctx}/exam/student/import" method="post" enctype="multipart/form-data"
			style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
			<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
			<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
			<a href="${ctx}/exam/student/import/template">下载模板</a>
		</form>
	</div>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/exam/student/list">考生列表</a></li>
		<li><a href="${ctx}/exam/student/form">考生添加</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="student" action="${ctx}/exam/student/list" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="orderBy" name="orderBy" type="hidden" value="${page.orderBy}"/>
		<div>
			<label>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</label><form:input path="name" htmlEscape="false" maxlength="50" class="input-small"/>
			<label>身份证号：</label><form:input path="idCard" htmlEscape="false" maxlength="18" class="input-small"/>
		</div><div style="margin-top:8px;">
			<label>准考证号：</label><form:input path="examNumber" htmlEscape="false" maxlength="50" class="input-small"/>
			<label>专&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;业：</label><form:select id="profession.code" path="profession.code" class="input-small"><form:option value="" label="请选择..."/><form:options items="${professionList}" itemValue="code" itemLabel="name" htmlEscape="false"/></form:select>
			&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" onclick="return page();"/>
			&nbsp;<input id="btnExport" class="btn btn-primary" type="button" value="导出"/>
			&nbsp;<input id="btnImport" class="btn btn-primary" type="button" value="导入"/>
		</div>
	</form:form>
	<tags:message content="${message}"/>
	<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>
				<th>手机</th>
				<th>创建时间</th>
				<shiro:hasPermission name="exam:student:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="student">
			<tr>
				<td><a href="${ctx}/exam/student/form?id=${student.id}">${student.name}</a></td>
				<td>${student.idCard }</td>
				<td>${student.examNumber }</td>
				<td>${student.profession.name }</td>
				<td>${student.sex eq '1'?'男':'女'}</td>
				<td>${student.age }</td>
				<td>${student.phone }</td>
				<td>${student.createDate}</td>
				<shiro:hasPermission name="exam:student:edit"><td>
    				<a href="${ctx}/exam/student/form?id=${student.id}">修改</a>
					<a href="${ctx}/exam/student/delete?id=${student.id}" onclick="return confirmx('确认要删除该考生吗？', this.href)">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
	$('.pagination a').click(function(){
		var pageNumber = $(this).attr('data-page');
		if(pageNumber!=undefined && pageNumber>0){
			$('#search-form input[name="pageNumber"]').val(pageNumber);
			$('#search-form').submit();
		}
	});
	$('.edit-button').click(function(){
		var listDiv = $(this).parent().parent();
		var editDiv = $('.tab-edit[data-id="'+listDiv.attr('data-id')+'"]');
		editDiv.find('input[name="name"]').val(listDiv.find('i[name="name"]').html());
		editDiv.find('input[name="classCode"]').val(listDiv.find('i[name="classCode"]').html());
		editDiv.find('select[name="classType"]').val(listDiv.attr('data-class-type'));
		editDiv.find('select[name="graduateType"]').val(listDiv.attr('data-graduate-type'));
		listDiv.hide();
		editDiv.show();
	});
	$('.cancel-button').click(function(){
		var editDiv = $(this).parent().parent();
		var listDiv = $('.tab-list[data-id="'+editDiv.attr('data-id')+'"]');
		editDiv.hide();
		listDiv.show();
	});
	$('.delete-button').click(function(){
		var listDiv = $(this).parent().parent();
		var editDiv = $('.tab-edit[data-id="'+listDiv.attr('data-id')+'"]');
		if(confirm('确认要删除该考生吗？')){
			$.post('${ctx}/admin/exam-param/student/delete', {studentId: listDiv.attr('data-id')}, function(obj){
				if(obj.success){
					listDiv.remove();
					editDiv.remove();
					alert("删除成功");
				}else{
					alert(obj.message);
				}
			});
		}
	});
	$('.save-button').click(function(){
		var editDiv = $(this).parent().parent();
		var listDiv = $('.tab-list[data-id="'+editDiv.attr('data-id')+'"]');
		var student ={
			id: editDiv.attr('data-id'),
			name: editDiv.find('input[name="name"]').val(),
			classCode: editDiv.find('input[name="classCode"]').val(),
			classTypeValue: editDiv.find('select[name="classType"]').val(),
			graduateTypeValue: editDiv.find('select[name="graduateType"]').val(),
			
		};
		student.classTypeName = editDiv.find('select[name="classType"] option[value="'+student.classTypeValue+'"]').attr('name');
		student.graduateTypeName = editDiv.find('select[name="graduateType"] option[value="'+student.graduateTypeValue+'"]').attr('name');
		if(student.name==''){
			alert('请输入考生姓名');
			return;
		}
		if(student.classCode==''){
			alert('请输入班级代码');
			return;
		}
		$.post('${ctx}/admin/exam-param/student/update.json', student, function(obj){
			if(obj.success){
				alert("保存成功");
				listDiv.find('i[name="name"]').html(student.name);
				listDiv.find('i[name="classCode"]').html(student.classCode);
				listDiv.find('i[name="classType"]').html(student.classTypeName);
				listDiv.find('i[name="graduateType"]').html(student.graduateTypeName);
				listDiv.attr('data-class-type', student.classTypeValue);
				listDiv.attr('data-graduate-type', student.graduateTypeValue);
				editDiv.hide();
				listDiv.show();
			}else{
				alert(obj.message);
			}
		});	
	});
	
	$('#multi-checkbox').click(function(){
		if($(this).attr('checked')){
			$('.tab-list :checkbox').each(function(index, obj){
				$(obj).attr("checked","true");
			});
		}else{
			$('.tab-list :checkbox').each(function(index, obj){
				$(obj).removeAttr("checked");
			});
		}
		if($('input:checked').length>0){
			$('#tab-search').show();
		}else{
			$('#tab-search').hide();
		}
	});
	$('.student-checkbox').click(function(){
		if($('input:checked').length>0){
			$('#tab-search').show();
		}else{
			$('#tab-search').hide();
		}
	});
	$('#clear-all-button').click(function(){
		if(confirm('确定清空所有考生吗？')){
			window.location.href="${ctx}/admin/exam-param/student/clear";
		}
	});
	
	$('#delete-all-button').click(function(){
		var studentIds=new Array();
		$('.list-checkbox').find('input[type=checkbox]:checked').each(function(index,obj){
			var studentId=$(obj).parent().parent().attr('data-id');
			studentIds.push(studentId);
		});
		multiDel(studentIds);
	});
});

function multiDel(studentIds){
	if(studentIds.length>0 && confirm('确定删除这些学生吗？')){
		$.post('${ctx}/admin/exam-param/student/delete-all.json', {studentIds: studentIds.join(',')}, function(obj){
			if(obj.count>0){
				$.each(obj.ids.split(','), function(index, id){
					$('.tab-list[data-id="'+id+'"]').remove();
					$('.tab-edit[data-id="'+id+'"]').remove();
				});
			}
			$('.list-num').find('input[type=checkbox]').removeAttr("checked");
		});
	}
};
</script>
</html>