<%@ 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" %>
    <style type="text/css">.sort {
        color: #0663A2;
        cursor: pointer;
    }</style>
</head>
<body>
<%-- <%@include file="/WEB-INF/views/include/examInfoNavTabs.jsp" %> --%>
<form id="searchForm" action="${ctx}/admin/user/getSubjectCode" method="post" class="breadcrumb form-search">
    <div>
        <label>科目</label>
        <select class="input-large" name="code" id="subject-select">
            <option value="">请选择</option>
            <c:forEach items="${list}" var="subject">
                <option value="${subject.code}" data-level="${subject.level}" <c:if test="${subject.code==query.code}">selected</c:if>>${subject.code}-${subject.name}</option>
            </c:forEach>
        </select>
        &nbsp;
        <input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
         &nbsp;
        <input id="btnCheck" class="btn btn-primary" type="button" value="选中" onclick="goCheck()"/>
    </div>
</form>
<tags:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th><input type="checkbox" id="codes" checked="checked">科目名称</th>
        <th>客观总分</th>
        <th>主观总分</th>
        <th>试卷总分</th>
        <th>状态</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${list}" var="subject">
        <tr>
            <td>
            	<input type="checkbox" class="codes" name="codes" value="${subject.code}" checked="checked">
                ${subject.code}-${subject.name}&nbsp;${subject.remark}
            </td>
            <td><fmt:formatNumber pattern="###.###" value="${subject.objectiveScore}"/></td>
            <td><fmt:formatNumber pattern="###.###" value="${subject.subjectiveScore}"/></td>
            <td><fmt:formatNumber pattern="###.###" value="${subject.totalScore}"/></td>
            <td>正常
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<script type="text/javascript">
$(document).ready(function (e) {
	var subjectCodeString = window.localStorage.getItem("subjectCodeString");
	if (subjectCodeString != null && subjectCodeString != undefined) {
		$("input[name='codes']").each(function(){
    		$(this).attr("checked", false);
    	});
	    var check_list =subjectCodeString.split(",");
        check_list.forEach(code => {
        	$("input[name='codes']").each(function(){
        		if($(this).val()==code){
        			$(this).attr("checked", true);
        		}
        	})
        });
        $(".codes").change();
	}
});

$("#codes").change(function () {
    if ($("#codes").is(':checked')) {
        $(".codes").attr("checked", true);
    } else {
    	$(".codes").attr("checked", false);
    }
});

$(".codes").change(function () {
	var all = true;
	$("input[name='codes']").each(function(){
		if(!$(this).is(':checked')){
			all = false;
		}
	})
	 $("#codes").attr("checked", all);
});
function goCheck() {
	var check_list = []
	$("input[name='codes']:checked").each(function(){
		check_list.push($(this).val())
	})
    if(check_list.length==0) {
        alert('请选择');
        return false;
    }
	if (window.opener && !window.opener.closed) {
		var result = check_list.join(",");
        window.opener.document.getElementById("subjectCodeString").value = result;
        window.opener.document.getElementById("configuration").innerText = "设置成功";
        window.localStorage.setItem("subjectCodeString",result);
        window.close();
    }
    return false;
}
function goSearch() {
    $("#searchForm").submit();
    return false;
}
</script>
</body>
</html>