<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>评卷大题新增</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			window.localStorage.removeItem("pictureConfig");
			$("#number").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$(".doubleDiv").hide();
			$("#openDouble").change(function() { 
				if ($("#openDouble").is(':checked')){
					$(".doubleDiv").show();
				}else{
					$(".doubleDiv").hide();
				}
			});
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="##">新增大题</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="group" action="${ctx}/admin/exam/group/insert" method="post" class="form-horizontal">
		<tags:message content="${message}"/>
		<form:hidden path="subjectCode"/>
		<input type="hidden" id="questionDetail" name="questionDetail" />
		<div class="control-group">
            <label class="control-label">序号</label>
            <div class="controls">
                <form:input path="number" htmlEscape="false" maxlength="10" min="1" class="required digits"/>
            </div>
        </div>
        <div id="questionDiv">
        <div class="control-group">
            <label class="control-label">大题</label>
            <div class="controls">
                <input name="mainNumber" type ="number" htmlEscape="false" maxlength="10" min="1" class="required digits" placeholder="大题号"/>
                <input name="mainTitle" type="text" htmlEscape="false" maxlength="30" class="required" placeholder="名称"/>
                <input name="scoreList" type="text" htmlEscape="false" maxlength="100" class="required" placeholder="步骤分"/>
            </div>
        </div>
        </div>
        <div class="control-group">
        	<div class="controls">
        	<input type="button" value="增加大题" id="quetion-add">
        	</div>
        </div>
        <div class="control-group">
            <label class="control-label">试评数量</label>
            <div class="controls">
                <form:input path="trialCount" htmlEscape="false" min="0" class="digits" type="number" value="0"/>
                <label>0表示跳过试评</label>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">评卷模式</label>
            <div class="controls">
            <select name="markMode">
                <option value="">不限</option>
                <c:forEach items="${markModeList}" var="item">
                     <option value="${item}" >${item.name}</option>
                </c:forEach>
            </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">图片显示</label>
            <div class="controls">
                <form:input path="picList" class="required" id="picList"  type="hidden"/>
                <a href="${ctx}/admin/exam/group/getPictureConfig?subjectCode=${group.subjectCode}&number=${group.number}" target="_blank" class="required" id= "configuration">设置</a>
            </div>
        </div>
		<div class="control-group">
            <label class="control-label">双评</label>
            <div class="controls">
                <input type="checkbox" id="openDouble">开启
            </div>
        </div>
        <div class="doubleDiv">
        <div class="control-group">
            <label class="control-label">双评比例</label>
            <div class="controls">
                <form:input path="doubleRate" htmlEscape="false" maxlength="100" class="required" type="number"/>*比例范围为0-1
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">仲裁阀值</label>
            <div class="controls">
                <form:input path="arbitrateThreshold" htmlEscape="false" maxlength="100" class="required" type="number"/>*阈值为分数
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">合分策略</label>
            <div class="controls">
				<select name="scorePolicy">
	                <c:forEach items="${scorePolicyList}" var="item">
	                	 <option value="${item.value}" >${item.name}</option>
	                </c:forEach>
	            </select>
            </div>
        </div>
        </div>
		<div class="control-group">
			<label class="control-label">原卷显示</label>
			<div class="controls">
				<input name="sheetView" type="checkbox" <c:if test="${group.sheetView}">checked</c:if>/>
			</div>
		</div>
        <div class="form-actions">
            <a id="btnSubmit" href="##" class="btn btn-primary">保 存</a>&nbsp;
            <a href="${ctx}/admin/exam/group?subjectCode=${group.subjectCode}" class="btn">返回</a>
        </div>
	</form:form>
<script type="text/javascript">
$("#quetion-add").click(function() { 
	 var dom ='<div class="control-group"><label class="control-label">大题</label><div class="controls">\
<input name="mainNumber" class="mainNumber" type ="number" htmlEscape="false" maxlength="10" min="1" class="required digits" placeholder="大题号"/>\
<input name="mainTitle" class="mainTitle" type="text" htmlEscape="false" maxlength="30" class="required" placeholder="名称"/>\
<input name="scoreList" class="scoreList" type="text" htmlEscape="false" maxlength="100" class="required" placeholder="步骤分"/>\
&nbsp;<a href="#" class="question-delete" onclick="questionDelete(this)">删除</a>\
</div></div>';
	$("#questionDiv").append(dom);
});

function questionDelete(obj){
$(obj).parent().parent().remove();
}
$('#btnSubmit').click(function(){
	var questionDetail = [];
	var fill = true;
	$("#questionDiv div div").each(function(){
		var question = []
		$(this).children("input").each(function(){
			var q = $(this).val();
	        if(q==''){
	            fill = false;
	        }
			question.push(q);
		});
		var detail = {
				mainNumber:question[0],
				mainTitle:question[1],
				scoreList:question[2].split(",")
		};
	    questionDetail.push(detail);
	});
	 if(fill){
		$('#questionDetail').val(JSON.stringify(questionDetail));
	    $('#inputForm').submit();
	 }else{
		 alert('大题不能为空');
	 }
});
</script>
</body>
</html>
