<%@ 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>
<form id="searchForm" action="${ctx}/admin/exam/problem/history" method="post" class="breadcrumb form-search">
    <input type="hidden" id="pageNumber" name="pageNumber" value="${query.pageNumber }"/>
    <input type="hidden" id="pageSize" name="pageSize" value="${query.pageSize }"/>
    <div>
        <label>科目</label>
        <select class="input-large" name="subjectCode" id="subject-select">
            <option value="">请选择</option>
            <c:forEach items="${subjectList}" var="subject">
                <option value="${subject.code}" <c:if test="${subject.code==query.subjectCode}">selected</c:if>>${subject.code}-${subject.name}</option>
            </c:forEach>
        </select>
        <label>分组</label>
        <select class="input-medium" id="group-select" name="groupNumber">
            <option value="0">请选择</option>
            <c:forEach items="${groupList}" var="item">
                <option value="${item.number}" <c:if test="${item.number==query.groupNumber}">selected</c:if>>${item.number}-${item.title}</option>
            </c:forEach>
        </select>
        <label>类型</label>
        <select class="input-medium" name="problemId">
            <option value="">请选择</option>
            <c:forEach items="${problemList}" var="problem">
                <option value="${problem.id}" <c:if test="${problem.id==query.problemId}">selected</c:if>>${problem.name}</option>
            </c:forEach>
        </select>
        &nbsp;
        <label>状态</label>
        <select class="input-medium" name="status">
            <c:forEach items="${statusList}" var="status">
                <option value="${status.value}" <c:if test="${status.value==query.status.value}">selected</c:if>>
                	<c:if test="${status=='BACK'}">已处理</c:if>
                	<c:if test="${status!='BACK'}">${status.name}</c:if>
                </option>
            </c:forEach>
        </select>
        &nbsp;<br/><br/>
        <label>密号</label>
        <input type="text" name="secretNumber" id="secretNumber" value="${query.secretNumber}" class="input-medium"/>
        &nbsp;
        <input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
        
        <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_problem_history-batch_reset') && query.status=='WAITING'}">
        <input id="btnRest" class="btn" type="button" value="批量重置" onclick="goRest()"/>
        </c:if>
    </div>
</form>
<tags:message content="${message}"/>
<form id="restForm" action="${ctx}/admin/exam/problem/history/restBatch" method="post" class="breadcrumb form-search">
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
    	<th><input type="checkbox" id="checkAll"></th>
        <th>科目</th>
        <th>分组序号</th>
        <th>状态</th>
        <th>准考证号</th>
        <th>密号</th>
        <th>姓名</th>
        <th>评卷员</th>
        <th>提交时间</th>
        <th>问题类型</th>
        <th>处理人</th>
        <th>处理时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${resultList}" var="result">
        <tr>
        	<td><input type="checkbox" class="libraryIds" name="libraryIds" value="${result.libraryId}"></td>
            <td>${result.subjectCode}-${result.subjectName}</td>
            <td>${result.number}</td>
            <td>
            		<c:if test="${query.status=='WAITING'}">
                        待处理
                    </c:if>
                    <c:if test="${query.status=='BACK'}">
                        已处理
                    </c:if>
            </td>
            <td>
            	<c:if test="${web_user.subjectHeader==true && forbiddenInfo==true}">
	            ***
	            </c:if>
	            <c:if test="${web_user.schoolAdmin==true || forbiddenInfo==false}">
	            ${result.examNumber}
	            </c:if>
            </td>
            <td>${result.secretNumber}</td>
            <td>
            	<c:if test="${web_user.subjectHeader==true && forbiddenInfo==true}">
	            ***
	            </c:if>
	            <c:if test="${web_user.schoolAdmin==true || forbiddenInfo==false}">
	            ${result.name}
	            </c:if>
            </td>
            <td>${result.markLogin}</td>
            <td>${result.markTime}</td>
            <td>${result.problemType.name}</td>
            <td>${result.problemUserName}</td>
            <td>${result.problemRestTime}</td>
            <td>
                <%--  <a class="json-link" href="${ctx}/admin/exam/library/getJson?studentId=${result.id}&groupNumber=${result.number}" target="_blank">原图</a>--%>
               	<a href="${ctx}/web/admin/exam/track/library?libraryId=${result.libraryId}&subjectCode=${result.subjectCode}" target="_blank">试卷详情</a>
                &nbsp;
                <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_problem_history-reset') && result.problemUserName==null}">
	                <a href="##" data-id="${result.libraryId}" class="back-link">重置</a>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
</form>
<div class="pagination">${query}</div>
<%@include file="/WEB-INF/views/include/trackView.jsp" %>
<script type="text/javascript">
    $(document).ready(function () {
        /* new jBox('Image', {
            imageFade: 0,
            delayOpen: 0,
            delayClose: 0,
            maxHeight: $(window).height()*0.88
        }); */
        $('.back-link').click(function () {
            if (!confirm('确定要重置该评卷任务吗?')) {
                return;
            }
            $.post('${ctx}/admin/exam/library/reject', {id: $(this).attr('data-id'),isRest:true}, function (result) {
                if (result.success == true) {
                    alert('重置成功');
                    $("#searchForm").submit();
                } else {
                    alert(result.message);
                }
            });
        });
        $('.track-link').click(function () {
            initTrackPopover($(this).attr('data-title'), $(this).attr('data-image-url'));
            return false;
        });
        $('#subject-select').change(function () {
            var code = $(this).val();
            $('#group-select').empty();
            $("<option value='0'>请选择</option>").appendTo('#group-select');
            if (code == '') {
                $('#group-select').val('').trigger('change');
                return;
            }

            $.post('${ctx}/admin/exam/group/query', {subjectCode: code, status: 'FORMAL'}, function (result) {
                var parent = $('#group-select');
                var first = '';
                for (var i = 0; i < result.length; i++) {
                    var group = result[i];
                    $('<option value="' + group.number + '">' + group.number + '-' + group.title + '</option>').appendTo(parent);
                    if (i == 0) {
                        first = group.number;
                    }
                }
                parent.val(first).trigger('change');
            });
        });
    });

    function page(n, s) {
        $("#pageNumber").val(n);
        $("#pageSize").val(s);
        $("#searchForm").attr('action', '${ctx}/admin/exam/problem/history');
        $("#searchForm").submit();
        return false;
    }

    function goSearch() {
        $("#pageNumber").val(1);
        $("#pageSize").val('${query.pageSize}');
        $("#searchForm").attr('action', '${ctx}/admin/exam/problem/history');
        $("#searchForm").submit();
        return false;
    }
    $("#checkAll").change(function () {
        if ($("#checkAll").is(':checked')) {
            $(".libraryIds").attr("checked", true);
        } else {
        	$(".libraryIds").attr("checked", false);
        }
    });
    
    $(".libraryIds").change(function () {
    	var all = true;
    	$("input[name='libraryIds']").each(function(){
    		if(!$(this).is(':checked')){
    			all = false;
    		}
    	})
		 $("#checkAll").attr("checked", all);
    });
    
    function goRest() {
    	var check_list = []
    	$("input[name='libraryIds']:checked").each(function(){
    		check_list.push($(this).val())
    	})
        if(check_list.length==0) {
            alert('请选择问题卷');
            return false;
        }
        $("#restForm").submit();
        return false;
    }
</script>
</body>
</html>