<%@ 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"%>
<script type="text/javascript" src="${ctx}/static/admin/js/jquery.edatagrid.js"></script>
<script type="text/javascript" src="${ctx}/static/admin/js/easyui-lang-zh_CN.js"></script>
</head>
<body class="easyui-layout">
	<%@ include file="../common/header.jsp"%>
	<%@ include file="../leftMenu/exam-admin.jsp"%>
	<div data-options="region:'center',title:'首页 -【考试管理】- 新建考试'">
		<div class="easyui-layout" data-options="fit:true,border:false">
			<div class="border" data-options="region:'center'">
				<form id="examFrm" class="mr-t form-horizontal" action="${ctx}/admin/exam/save" method="post">
					<input type="hidden" id="sourceExamId" name="sourceExamId" value="" /> 
					<input type="hidden" id="scope" name="scope" value="1" />
					<input type="hidden" id="copyHistory" name="copyHistory" value="false"/>
					<div class="control-group">
						<label class="control-label" for="">考试名称</label>
						<div class="controls">
							<input type="text" id="name" name="name" required="true" />
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="">考试时间</label>
						<div class="controls">
							<input type="text" style="height: 30px" id="examTime" name="examTime" class="easyui-datebox"
								required="true" />
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="">图片服务地址</label>
						<div class="controls">
							<input type="text" id="imageServer" name="imageServer" />
						</div>
					</div>
					<div class="control-group">
			            <div class="controls">
							<label class="checkbox pa">
								<input id="selectExam" type="checkbox">
								<a id="examhistory" href="#myModal" data-toggle="modal">使用历史考试</a>
							</label>
						</div>
			        </div>
					<div class="control-group">
						<label class="control-label" for="">描述</label>
						<div class="controls">
							<textarea rows="4" id="description" name="description" class="input-xxlarge"></textarea>
						</div>
					</div>
					<div class="control-group">
						<div class="controls">
							<input class="btn btn-primary" type="button" onclick="save()" value="保存" /> 
							<a href="${ctx}/admin/exam/list" class="btn">返回</a>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<%@ include file="history.jsp"%>
</body>
<script type="text/javascript">
	$(document).ready(function(e) {
		if(e.preventDefault) {  
	        e.preventDefault();  
	    } else {  
	        e.returnValue = false; // IE8
	    } 
		$('#examTime').datebox({
			"required" : true,
			onSelect: function(date){
				$("#examTime").val(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+ " 00:00:00");
			}

		});
		$("#examhistory").click(function(){
			$("#selectExam").attr("checked","true");
			$.post('${ctx}/admin/exam/page-list.json', {statusValue:2}, function(result){
				$('#exam-history-table tbody').empty();
				$.each(result.examList, function(index, exam){
					$('#exam-history-table tbody').append($.nano($('#exam-tr-template').html(),exam));
				});
				buildPaginator(result);
			});
		});
		$("#selectExam").change(function() {
            if (!$("#selectExam").attr("checked")) {
            }else if($("#selectExam").attr("checked")){
            	$("#examhistory").trigger("click");
            }
        });
	});

	function submit() {
		var examTime = $("input[name='examTime']").val();
		examTime += " 00:00:00";
		$("input[name='examTime']").val(examTime);
		$('#examFrm').submit();
	}

	function save() {
		if ($('#examFrm').form('validate')) {
			submit();
		}
	}

	function copyHistoryExam() {
		if ($('#examFrm').form('validate')) {
			initExamHistory();
		}
	}
</script>
</html>
