<%@ 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 {
                    $("#doubleRate").attr("value", "");
                    $("#thirdPolicy").attr("value", "");
                    $("#arbitrateThreshold").attr("value", "");
                    $(".doubleDiv").hide();
                }
            });
            $("#btnNext").click(function () {
            	var check_list = []
            	$("input[name='questionIds']:checked").each(function(){
	            	if($(this).val()!=""){
	            		check_list.push($(this).val())
            		}
            	})
                if(check_list.length==0) {
                    alert('请选择题目');
                    return false;
                }
            	$("#nextDiv").show();
            	$("#nextLi").attr("class","active");
            	$("#preDiv").hide();
            	$("#preLi").attr("class","");
            	
            });
			$("#btnPre").click(function () {
            	$("#nextDiv").hide();
				$("#preDiv").show();
            	$("#nextLi").attr("class","");
				$("#preLi").attr("class","active");
            });
        });
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li class="active" id="preLi"><a>勾选试题分组</a></li>
    <li id="nextLi"><a>分组参数设置</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 id="preDiv">
	<div>
        <table id="contentTable" class="table table-striped table-bordered table-condensed">
        <caption><h4>${subject.code }-${subject.name } 主观题<fmt:formatNumber pattern="###.###" value="${subject.subjectiveScore }"/>分</h4></caption>
        	<thead>
        	<tr>
       			 <th>大题号</th>
        		 <th>小题号</th>
        		 <th>名称</th>
        		 <th>分数</th>
        		 <th>是否选做题</th>
        		 <th>选做题分组</th>
				 <th>选做题区</th>
        		 <th></th>
			</tr>
        	</thead>
			<c:forEach items="${questionList}" var="item">
		    <tr>
		    <td>${item.mainNumber }</td>
		    <td>${item.subNumber }</td>
			<td>${item.mainTitle }</td>
			<td><fmt:formatNumber pattern="###.###" value="${item.totalScore}"/></td>
			<td><c:if test="${item.selective }">选做题</c:if></td>
			<td>${item.selectiveIndex}</td>
			<td>${item.selectiveIndex}-${item.selectivePart}</td>
			<td><input type="checkbox" name="questionIds" value="${item.id }" <c:if test="${item.groupNumber!=null}"> disabled="disabled"</c:if>></td>
			</tr>
			</c:forEach>
		</table>
	</div>
    <div class="pull-right">
        <a href="${ctx}/admin/exam/group?subjectCode=${group.subjectCode}" class="btn">取&nbsp;消</a>&nbsp;&nbsp;
        <a id="btnNext" href="##" class="btn btn-primary">下一步 </a>
    </div>
</div>
<div id="nextDiv" class ="hide">
    <div class="control-group">
        <label class="control-label">分组号</label>
        <div class="controls">
            <form:input path="number" type="number" htmlEscape="false" max="100" min="1" class="required digits" value="${group.number }"/>
        </div>
    </div>
    <c:if test="${groupCount==0 }">
    <div class="control-group">
        <label class="control-label">试评数量</label>
        <div class="controls">
            <input name="trialCount" htmlEscape="false" min="0" class="digits" type="number" value="0"/>
            <label>0表示跳过试评</label>
        </div>
    </div>
    </c:if>
    <c:if test="${exam.type!='MULTI_MEDIA' && exam.markMode!='TRACK'}">
	    <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>
    </c:if>
     <c:if test="${exam.type!='MULTI_MEDIA'}">
        <div class="control-group">
            <label class="control-label">图片显示</label>
            <div class="controls">
                <a href="${ctx}/admin/exam/group/getPictureConfig?subjectCode=${group.subjectCode}&number=${group.number}"
                   target="_blank" id="configuration" rel="opener">设置</a>
            </div>
        </div>
	</c:if>
    <form:input path="picList" class="required" id="picList" type="hidden"/>
    <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" id="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" id="arbitrateThreshold" htmlEscape="false" maxlength="100"
                            class="required" type="number"/>*阈值为分数且大于等于0
            </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 class="control-group">
            <label class="control-label">三评规则</label>
            <div class="controls">
                <select name="thirdPolicy">
                    <c:forEach items="${thirdPolicyList}" var="item">
                        <option value="${item.value}">${item.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>
    <c:if test="${exam.type!='MULTI_MEDIA'}">
    	<c:if test="${exam.sheetView}">
        <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>
        </c:if>
        <div class="control-group">
            <label class="control-label">启用全零分</label>
            <div class="controls">
                <input name="enableAllZero" type="checkbox" value="1" <c:if test="${group.enableAllZero}">checked</c:if>/>
            </div>
        </div>
    </c:if>    
    <div class="form-actions">
        <a id="btnPre" class="btn">上一步</a>&nbsp;
        <a id="btnSubmit" href="##" class="btn btn-primary">保 存</a>
    </div>
</div>
</form:form>
<script type="text/javascript">

    $('#btnSubmit').click(function () {
    	if($("#arbitrateThreshold").val()<0){
    		alert("仲裁阈值不能小于0");
    		return;
    	}
    	var check_list = []
    	$("input[name='questionIds']:checked").each(function(){
        	if($(this).val()!=""){
        		check_list.push($(this).val())
    		}
    	})
        if(check_list.length==0) {
            alert('请选择题目');
            return false;
        }
       $('#inputForm').submit();
    });
</script>
</body>
</html>
