<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />

<%@ include file="../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/papers/batchPaper.js"></script>
<%@ include file="../common/validation.jsp"%>
<title>试卷检索</title>

<script language="javascript">
$(document).ready(function(){
    $('#search-form').submit(function(event){
    	event.preventDefault(); 
        var param = $('#search-form').serializeJson();
        param = $.extend(param, {page:1,rows:10});
        $('#addToBatchPapersDG').datagrid('load',param);
    });
});

function addPapersToBatch(batchId){
	var rowSel = $("#addToBatchPapersDG").datagrid("getSelected"); 
	if(rowSel==null){
		$.messager.alert('提示','请选择一行记录！');
	}else{
		var paperIds =[];
		var rows = $("#addToBatchPapersDG").datagrid("getSelections");
		for(var i=0; i<rows.length; i++){
	        paperIds.push(rows[i].id);
	    }
		
		$.ajax({
			type : "POST",
			url : "${ctx}/examPaper/addPapersToBatch",
			data :  {batchId: batchId, paperIds: paperIds},
			dataType : "json",
			success : function(callback) {
				if(callback.flag=="success"){
	                $.messager.alert('提示','操作成功！');
	                $('#addToBatchPapersDG').datagrid('reload'); 
                    $('#addToBatchPapersDG').datagrid('clearChecked');
	            }else{
	                $.messager.alert('提示','操作失败！');
	            }
			}
		});
	}
}

function backToBatchPaperList(batchId){
	window.location.href="${ctx}/examPaper/batchPapers/"+batchId;
}

</script>
</head>
<body>
    <%@ include file="../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../common/sub_menu.jsp"%>
        <div class="page" id="page" >
        <div class="page-header" >试卷检索</div>
        <div class="page-body">
        
	        <div>
	            <form id="search-form" method="post" >
		            <table class="searchTable">
		              <tr>
		                  <th>课程：</th>
		                  <td><input name="courseName" placeholder="课程代码或名称" id="courseName"/></td>
		                  <th>教材：</th>
		                  <td><input name="bookName" placeholder="教材名称" id="bookName"/></td>
		                  <th>学校：</th>
		                  <td><input name="school" placeholder="学校名称" id="school"/></td>
		              </tr>
		              <tr>
		                  <th>试卷编号：</th>
                          <td><input name="code" placeholder="试卷编号" id="code"/></td>
		                  <th>试卷状态：</th>
		                  <td style="width:300px;" colspan="3">
		                      <c:if test="${paperBatch.type == '清样' }" >
			                      <input type="checkbox" checked disabled><label>毛坯</label></input>
		                      </c:if>
		                      <c:if test="${paperBatch.type == '启用' }" >
			                      <span class="checkbox" ><input type="checkbox" checked disabled><label>清样</label></input></span>
                              </c:if>
		                  </td>
		              </tr>
		            </table>
		            <input type="submit" value="查询" id="search" />
	            </form>
				</div>
	        <div style="clear:both; margin-bottom:10px;"></div>
	        
	        <div class="right" style="min-height:300px;position: relative;">
	             <div id="list-wrap posts" class="listview">
	                 <table id="addToBatchPapersDG" class="easyui-datagrid"
	                     data-options="url: '${ctx}/examPaper/queryNeedQYPaper/${paperBatch.id}',fitColumns:true,singleSelect:false,striped:true,pagination:true,selectOnCheck:true,checkOnSelect:true,toolbar: '#tb'">
	                     <thead>
	                         <tr class="title">
	                             <th data-options="field:'ck',checkbox:true"></th>
	                             <th data-options="field:'code',width:80">试卷编码</th>
	                             <th data-options="field:'status',width:60,formatter: formatStatus">状态</th>
	                             <th data-options="field:'courseCode',width:50">课程代码</th>
	                             <th data-options="field:'courseName',width:110">课程名称</th>
	                             <th data-options="field:'bookName',width:150">教材名称</th>
	                             <th data-options="field:'bookAuthor',width:60">作者</th>
	                             <th data-options="field:'bookPress',width:80">出版社</th>
	                             <th data-options="field:'bookPressYear',width:60">版次</th>
	                         </tr>
	                     </thead>
	                   </table>
	                   
	                   <div id="tb" style="height:auto">
	                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addPapersToBatch('${paperBatch.id}')">添加到批次</a>
	                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-return',plain:true" onclick="backToBatchPaperList('${paperBatch.id}')">返回</a>
                        </div>
	               </div>
	            </div>
	        </div>
        </div>
    </div>
</body>
</html>