<%@ 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>
<ul class="nav nav-tabs">
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-mark')}">
        <li><a href="${ctx}/admin/exam/mark?subjectCode=${subject.code}">评卷进度</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-group')}">
        <li><a href="${ctx}/admin/exam/group?subjectCode=${query.subjectCode}">分组管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-marker')}">
        <li><a href="${ctx}/admin/exam/marker?subjectCode=${query.subjectCode}">评卷员管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-trial')}">
        <li><a href="${ctx}/admin/exam/trial?subjectCode=${query.subjectCode}">试评管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-library')}">
        <li><a href="${ctx}/admin/exam/library?subjectCode=${query.subjectCode}">任务管理</a></li>
    </c:if>
    <li class="active"><a href="##">仲裁管理</a></li>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-quality')}">
        <li><a href="${ctx}/admin/exam/quality?subjectCode=${query.subjectCode}">质量监控</a></li>
    </c:if>
</ul>
<form id="searchForm" action="${ctx}/admin/exam/arbitrate" 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" id="subject-select" name="subjectCode">
            <c:forEach items="${subjectList}" var="item">
                <option value="${item.code}"
                        <c:if test="${item.code==query.subjectCode}">selected</c:if>>${item.code}-${item.name}</option>
            </c:forEach>
        </select>
        <label>分组</label>
        <select class="input-medium" id="group-select" name="groupNumber">
            <option value="" <c:if test="${query.groupNumber==null}">selected</c:if>>不限</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-small" id="status-select" name="status">
            <option value="">不限</option>
            <c:forEach items="${statusList}" var="item">
                <option value="${item.value}"
                        <c:if test="${query.status!=null && item.value==query.status.value}">selected</c:if>>${item.name}</option>
            </c:forEach>
        </select>
        <label>选做题</label>
        <select class="input-small" name="unselective">
            <option value="false" <c:if test="${!query.unselective}">selected</c:if>>不限</option>
            <option value="true" <c:if test="${query.unselective}">selected</c:if>>未选做</option>
        </select>
        <c:if test="${web_user.schoolAdmin==true || forbiddenScore==false}">
            <label>准考证号</label>
            <input type="text" name="examNumber" value="${query.examNumber}" maxlength="20" class="input-medium"
                    <c:if test="${(web_user.subjectHeader==true||web_user.schoolViewer==true) && forbiddenInfo==true}"> disabled="disabled"</c:if>/>
            &nbsp;
        </c:if>
        <input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>

        <c:if test="${query.totalCount>0}">
            &nbsp;
            <a href="##" class="btn" id="batch-process-link" target="_blank">批量处理</a>
        </c:if>
    </div>
</form>
<tags:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th>科目代码</th>
        <th>分组序号</th>
        <th>准考证号</th>
        <th>状态</th>
        <th>创建时间</th>
        <th>处理时间</th>
        <th>处理人</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${query.result}" var="result">
        <tr>
            <td>${result.subjectCode}</td>
            <td>${result.groupNumber}</td>
            <td>
                <c:if test="${(web_user.subjectHeader==true||web_user.schoolViewer==true) && forbiddenInfo==true}">
                    ***
                </c:if>
                <c:if test="${web_user.schoolAdmin==true || forbiddenInfo==false}">
                    ${result.examNumber}
                </c:if>
            </td>
            <td>${result.status.name}</td>
            <td>
                <fmt:formatDate value="${result.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
            </td>
            <td>
                <c:if test="${result.updateTime!=null}">
                    <fmt:formatDate value="${result.updateTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </c:if>
                <c:if test="${result.updateTime==null}">
                    &nbsp;
                </c:if>
            </td>
            <td>
                <c:if test="${result.user!=null}">
                    <a href="##" data-toggle="tooltip" title="${result.user.name}">${result.user.loginName}</a>
                </c:if>
                <c:if test="${result.user==null}">
                    &nbsp;
                </c:if>
            </td>
            <td>
                <c:if test="${(result.status.value==0 || result.status.value==1) && (result.totalScore!= -1)}">
                    <a href="${ctx}/web/admin/exam/arbitrate/start?historyId=${result.id}" target="_blank"
                       class="process-link">处理</a>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="pagination">${query}</div>
<script type="text/javascript">
    $('.back-link').click(function () {
        if (!confirm('确定要打回该仲裁记录的所有评卷任务吗?')) {
            return;
        }
        $.post('${ctx}/admin/exam/arbitrate/back', {id: $(this).attr('data-id')}, function (result) {
            if (result.success == true) {
                alert('打回成功');
                $("#searchForm").submit();
            } else {
                alert(result.message);
            }
        });
    });
    $('#batch-process-link').click(function () {
        var subjectCode = $('#subject-select').val();
        var groupNumber = $('#group-select').val();
        if (subjectCode == undefined || subjectCode == '') {
            alert('请选择科目')
            return false;
        }
        if (groupNumber == undefined || groupNumber == '') {
            alert('请选择分组')
            return false;
        }
        $('#batch-process-link').attr('href', '${ctx}/web/admin/exam/arbitrate/start?subjectCode=' + subjectCode + '&groupNumber=' + groupNumber);
        return true;
    });
    $('#subject-select').change(function () {
        var code = $(this).val();
        $('#group-select').empty();
        if (code == '') {
            $('#group-select').val('').trigger('change');
            return;
        }
        $.post('${ctx}/admin/exam/group/query', {subjectCode: code, withDouble: true}, function (result) {
            var parent = $('#group-select');
            var first = '';
            $('<option value="">不限</option>').appendTo(parent);
            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").submit();
        return false;
    }

    function goSearch() {
        $("#pageNumber").val(1);
        $("#searchForm").submit();
        return false;
    }
</script>
</body>
</html>