<%@ 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/campus-admin.jsp"%>
	<div data-options="region:'center',title:'首页 -【基础数据维护】- 学生信息管理'">
		<div class="easyui-layout" data-options="fit:true,border:false">
			<div data-options="region:'north',border:false" class="domain">
				<form id="search-form" class="form-inline fl">
					<span class="help-inline">姓名：</span> 
					<input class="input-mini" type="text" id="studentName" name="studentName"/> 
					<span class="help-inline">班级：</span> 
					<select class="span2" name="classCode" id="classCode">
						<option value="">不限</option>
						<c:forEach items="${classes}" var="c">
							<option value="${c}">${c}</option>
						</c:forEach>
					</select> 
					<span class="help-inline">学号：</span> 
					<input class="input-mini" type="text" id="studentCode" name="studentCode"/> 
					<span class="help-inline">级别：</span> 
					<select class="span2" id="schoolLevel" name="schoolLevelValue" onchange="selectGY(this.value)">
						<option value="-1">请选择</option>
						<c:forEach items="${level}" var="l">
							<option value="${l.value}">${l.name}</option>
						</c:forEach>
					</select> 
					<span class="help-inline">毕业年份：</span> 
					<select class="span2" id="graduateYear" name="graduateYear">
						<c:forEach items="${graduateYear}" var="gy">
							<option value="${gy}">${gy}</option>
						</c:forEach>
					</select>
					<button class="btn">
						<i class="icon-search"></i>&nbsp;查询
					</button>
				</form>
				<a href='${ctx}/admin/student/add/${schoolId}'>
					<button class="btn btn-primary fr" type="button">
						<i class="icon-plus icon-white"></i> 添加学生
					</button> 
				</a>
			</div>
			<div data-options="region:'center'" style="border-color: #ccc; border-left: none;">
				<table class="easyui-datagrid" id="dg"
					data-options="loadMsg:'正在查询请稍等...',pagination:'true',url:'${ctx}/admin/student/pagelist.json',rownumbers:true,singleSelect:true,fit:true,border:false,fitColumns:true,striped:true">
					<thead>
						<tr>
							<th width="15%" data-options="field:'studentCode'"><strong>学籍号</strong></th>
							<th width="15%" data-options="field:'name'"><strong>姓名</strong></th>
							<th width="10%" data-options="field:'gender',formatter:gender"><strong>性别</strong></th>
							<th width="15%" data-options="field:'classCode'"><strong>班级</strong></th>
							<th width="15%" data-options="field:'schoolLevel',formatter:schoolLevel"><strong>级别</strong></th>
							<th width="10%" data-options="field:'graduateYear'"><strong>毕业年份</strong></th>
							<th width="20%" data-options="field:'statupps',formatter:operate"><strong>操作</strong></th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		$("#studentItem").addClass("active");
		$("#schoolItem").removeClass("active");
	});

	$('#search-form').submit(function(event) {
		event.preventDefault();
		var query = $('#search-form').serializeJson();
		$('#dg').datagrid('load', query);
	});

	function selectGY(level) {
		if (level != -1) {
			$('#graduateYear').empty();
			$.post('${ctx}/admin/student/selectgraduateyear.json', {
				level : level
			}, function(res) {
				$.each(res,
						function(n, obj) {
							var opt = $('<option value="'+obj+'">' + obj
									+ '</option>');
							$('#graduateYear').append(opt);
						});
			});
		}
	}

	function operate(value, row, index) {
		return '<button class="btn btn-info" onclick="edit('
				+ row.id
				+ ')">修改</button>&nbsp;&nbsp;<button class="btn btn-danger" onclick="del('
				+ row.id + ')">删除</button>';
	}
	function edit(studentId) {
		window.location.href = "${ctx}/admin/student/edit/" + studentId;
	}
	function del(studentId) {
		$.messager.confirm('删除', '确定删除这个学生吗?', function(r) {
			if (r) {
				window.location.href = "${ctx}/admin/student/delete/"
						+ studentId;
			}
		});
	}
	
	function schoolLevel(value, row, index){
		return value.name;
	}

	function gender(value, row, index) {
		var str = "";
		if (row.gender == 1) {
			str = "男"
		} else {
			str = "女"
		}
		return str;
	}
</script>
</html>
