<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-classes-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">班级名称：</label>
				<div class="col-sm-8">
					<input id="className" name="className" class="form-control" type="text">
				</div>
			</div>
			<input name="schoolId"  type="hidden" id="treeId"/>
			<div class="form-group">	
				<label class="col-sm-3 control-label">所属校区：</label>
				<div class="col-sm-8">
					<!--<select id="schoolId" name="schoolId" class="form-control" type="text">
						<option th:each="obj,eStat:${school}" th:value="${obj.schoolId}"
								th:text="${obj.schoolName}"></option>
					</select>-->
					<input class="form-control" type="text" name="schoolName" onclick="selectDeptTree()" readonly="true" id="treeName">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">所属专业：</label>
				<div class="col-sm-8">
					<select id="majorId" name="majorId" class="form-control" type="text">
						<option th:each="obj,eStat:${major}" th:value="${obj.majorId}"
								th:text="${obj.majorName}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">当前阶段：</label>
				<div class="col-sm-8">
					<input id="stageNew" name="stageNew" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">阶段时间：</label>
				<div class="col-sm-8">
					<input id="stageStarttime" name="stageStarttime" class="form-control" type="text">-
					<input id="stageEndtime" name="stageEndtime" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">班主任：</label>
				<div class="col-sm-8">
					<input id="headTeacher" name="headTeacher" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">教员1：</label>
				<div class="col-sm-8">
					<input id="teacherOne" name="teacherOne" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">教员2：</label>
				<div class="col-sm-8">
					<input id="teacherTwo" name="teacherTwo" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">教员3：</label>
				<div class="col-sm-8">
					<input id="teacherThree" name="teacherThree" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">教员4：</label>
				<div class="col-sm-8">
					<input id="teacherFour" name="teacherFour" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">助教：</label>
				<div class="col-sm-8">
					<input id="teachingAssistant" name="teachingAssistant" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "teach/classes"
		$("#form-classes-add").validate({
			rules:{
                schoolName:{
					required:true,
				},
			}
		});

        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择校区',
                width: "500",
                url: ctx + "system/dept/selectDeptTree/" + deptId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
        }
		
		function submitHandler() {
	        if ($.validate.form()) {
                add();
	        }
	    }

        function add() {
			var className = $("input[name='className']").val();
			var schoolId = $("input[name='schoolId']").val();
            var majorId = $("select[name='majorId']").val();
            var stageNew = $("input[name='stageNew']").val();
            var stageStarttime = $("input[name='stageStarttime']").val();
            var stageEndtime = $("input[name='stageEndtime']").val();
            var headTeacher = $("select[name='headTeacher']").val();
            var teacherOne = $("input[name='teacherOne']").val();
            var teacherTwo = $("input[name='teacherTwo']").val();
            var teacherThree = $("input[name='teacherThree']").val();
            var teacherFour = $("select[name='teacherFour']").val();
            var teachingAssistant = $("input[name='teachingAssistant']").val();
            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/add",
                data : {
                    "className": className,
                    "schoolId": schoolId,
                    "majorId": majorId,
                    "stageNew": stageNew,
                    "stageStarttime": stageStarttime,
                    "stageEndtime": stageEndtime,
                    "headTeacher": headTeacher,
                    "teacherOne": teacherOne,
                    "teacherTwo": teacherTwo,
                    "teacherThree": teacherThree,
                    "teacherFour": teacherFour,
                    "teachingAssistant": teachingAssistant
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.successCallback(data);
                }
            });
		}

	</script>
</body>
</html>
