<%@ 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;}
        .taskWindow,.reSetPasswordWin{
            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,.password-header{
            width: 100%;
            height: 46px;
            background: #5d6d7d;
            color: #fff;
        }
        .task-content,.password-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,.password-value{
            width: 150px;
        }
        .btn-info{
            height: 25px;
            margin-left: 320px;
            margin-bottom: 20px;
        }
        .wrong,.passwordWrong{
            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>
</head>
<body>
<div style="display: block;" id="cover"></div>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/admin/exam-param/marker">评卷员列表</a></li>
		<li><a href="${ctx}/admin/exam-param/marker/batch-create">批量创建</a></li>
		<li><a href="${ctx}/admin/exam-param/marker/subjectViewer">科组长列表</a></li>
	</ul>
    <div id="importBox" class="hide">
        <form id="importForm" action="${ctx}/admin/exam-param/marker/import" method="post" enctype="multipart/form-data"
              style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
            <input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
            <input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
            <a href="${ctx}/admin/exam-param/marker/template">下载模板</a>
        </form>
    </div>

    <div id="importUpdateBox" class="hide">
        <form id="importUpdateForm" action="${ctx}/admin/exam-param/marker/importUpdate" method="post" enctype="multipart/form-data"
              style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
            <input id="uploadUpdateFile" name="file" type="file" style="width:330px"/><br/><br/>　　
            <input id="btnUpdateImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
            <a href="${ctx}/admin/exam-param/marker/updateLoginNameTemplate">下载模板</a>
        </form>
    </div>

	<form id="searchForm"  action="${ctx}/admin/exam-param/marker" 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 id="subject-select" name="subjectCode">
				<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>
			<input type="text" name="loginName" value="${query.loginName }"  maxlength="20" class="input-small"/>
			
			&nbsp;
			<input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
			<c:if test="${showBtnImport}">
				&nbsp;<input id="btnImport" class="btn" type="button" value="导入"/>
				&nbsp;<input id="btnUpdateImport" class="btn" type="button" value="批量修改评卷员账号"/>
			</c:if>
			&nbsp;
			<input id="btnExport" class="btn" type="button" value="导出"/>
			&nbsp;
			<a href="${ctx}/admin/exam-param/marker/progress" class="btn">评卷进度</a>
		</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>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${query.result}" var="marker">
			<tr>
				<td>
				<c:if test="${marker.subject!=null}">
				${marker.subject.code}-${marker.subject.name}
				</c:if>
				<c:if test="${marker.subject==null}">
				不限
				</c:if>
				</td>
				<td>${marker.loginName}</td>
				<td>${marker.name}</td>
				<td>
				<c:if test="${marker.topCount!=null}">
				${marker.topCount}
				</c:if>
				</td>
				<td>${marker.password}</td>
				<td>${marker.enable eq true ? "启用" : "禁用"}</td>
				<td>
					<a href="javascript:void(0)" class="delete-button" data-id="${marker.id}">删除</a>
					<c:if test="${marker.enable==true}">
					<a href="javascript:void(0)" class="toggle-button" data-id="${marker.id}" data-value="false">禁用</a>
					</c:if>
					<c:if test="${marker.enable==false}">
					<a href="javascript:void(0)" class="toggle-button" data-id="${marker.id}" data-value="true">启用</a>
					</c:if>
                    <a href="javascript:void(0)" class="task-button" data-id="${marker.id}" onclick="showTaskWin('${marker.id}');">设置评卷数</a>
                    <a href="javascript:void(0)" class="reSetPassword-button" data-id="${marker.id}" onclick="reSetPassword('${marker.id}');">重置密码</a>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
    <div class="taskWindow" 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="task-count" placeholder="请输入任务数"/><i class="wrong"></i></div>
        <a href="#" class="btn btn-small btn-info task-btn">确定</a>
    </div>

    <div class="reSetPasswordWin" style="display:none"><div class="password-header">
        <p class="title">重置密码</p><p class="image-close password-close"><img src="${ctxStatic}/mark-new/images/images-close.png" /></p></div>
        <div class="password-content"><input type="text" class="password-value" placeholder="请输入新的密码"/><i class="passwordWrong"></i></div>
        <a href="#" class="btn btn-small btn-info password-btn">确定</a>
    </div>
	<div class="pagination">${query}</div>
<script type="text/javascript">
    var markerId ;
    $(document).ready(function () {
      $('#cover').hide();
    });
$("#btnImport").click(function(){
  $.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true},
    bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
});
$("#btnUpdateImport").click(function(){
  $.jBox($("#importUpdateBox").html(), {title:"导入数据", buttons:{"关闭":true},
    bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
});
$("#btnExport").click(function(){
	top.$.jBox.confirm("确认要导出评卷员数据吗？","系统提示",function(v,h,f){
		if(v=="ok"){
			$("#searchForm").attr("action","/admin/exam-param/marker/export");
			$("#searchForm").submit();
		}
	},{buttonsFocus:1});
	top.$('.jbox-body .jbox-icon').css('top','55px');
});
$("#clear-button").click(function(){
	if(confirm('确定要删除当前的所有评卷员?')){
		$("#searchForm").attr("action","${ctx}/admin/exam-param/marker/clear");
		$("#searchForm").submit();
	}
});
$('.delete-button').click(function(){
	var id = $(this).attr('data-id');
	$.post('${ctx}/admin/exam-param/marker/delete', {id: id}, function(result){
		if(result.success==true){
			alert('删除成功');
			$("#searchForm").submit();
		}else{
			alert(result.message);
		}
	});
});
$('.toggle-button').click(function(){
	var id = $(this).attr('data-id');
	var enable = $(this).attr('data-value');
	$.post('${ctx}/admin/exam-param/marker/toggle', {id: id, enable: enable}, function(result){
		if(result.success==true){
			alert('修改成功');
			$("#searchForm").submit();
		}else{
			alert(result.message);
		}
	});
});
function showTaskWin(obj){
  $('.wrong').html('');
  $('.task-count').val('');
  $('.taskWindow').show();
  $('#cover').show();
  markerId = obj;
}
function reSetPassword(obj){
  $('.passwordWrong').html('');
  $('.password-value').val('');
  $('.reSetPasswordWin').show();
  $('#cover').show();
  markerId = obj;
}
$('.image-close').click(function () {
  $('.taskWindow').hide();
  $('#cover').hide();
});
$('.password-close').click(function () {
  $('.reSetPasswordWin').hide();
  $('#cover').hide();
});

$('.task-btn').click(function () {
  var taskCount = $('.task-count').val();
  var wrongMessage = $('.wrong');
       taskCount = taskCount.replace(/(^\s*)|(\s*$)/g, "");
       if(taskCount.length == 0){
         wrongMessage.html('任务数不能为空！');
         return false;
       }else {
         if(!/^\+?[1-9][0-9]*$/.test(taskCount)){
           wrongMessage.html('请输入正整数!');
           return false;
         }
       }
  $.post('${ctx}/admin/exam-param/marker/setTaskCount', {id: markerId,taskCount:taskCount}, function(result){
    if(result.success==true){
      $("#searchForm").submit();
    }else{
      alert(result.message);
    }
    $('.taskWindow').hide();
  });
});
    $('.password-btn').click(function () {
      var password = $('.password-value').val();
      var wrongMessage = $('.passwordWrong');
      password = password.replace(/(^\s*)|(\s*$)/g, "");
      if(password.length == 0){
        wrongMessage.html('密码不能为空！');
        return false;
      }else if(password.length < 4){
        wrongMessage.html('密码至少4位！');
        return false;
      }
      $.post('${ctx}/admin/exam-param/marker/reSetPassword', {id: markerId,password:password}, function(result){
        if(result.success==true){
          $("#searchForm").submit();
        }else{
          alert(result.message);
        }
        $('.reSetPasswordWin').hide();
      });
    });

function page(n,s){
	$("#pageNumber").val(n);
	$("#pageSize").val(s);
	$("#searchForm").attr("action","${ctx}/admin/exam-param/marker");
	$("#searchForm").submit();
	return false;
}
function goSearch(){
	$("#pageNumber").val(1);
	$("#pageSize").val('${query.pageSize}');
	$("#searchForm").attr("action","${ctx}/admin/exam-param/marker");
	$("#searchForm").submit();
	return false;
}
</script>	
</body>
</html>