<%@page import="com.qmth.qrzk.repository.utils.Consts"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<c:set var="defaultBookInCourseStatus" value="<%=Consts.BookInCourseStatus.USED%>" scope="request"/>
<c:set var="paperStatus" value="<%=Consts.PaperStatus.dicMap%>" scope="request"/>
<c:set var="defaultPaperToApproveStatus" value="<%=Consts.PaperStatus.TOAPPROVE%>" scope="request"/>
<!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/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' />
<style>
.myTitleTd{
	font-size: 12px;
	font-weight: normal;
	width: 100px;
	height:25px;
	text-align: right;
}

.bookSelTable{
	font-size: 12px;
	font-weight: normal;
}

.myValueTd{
	font-size: 12px;
	font-weight: normal;
	text-align: left;
}

.myValueTd input[type=text]{
	width: 200px;
}

.myValueTd textarea{
	width: 200px;
	height: 50px;
}

.myValueTd select{
	width: 200px;
}

.myValueTd label{
	color: red;
}

.formErrorContent{
	display: none;
}
</style>
<%@ 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/validator.js"></script>
<%@ include file="../common/validation.jsp"%>
<title>课程管理</title>
</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" >
	            	<select name="status" id="status">
	            		<option value="">请选择状态</option>
	            		<c:forEach items="${paperStatus}" var="m">
            			<option value="${m.key }" <security:authorize ifAnyGranted="SECRETARY" ><c:if test="${m.key==defaultPaperToApproveStatus}">selected="selected"</c:if></security:authorize>>${m.value }</option>
            			</c:forEach>
	            	</select>
		            <input name="pagerKey" placeholder="试卷名称"/>
		            <button id="searchBtn">查询</button>
	            </form>
				</div>
	        
	        <div class="right" style="min-height:300px;position: relative;">
	             <div id="list-wrap posts" class="listview">
	                 <table id="dg" class="easyui-datagrid"
	                     data-options="fitColumns:true,singleSelect:true,striped:true,pagination:true,toolbar: '#tb'">
	                     <thead>
	                         <tr class="title">
	                             <th data-options="field:'showName',width:120">名称</th>
	                             <th data-options="field:'head',width:120">题头</th>
	                             <th data-options="field:'courseName',width:100,formatter: function(value,row,index){
					return row.skeleton.course.name + (row.skeleton.course.code != null && row.skeleton.course.code != ''?('(' + row.skeleton.course.code + ')'):'');
				}">课程</th>
	                             <th data-options="field:'bookName',width:120,formatter: function(value,row,index){
					return row.skeleton.book.name + (row.skeleton.book.code != null && row.skeleton.book.code != ''?('(' + row.skeleton.book.code + ')'):'');
				}">教材</th>
	                             <th data-options="field:'statusName',width:60">状态</th>
	                             <th data-options="field:'createdTimeStr',width:60">创建日期</th>
	                             <th data-options="field:'createdByName',width:60">创建人</th>
	                         </tr>
	                     </thead>
	                   </table>
	                   <div id="tb" style="height:auto">
					        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" id="viewBtn">查看</a>
					        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="wordBtn">Word下载</a>
					    </div>
	               </div>
	            </div>
	        </div>
        </div>
    </div>
    
    <div style="display: none;">
	    <form id="downloadForm" action="${ctx}/zujuan/previewPaper/downloadPaper" method="post">
	    	<input type="hidden" id="paperName" name="paperName"/>
	    	<input type="hidden" id="paperId" name="paperId"/>
	    </form>
    </div>
</body>
</html>
<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});
        $('#dg').datagrid({
        	'url':'${ctx}/zujuan/queryPagers',
        	'queryParams':param
        });
        //$('#dg').datagrid('load',param);
    });

    $("#wordBtn").click(function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData != null){
    		createWord(rowData.id,rowData.name);
    	}
    });
    $("#viewBtn").click(function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData != null){
    		var url = "${ctx}/zujuan/viewPapers?skeletion=" + rowData.skeletonId + "&pcIdArrStr=" + rowData.id;
    		window.location.href = url;
    	}
    });
    $("#dg").datagrid({
        onDblClickRow: function (rowIndex, rowData) {
        	$("#viewBtn").click();
        }
    });
    window.setTimeout(function(){$('#search-form').submit();},200);
});

function createWord(paperId,paperName){
	$(document).mask('正在生成试卷，请稍等...');
	$.ajax({
		type : "POST",
		url : "${ctx}/zujuan/previewPaper/" + paperId,
		data : {}, 
		success : function(paper) {
			$(document).unmask();
			if(paper.paperId){
				$('#paperId').val(paper.paperId);
				$('#paperName').val(paper.paperName);
				$('#downloadForm').submit();
			}else{
				$.messager.alert('提示', "生成试卷失败，请刷新后操作!", 'error');
			}
		}
	});
}
</script>