<%@ 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>
    <li class="active"><a href="##">分组管理</a></li>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-marker')}">
    <li><a href="${ctx}/admin/exam/marker?subjectCode=${subject.code}">评卷员管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-trial')}">
    <li><a href="${ctx}/admin/exam/trial?subjectCode=${subject.code}">试评管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-library')}">
    <li><a href="${ctx}/admin/exam/library?subjectCode=${subject.code}">任务管理</a></li>
    </c:if>
        <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-arbitrate')}">
    <li><a href="${ctx}/admin/exam/arbitrate?subjectCode=${subject.code}">仲裁管理</a></li>
    </c:if>
        <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-quality')}">
    <li><a href="${ctx}/admin/exam/quality?subjectCode=${subject.code}">质量监控</a></li>
    </c:if>
</ul>
<form id="searchForm" action="${ctx}/admin/exam/group" method="post" class="breadcrumb form-search">
    <div>
        <label>科目</label>
        <select class="input-large subjectCode" name="subjectCode" id="subjectCode">
            <c:forEach items="${subjectList}" var="item">
                <option value="${item.code}" <c:if test="${item.code==subject.code}">selected</c:if>>${item.code}-${item.name}</option>
            </c:forEach>
        </select>
        &nbsp;
        <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>

        <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-group-add')}">
	            &nbsp;
	 			<a href="${ctx}/admin/exam/group/add?subjectCode=${subject.code}" class="btn">新增</a>
        </c:if>
	            &nbsp;
	            <a href="${ctx}/admin/exam/group/check-count?subjectCode=${subject.code}" class="btn">数量校对</a>
            &nbsp;
            <input id="btnFinish" class="btn" type="button" value="关闭" onclick="goFinish()"/>
            <a href="javascript:void(0)" class="trial-button"
                       onclick="updateTrialCount();">设置试评数量</a>
    </div>
</form>
<tags:message content="${message}"/>
<form id="groupForm" action="${ctx}/admin/exam/group/finish" method="post" class="breadcrumb form-search">
	<input type="hidden" name="subjectCode" value="${subject.code }"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th><input type="checkbox" id="groupNumbers">分组序号</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>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${resultList}" var="result">
        <tr>
            <td><input type="checkbox" class="groupNumbers" name="groupNumbers" value="${result.number}">${result.number}</td>
            <td>${result.mainNumber}</td>
            <td>${result.title}</td>
            <td>${result.scoreList}</td>
            <td>${result.selectiveIndex}</td>
            <td>
            <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-marker')}">
                <a href="${ctx}/admin/exam/marker?subjectCode=${result.subjectCode}&groupNumber=${result.number}">${result.markerCount}</a>
            </c:if>
            <c:if test="${!fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-marker')}">
            ${result.markerCount}
            </c:if>
            </td>
            <td>${result.libraryCount}</td>
            <td>${result.markedCount}</td>
            <td>${result.leftCount}</td>
            <td>${result.currentCount}</td>
            <td>${result.percent}%</td>
            <td>
            	<c:if test="${result.picList!=null && result.picList!=''}">是</c:if>
            	<c:if test="${result.picList==null || result.picList==''}">否</c:if>
            </td>
            <td>${result.status.name}</td>
            <td>
                <c:if test="${result.deleting==true}">
                    正在删除
                </c:if>
                <c:if test="${result.deleting==false}">
                    <c:if test="${result.status.value!=3}">
                        <c:if test="${result.status.value==1}">
                            <a href="${ctx}/admin/exam/group/changeStatus?subjectCode=${result.subjectCode}&number=${result.number}&status=FORMAL" data-number="${result.number}" class="edit-button"
                               id="statusButton">开始正评</a>
                        </c:if>
                        <c:if test="${result.status.value==2 && result.leftCount==0}">
                            <a href="${ctx}/admin/exam/group/changeStatus?subjectCode=${result.subjectCode}&number=${result.number}&status=FINISH" data-number="${result.number}"
                               class="edit-button">结束</a>
                        </c:if>
                        <c:if test="${result.currentCount>0}">
                            &nbsp;
                            <a href="${ctx}/admin/exam/group/release?subjectCode=${result.subjectCode}&number=${result.number}">回收</a>
                        </c:if>
                       <%--  <c:if test="${result.libraryCount>0}">
                            &nbsp;
                            <a href="${ctx}/admin/exam/group/reset?subjectCode=${result.subjectCode}&number=${result.number}" data-number="${result.number}" class="reset-button">重置</a>
                        </c:if> --%>
                        &nbsp;
                        <c:if test="${examType!='MULTI_MEDIA' && fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-group-edit')}">
                            <a href="${ctx}/admin/exam/group/edit-simple?subjectCode=${result.subjectCode}&number=${result.number}" data-number="${result.number}" class="edit-button">修改</a>
                            &nbsp;
                        </c:if>
                        <c:if test="${examType=='MULTI_MEDIA' && fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-group-delete')}">
                            <a href="${ctx}/admin/exam/group/delete?subjectCode=${result.subjectCode}&number=${result.number}" data-number="${result.number}" class="delete-button">删除</a>
                            &nbsp;
                        </c:if>
                    </c:if>
                    
                    <c:if test="${(web_user.schoolAdmin==true ||web_user.subjectHeader==true)&& result.status.value==3}">
                        &nbsp;
                        <a href="${ctx}/admin/exam/group/changeStatus?subjectCode=${result.subjectCode}&number=${result.number}&status=FORMAL" data-number="${result.number}"
                           class="edit-button">开始正评</a>
                    </c:if>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="trialCountWin" style="display:none">
    <div class="task-header">
        <p class="title">设置试评数</p>
        <p class="image-close"><img src="${ctxStatic}/mark-new/images/images-close.png"/></p></div>
    <div class="task-content"><input type="text" class="trial-count" placeholder="请输入试评数" value="${subject.trialCount }"/><i class="wrong"></i></div>
    <a href="#" class="btn btn-small btn-info save-btn">确定</a>
</div>
</form>
<script type="text/javascript">
    function page(n, s) {
        $("#pageNumber").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }

    function goSearch() {
        $("#pageNumber").val(1);
        $("#searchForm").submit();
        return false;
    }

    $('.reset-button').click(function () {
        var number = $(this).attr('data-number');
        return confirm('确定要重置第' + number + '分组的评卷任务吗?');
    });
    $('#statusButton').click(function () {
        return confirm('确定开始正评吗？');
    });
    $("#groupNumbers").change(function () {
        if ($("#groupNumbers").is(':checked')) {
            $(".groupNumbers").attr("checked", true);
        } else {
        	$(".groupNumbers").attr("checked", false);
        }
    });
    
    $(".groupNumbers").change(function () {
    	var all = true;
    	$("input[name='groupNumbers']").each(function(){
    		if(!$(this).is(':checked')){
    			all = false;
    		}
    	})
		 $("#groupNumbers").attr("checked", all);
    });
    
    function goFinish() {
    	var check_list = []
    	$("input[name='groupNumbers']:checked").each(function(){
    		check_list.push($(this).val())
    	})
        if(check_list.length==0) {
            alert('请选择分组');
            return false;
        }
        $("#groupForm").submit();
        return false;
    }
    
    function updateTrialCount() {
        $('.trialCount-value').val('');
        $('.trialCountWin').show();
        $('#cover').show();
    }
    $('.image-close').click(function () {
        $('.trialCountWin').hide();
        $('#cover').hide();
    });
    $('.save-btn').click(function () {
    	var trialCount = $('.trial-count').val();
        var wrongMessage = $('.wrong');
        trialCount = trialCount.replace(/(^\s*)|(\s*$)/g, "");
        if (trialCount.length == 0) {
            wrongMessage.html('数量不能为空！');
            return false;
        } else {
            if (!/^\+?[1-9][0-9]*$/.test(trialCount)) {
                wrongMessage.html('请输入正整数!');
                return false;
            }
            if (trialCount > 2147483647) {
                wrongMessage.html('数量不合法!');
                return false;
            }
        }
        var subjectCode = $('#subjectCode').val();
        $.post('${ctx}/admin/exam/group/updateTrialCount', {subjectCode: subjectCode, trialCount: trialCount}, function (result) {
            if (result.success == true) {
                alert('修改成功');
                $("#searchForm").submit();
            } else {
                alert(result.message);
            }
            $('.trialCountWin').hide();
        });
    });
</script>

<style type="text/css">
	.sort {
        color: #0663A2;
        cursor: pointer;
    }
</style>
    <style type="text/css">
        .sort {
            color: #0663A2;
            cursor: pointer;
        }
        
        .trialCountWin {
            width: 400px;
            min-height: 150px;
            background: #fff;
            font-family: "微软雅黑", Fixedsys;
            border: #5d6d7d solid 1px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin: -150px 0 0 -200px;
            text-align: center;
            z-index: 99999;
        }
        
        .task-header{
            width: 100%;
            height: 46px;
            background: #5d6d7d;
            color: #fff;
        }
        
        .task-content{
            font-size: 18px;
            color: #005277;
            text-align: left;
            padding: 15px;
            line-height: 30px;
            word-wrap: break-word;
        }
        
        .image-close {
            margin-top: 15px;
            margin-right: 15px;
            cursor: pointer;
            float: right;
        }
        
        .title {
            font-size: 22px;
            font-weight: bold;
            color: #fff;
            margin: 0px;
            padding: 13px 0 0 13px;
            float: left;
        }

        .task-count{
            width: 150px;
        }

        .btn-info {
            height: 25px;
            margin-left: 320px;
            margin-bottom: 20px;
        }
        
        .wrong {
            font-size: 12px;
            color: #f00;
            line-height: 30px;
            padding-left: 20px;
        }
        
        #cover {
            position: fixed;
            z-index: 9999;
            top: 0px;
            left: 0px;
            display: none;
            width: 100%;
            height: 100%;
            opacity: 0.5;
            background: #000 none repeat scroll 0% 0%;
        }
    </style>
</body>
</html>