<%@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"/>
<!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>
 .tongjiTab td{border:1px solid #999999;}
 .first{width: 100px;height: 25px;text-align: center;}
  .second{width: 280px;height: 25px; text-align: center;}
.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;
}

.boderTbl {border-collapse:collapse;border:none;}
.boderTbl th{text-align:center;vertical-align:middle;border:1pt solid #dddddd;padding:5px;}
.boderTbl td{vertical-align:middle;border:1pt solid #dddddd;padding:5px;}
</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>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/uploadHandlers.js"></script>
<%@ include file="../../common/validation.jsp"%>
<title>课程管理</title>

<script language="javascript">
var inCourseStatusMap = ${inCourseStatusMap};
function inCourseStatusFormatter(value, rowData, rowIndex) {
    for (var i = 0; i < inCourseStatusMap.length; i++) {
        if (inCourseStatusMap[i].key == value) {
            return inCourseStatusMap[i].text;
        }
    }
}

$(document).ready(function(){
	
	$("#downCourseTemp").on('click',function(){
		window.location.href="${ctx}/resources/downloads/国考课程信息导入模板.xlsx";
	});
	$("#searchBtn").on('click',function(){
    	$('#search-form').submit();
    });
    $('#search-form').submit(function(event){
        event.preventDefault(); 
        var param = $('#search-form').serializeJson();
        param = $.extend(param, {page:1,rows:10});
        $('#dg').datagrid('load',param);
    });

    $("#dg").datagrid({
        onDblClickRow: function (rowIndex, rowData) {
            openCourseWin(rowData,"编辑课程信息");
        }
    });
    
    $("#addBtn").click(function(){
    	openCourseWin({type:1,status:1},"添加课程信息");
    	return false;
    });
    
    $("#cancleEditBtn").click(function(){
    	$('#editCourseDiv').window('close');
    	return false;
    });
    
    $("#saveEditBtn").click(function(){
    	try{
    		saveCourseEdit();
    	}catch(e){
    		//console.log(e);
    	}
    	return false;
    });
    
    $("#formForEdit").validationEngine();
    
    $("#remarkForEdit").keydown(function(){
    	calculate_byte(200,'remarkForEdit','count');
    });
    $("#remarkForEdit").keyup(function(){
    	calculate_byte(200,'remarkForEdit','count');
    });
    $("#remarkForEdit").keypress(function(){
    	calculate_byte(200,'remarkForEdit','count');
    });
    
    $("#editBtn").click(function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData){
    		openCourseWin(rowData,"编辑课程信息");
    	}else{
    		$.messager.alert('提示','请选择一行进行编辑操作');
    	}
    });
    
    $("#linkBooksBtn").click(function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData){
    		openLinkBooksWin(rowData.id);
    	}else{
    		$.messager.alert('提示','请选择一行进行关联教材操作');
    	}
    });
    
    $("#linkQuestionTypeBtn").click(function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData){
    		openLinkQuestionTypeWin(rowData.id);
    	}else{
    		$.messager.alert('提示','请选择一行进行关联题型操作');
    	}
    });
    
    $("#cancleLinkBooksBtn").click(function(){
    	$('#linkBooksDiv').window('close');
    	return false;
    });
    
    $("#saveLinkBooksBtn").click(function(){
    	saveLinkBooks();
    	return false;
    });
    
    
    $("#cancleLinkQuestionTypeBtn").click(function(){
    	$('#linkQuestionTypeDiv').window('close');
    	return false;
    });
    
    $("#saveLinkQuestionTypeBtn").click(function(){
    	saveLinkQuestion();
    	return false;
    });
    
    $('#searchBookBtn').click(function(){
        var param = {'keyword':$('#keywordForSearchBook').val()};
        param = $.extend(param, {page:1,rows:10});
        $('#allBooksDg').datagrid('load',param);
        return false;
    });

    $('#searchQuestionTypeBtn').click(function(){
        var param = {'keyword':$('#keywordForSearchQuestionType').val()};
        param = $.extend(param, {page:1,rows:10});
        $('#allQuestionTypeDg').datagrid('load',param);
        return false;
    });
    
    $("#addBooksBtn").click(function(){
    	bookToRight();
    });
    
    $("#delBooksBtn").click(function(){
    	bookToLeft();
    });
    
    
    
    $("#addQuestionTypeBtn").click(function(){
    	questionTypeToRight();
    });
    
    $("#delQuestionTypeBtn").click(function(){
    	questionTypeToLeft();
    });
    
    $("#linkSkelCfgBtn").click(function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData){
    		$(document).mask('正在加载中，请稍等...');
    		var courseId = rowData.id;
        	$.ajax({
    			type : "POST",
    			url : "${ctx}/paperSkeleton/getSkelCfgInfo",
    			data : {"courseId":courseId}, 
    			success : function(callback) {
    				$(document).unmask();
    				if(callback.flag == 'success'){
    					var cfg = callback.skelCfg;
    					$("#skelCfgId").val(cfg.id);
    					$("#courseIdForSkelCfg").val(courseId);
    					$("#ability1Percent").val(cfg.ability1Percent);
    					$("#ability2Percent").val(cfg.ability2Percent);
    					$("#ability3Percent").val(cfg.ability3Percent);
    					$("#ability4Percent").val(cfg.ability4Percent);
    					$("#abilityOffset").val(cfg.abilityOffset);
    					$("#estimateDifficulty1Percent").val(cfg.estimateDifficulty1Percent);
    					$("#estimateDifficulty2Percent").val(cfg.estimateDifficulty2Percent);
    					$("#estimateDifficulty3Percent").val(cfg.estimateDifficulty3Percent);
    					$("#estimateDifficulty4Percent").val(cfg.estimateDifficulty4Percent);
    					$("#estimateDifficultyOffset").val(cfg.estimateDifficultyOffset);
    					$('#editSkelCfgDiv').window('open');
    					$("#ability1Percent").focus();
    				}else{
    					$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
    				}
    			}
    		});
    	}else{
    		$.messager.alert('提示','请选择一行进行细目表配置操作');
    	}
    });
    
	$("[textType='number']").each(function(){
    	$(this).keyup(function(e){
    		var val = $(this).val() - 0;
    		if(!val || val < 0){
    			val = '';
    		}
    		$(this).val(val);
    	});
	});
	
	$("#setDefaultSkelCfgBtn").click(function(){
		$('#ability1Percent').val(20);
    	$('#ability2Percent').val(30);
    	$('#ability3Percent').val(30);
    	$('#ability4Percent').val(20);
    	$('#abilityOffset').val(3);
    	$('#estimateDifficulty1Percent').val(20);
    	$('#estimateDifficulty2Percent').val(30);
    	$('#estimateDifficulty3Percent').val(30);
    	$('#estimateDifficulty4Percent').val(20);
    	$('#estimateDifficultyOffset').val(3);
    	return false;
	});
    
    $("#saveSkelCfgEditBtn").click(function(){
    	var allRight = true;
		$("[textType='number']").each(function(index,element){
			var curInput = $(this);
    		var val = curInput.val() - 0;
    		if(!val || val < 0){
    			val = '';
    		}
    		curInput.val(val);
    		if(val == ''){
    			$.messager.alert('提示', '请输入数值!', 'error', function () {
    				curInput.focus();
 	        	});
    			allRight = false;
    			return allRight;
    		}
		});
		if(!allRight){
			return false;
		}
    	var ability1Percent = $('#ability1Percent').val() - 0;
    	var ability2Percent = $('#ability2Percent').val() - 0;
    	var ability3Percent = $('#ability3Percent').val() - 0;
    	var ability4Percent = $('#ability4Percent').val() - 0;
    	var abilityOffset = $('#abilityOffset').val() - 0;
    	var estimateDifficulty1Percent = $('#estimateDifficulty1Percent').val() - 0;
    	var estimateDifficulty2Percent = $('#estimateDifficulty2Percent').val() - 0;
    	var estimateDifficulty3Percent = $('#estimateDifficulty3Percent').val() - 0;
    	var estimateDifficulty4Percent = $('#estimateDifficulty4Percent').val() - 0;
    	var estimateDifficultyOffset = $('#estimateDifficultyOffset').val() - 0;
    	
    	var abilityPercent = ability1Percent + ability2Percent + ability3Percent + ability4Percent;
    	if(abilityPercent != 100){
    		$.messager.alert('提示', '您输入的认知层次比例值总和为：' + abilityPercent + '，必须为100，请重新填写!', 'error', function () {
				$("#ability1Percent").focus();
	        });
    		return false;
    	}
    	var estimateDifficultyPercent = estimateDifficulty1Percent + estimateDifficulty2Percent + estimateDifficulty3Percent + estimateDifficulty4Percent;
    	if(estimateDifficultyPercent != 100){
    		$.messager.alert('提示', '您输入的预计难度比例值总和为：' + estimateDifficultyPercent + '，必须为100，请重新填写!', 'error', function () {
				$("#estimateDifficulty1Percent").focus();
	        });
    		return false;
    	}
    	
    	$(document).mask('正在加载中，请稍等...');
		$.ajax({
			type : "POST",
			url : "${ctx}/paperSkeleton/saveSkelCfg",
			data : $('#skelCfgForm').serialize(), 
			success : function(callback) {
				$(document).unmask();
				if(callback.flag == 'success'){
					$.messager.alert('提示', callback.msg, 'info', function () {
						$('#editSkelCfgDiv').window('close');
                    });
				}else{
					$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
				}
			}
		});
    	return false;
    });
    
    $("#cancleSkelCfgEditBtn").click(function(){
    	$('#editSkelCfgDiv').window('close');
    	return false;
    });
});

function questionTypeToLeft(){
	var selectedRow = null;
	while((selectedRow = $("#chosenQuestionTypeDg").datagrid('getSelected')) != null){
		var selectedIndex = $("#chosenQuestionTypeDg").datagrid('getRowIndex',selectedRow);
		$("#chosenQuestionTypeDg").datagrid('deleteRow',selectedIndex);
	}
}

function questionTypeToRight(){
	var rows1 = $("#allQuestionTypeDg").datagrid('getSelections');
	
	var data= $("#chosenQuestionTypeDg").datagrid("getData");
	var rows=data.rows;
	var id;
	var flag;
	for(var i=0;i<rows1.length;i++){
		id=rows1[i].id;
	}
	for(var i=0;i<rows.length;i++){
		if(rows[i].id==id){
			flag=true;
		}
	}
	if(!flag){
		for(var i=0;i<rows1.length;i++){
			var index = -1;
			var existed = ((index = $("#chosenQuestionTypeDg").datagrid('getRowIndex',rows1[i])) >= 0);
			if(!existed){
	    		rows1[i].inCourseStatus = ${defaultBookInCourseStatus};
	    		index = $('#chosenQuestionTypeDg').datagrid('insertRow',{row:rows1[i]}).datagrid('getRows').length-1;
	    		$('#chosenQuestionTypeDg').datagrid('beginEdit', index);
			}
			$('#chosenQuestionTypeDg').datagrid('selectRow', index);
		}
		$("#allQuestionTypeDg").datagrid('unselectAll');
	}
	
}

function bookToRight(){
	var rows1 = $("#allBooksDg").datagrid('getSelections');
	
	var data= $("#chosenBooksDg").datagrid("getData");
	var rows=data.rows;
	var id;
	var flag;
	for(var i=0;i<rows1.length;i++){
		id=rows1[i].id;
	}
	for(var i=0;i<rows.length;i++){
		if(rows[i].id==id){
			flag=true;
		}
	}
	if(!flag){
		for(var i=0;i<rows1.length;i++){
			var index = -1;
			var existed = ((index = $("#chosenBooksDg").datagrid('getRowIndex',rows1[i])) >= 0);
			if(!existed){
	    		rows1[i].inCourseStatus = ${defaultBookInCourseStatus};
	    		index = $('#chosenBooksDg').datagrid('insertRow',{row:rows1[i]}).datagrid('getRows').length-1;
	    		$('#chosenBooksDg').datagrid('beginEdit', index);
			}
			$('#chosenBooksDg').datagrid('selectRow', index);
		}
		$("#allBooksDg").datagrid('unselectAll');
	}
	
}

function bookToLeft(){
	var selectedRow = null;
	while((selectedRow = $("#chosenBooksDg").datagrid('getSelected')) != null){
		var selectedIndex = $("#chosenBooksDg").datagrid('getRowIndex',selectedRow);
		$("#chosenBooksDg").datagrid('deleteRow',selectedIndex);
	}
}

function openCourseWin(course,title){
	$("#idForEdit").val(course.id);
	$("#codeForEdit").val(course.code);
	$("#codeHubeiForEdit").val(course.codeHubei);
	$("#nameForEdit").val(course.name);
	$("#typeForEdit").val(course.type);
	$("#statusForEdit").val(course.status);
	$("#scoreForEdit").val(course.score);
	$("#remarkForEdit").val(course.remark);
	calculate_byte(200,'remarkForEdit','count');
	$("#codeForEdit").focus();
	$('#editCourseDiv').window({"title":title});
	$('#editCourseDiv').window('open');
}

function openLinkBooksWin(courseId){
	$("#courseIdForlinkBooks").val(courseId);
	$('#chosenBooksDg').datagrid({
	    url:"${ctx}/course/selectedBooks/" + courseId,
	    onLoadSuccess:function(data){
	    	for(var i=0;i<data.total;i++){
	    		$('#chosenBooksDg').datagrid('beginEdit', i);
	    	}
	    }
	});
	$('#linkBooksDiv').window('open');
}

function openLinkQuestionTypeWin(courseId){
	$("#courseIdForlinkQuestionType").val(courseId);
	$('#chosenQuestionTypeDg').datagrid({
	    url:"${ctx}/questionType/selectQuestionTypesByCourseId/" + courseId,
	    onLoadSuccess:function(data){
	    	for(var i=0;i<data.total;i++){
	    		$('#chosenQuestionTypeDg').datagrid('beginEdit', i);
	    	}
	    }
	});
	$('#linkQuestionTypeDiv').window('open');
}



function saveCourseEdit(){
	if($("#formForEdit").validationEngine('validate')){
		$.ajax({
			type : "POST",
			url : "${ctx}/course/save",
			data : $('#formForEdit').serialize(), 
			success : function(callback) {
				if(callback.flag == 'success'){
					$.messager.alert('提示', callback.msg, 'info', function () {
						$('#editCourseDiv').window('close');
						$('#dg').datagrid('reload');
                    });
				}else{
					$.messager.alert('提示', callback.msg, 'error');
				}
			}
		});
	}
}

function saveLinkBooks(){
	$(document).mask('正在保存中，请稍等...');
	var rows = $('#chosenBooksDg').datagrid('getRows');
	var arr = [];
	for(var i=0;i<rows.length;i++){
		var status = $('#chosenBooksDg').datagrid('getEditor',{index:i,field:'inCourseStatus'}).target.combobox('getValue');
		arr[arr.length] = rows[i].id + "@" + status;
	}
	var param = {'courseId':$('#courseIdForlinkBooks').val(),'links':arr};
	$.ajax({
		type : "POST",
		url : "${ctx}/course/saveLinkBooks",
		data : param,
		success : function(callback) {
			$(document).unmask();
			if(callback.flag == 'success'){
				$.messager.alert('提示', callback.msg, 'info', function () {
					$('#linkBooksDiv').window('close');
                });
			}else{
				$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
			}
		}
	});
}

function saveLinkQuestion(){
	//$(document).mask('正在保存中，请稍等...');
	var rows = $('#chosenQuestionTypeDg').datagrid('getRows');
	var arr = [];
	for(var i=0;i<rows.length;i++){
		arr[arr.length] = rows[i].id ;
	}
	var param = {'courseId':$('#courseIdForlinkQuestionType').val(),'links':arr};
	$.ajax({
		type : "POST",
		url : "${ctx}/questionType/saveLinkQuestionType",
		data : param,
		success : function(callback) {
			$(document).unmask();
			if(callback.flag == 'success'){
				$.messager.alert('提示', callback.msg, 'info', function () {
					$('#linkQuestionTypeDiv').window('close');
                });
			}else{
				$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
			}
		}
	});
}
</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 class="right" style="min-height:300px;position: relative;">
	             <div id="list-wrap posts" class="listview">
	                 <table id="dg" class="easyui-datagrid"
	                     data-options="url:'${ctx}/course/queryCourses',fitColumns:true,singleSelect:true,striped:true,pagination:true,toolbar: '#tb',pageSize:20">
	                     <thead>
	                         <tr class="title">
	                             <th data-options="field:'code',width:80">课程代码</th>
	                             <!-- 
	                             <th data-options="field:'codeHubei',width:100">省编码</th>
	                              -->
	                             <th data-options="field:'name',width:150">课程名称</th>
	                             <th data-options="field:'typeName',width:80">课程类型</th>
	                             <th data-options="field:'statusName',width:80">状态</th>
	                             <!-- 
	                             <th data-options="field:'score',width:80">学分</th>
	                              -->
	                             <th data-options="field:'remark',width:80">备注</th>
	                         </tr>
	                     </thead>
	                   </table>
	                   
	                   
	                   <div id="tb">
	                   
	                   	<div  style="height:auto">
		                   		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" id="addBtn">添加</a>
						        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" id="editBtn">编辑</a>
						        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="linkBooksBtn">教材</a>
						        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="linkQuestionTypeBtn">题型</a>
						        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="linkSkelCfgBtn">细目表配置</a>
						        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" id="importCourseBtn">导入课程</a>
						        <a href="#" class="easyui-linkbutton" iconCls="icon-download" id="downCourseTemp">下载课程模板</a>
						    </div>
		                   <div>
				            <form id="search-form" method="post" >
					            <select name="type">
					                <option value="">课程类型</option>
					                <c:forEach items="${courseTypeDic}" var="m">
			            			<option value="${m.key }">${m.value }</option>
			            			</c:forEach>
					            </select>
					            &nbsp;&nbsp;<input name="keyword" placeholder="课程名称或编号"/>
					            <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchBtn">查找</a>
				            </form>
							</div>
						</div>
	               </div>
	            </div>
	        </div>
        </div>
    </div>

<div style="display: none;">
    <div id="editCourseDiv" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:500px;height:380px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;">
        	<form action="#" id="formForEdit">
        	<input type="hidden" name="id" id="idForEdit"/>
            <table style="width: 450px;" cellpadding="5" border="0">
            	<tr>
            		<td class="myTitleTd">课程代码</td>
            		<td class="myValueTd"><input type="text" name="code" id="codeForEdit" maxlength="5" class="validate[required,custom[integer],minSize[5]]"/><label>*</label>(5位数字)</td>
            	</tr>
            	<tr>
            		<td class="myTitleTd">省编码</td>
            		<td class="myValueTd"><input type="text" name="codeHubei" id="codeHubeiForEdit" maxlength="40"/></td>
            	</tr>
            	<tr>
            		<td class="myTitleTd">课程名称</td>
            		<td class="myValueTd"><input type="text" name="name" id="nameForEdit" maxlength="50" class="validate[required]"/><label>*</label></td>
            	</tr>
            	<tr>
            		<td class="myTitleTd">课程类型</td>
            		<td class="myValueTd"><select name="type" id="typeForEdit" class="validate[groupRequired[type]]">
            			<option value="">请选择</option>
            			<c:forEach items="${courseTypeDic}" var="m">
            			<option value="${m.key }">${m.value }</option>
            			</c:forEach>
            		</select><label>*</label></td>
            	</tr>
            	<tr>
            		<td class="myTitleTd">状态</td>
            		<td class="myValueTd"><select name="status" id="statusForEdit" class="validate[groupRequired[status]]">
            			<option value="">请选择</option>
            			<c:forEach items="${courseStatusDic}" var="m">
            				<option value="${m.key }">${m.value }</option>
            			</c:forEach>
            		</select></td>
            	</tr>
            	<!-- 
            	<tr>
            		<td class="myTitleTd">课程学分</td>
            		<td class="myValueTd"><input type="text" name="score" id="scoreForEdit" maxlength="3" class="validate[custom[integer],max[200],min[0]]" title="请输入学分[0-200]"/></td>
            	</tr>
            	 -->
            	<tr>
            		<td class="myTitleTd">备注</td>
            		<td class="myValueTd"><textarea rows="" cols="" name="remark" id="remarkForEdit"></textarea><span id="count"></span></td>
            	</tr>
            	<tr>
            		<td colspan="2" align="center"><button style="margin-right: 50px;" id="saveEditBtn">保存</button><button id="cancleEditBtn">取消</button></td>
            	</tr>
            </table>
            </form>
        </div>
    </div>
    
    <div id="editSkelCfgDiv" title="编辑细目表配置" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:550px;height:200px;padding:5px;overflow-x: hidden;">
        	<form action="#" id="skelCfgForm">
        	<input type="hidden" name="id" id="skelCfgId"/>
        	<input type="hidden" name="courseId" id="courseIdForSkelCfg"/>
            <table style="width: 500px;margin-top: 10px;" cellpadding="5" border="0" class="boderTbl" align="center">
            	<tr>
            		<td class="myTitleTd" style="width: 120px;">认知层次比例（%）</td>
            		<td class="myValueTd">
            			<input type="text" textType="number" name="ability1Percent" id="ability1Percent" maxlength="2" style="width:20px;"/>%-
            			<input type="text" textType="number" name="ability2Percent" id="ability2Percent" maxlength="2" style="width:20px;"/>%-
            			<input type="text" textType="number" name="ability3Percent" id="ability3Percent" maxlength="2" style="width:20px;"/>%-
            			<input type="text" textType="number" name="ability4Percent" id="ability4Percent" maxlength="2" style="width:20px;"/>%
            		</td>
            		<td class="myTitleTd" style="width: 80px;">允许浮动值（%）</td>
            		<td class="myValueTd">
            			<input type="text" textType="number" name="abilityOffset" id="abilityOffset" maxlength="2" style="width:20px;"/>%
            		</td>
            	</tr>
            	
            	<tr>
            		<td class="myTitleTd">预计难度比例（%）</td>
            		<td class="myValueTd">
            			<input type="text" textType="number" name="estimateDifficulty1Percent" id="estimateDifficulty1Percent" maxlength="2" style="width:20px;"/>%-
            			<input type="text" textType="number" name="estimateDifficulty2Percent" id="estimateDifficulty2Percent" maxlength="2" style="width:20px;"/>%-
            			<input type="text" textType="number" name="estimateDifficulty3Percent" id="estimateDifficulty3Percent" maxlength="2" style="width:20px;"/>%-
            			<input type="text" textType="number" name="estimateDifficulty4Percent" id="estimateDifficulty4Percent" maxlength="2" style="width:20px;"/>%
            		</td>
            		<td class="myTitleTd">允许浮动值（%）</td>
            		<td class="myValueTd">
            			<input type="text" textType="number" name="estimateDifficultyOffset" id="estimateDifficultyOffset" maxlength="2" style="width:20px;"/>%
            		</td>
            	</tr>
            	<tr>
            		<td colspan="4" align="center" style="height: 30px;">
            			<button style="margin-right: 50px;" id="setDefaultSkelCfgBtn">默认配置</button>
            			<button style="margin-right: 50px;" id="saveSkelCfgEditBtn">保存</button>
            			<button id="cancleSkelCfgEditBtn">取消</button>
            		</td>
            	</tr>
            </table>
            </form>
    </div>
    
    <div id="linkBooksDiv" title="关联教材" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:860px;height:380px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;">
        	<form action="#" id="formForlinkBooks">
        	<input type="hidden" name="courseId" id="courseIdForlinkBooks"/>
<table style="width: 830px;margin-top: 5px;" cellpadding="0" border="0" class="bookSelTable" align="center">
<tr>
<td>
<div style="text-align: left;">
	<input id="keywordForSearchBook" placeholder="教材名称或编号"/>
	<button id="searchBookBtn">查询</button>
</div>
<table id="allBooksDg" class="easyui-datagrid" style="width:450px;height:240px;" data-options="url:'${ctx}/book/queryBooks',fitColumns:true,singleSelect:true,pagination:true,onClickRow:bookToRight">
    <thead>
        <tr>
        	<th data-options="field:'id',width:40">id</th>
            <th data-options="field:'code',width:40">编码</th>
            <th data-options="field:'name',width:300">名称</th>
            <th data-options="field:'statusName',width:60">状态</th>
        </tr>   
    </thead>
</table>
</td>
<td valign="middle" align="center"><div style="margin-bottom: 30px;"><input type="button" value="&gt;" style="width: 30px;" id="addBooksBtn"/></div><div><input type="button" value="&lt;" style="width: 30px;" id="delBooksBtn"/></div></td>
<td align="right" valign="bottom">
<table id="chosenBooksDg" class="easyui-datagrid" style="width:320px;height:240px" data-options="fitColumns:true,singleSelect:true,onClickRow:bookToLeft">
    <thead>   
        <tr>
        	<th data-options="field:'id',width:60">id</th>
            <th data-options="field:'code',width:60">code</th>
            <th data-options="field:'name',width:160">名称</th>
            <th data-options="field:'inCourseStatus',width:80,formatter: inCourseStatusFormatter,editor:{type: 'combobox', options: { data: inCourseStatusMap,valueField: 'key', textField: 'text',required: true,editable:false} }">课程中状态</th>
        </tr>   
    </thead>   
</table>
</td>
</tr>
<tr>
<td colspan="3" style="padding-top: 10px;" align="center"><button style="margin-right: 50px;" id="saveLinkBooksBtn">保存</button><button id="cancleLinkBooksBtn">取消</button></td>
</tr>
</table>
            </form>
        </div>
    </div>
    
    <div id="linkQuestionTypeDiv" title="关联题型" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:860px;height:380px;padding:5px;overflow-x: hidden;">
    	<div id="barcode-scan" style="font-size: 12px;">
    		<form action="#" id="formForlinkQuestionType">
    			<input type="hidden" name="courseId" id="courseIdForlinkQuestionType"/>
    			<table style="width: 830px;margin-top: 5px;" cellpadding="0" border="0" class="bookSelTable" align="center">
    				<tr>
    					<td>
							<div style="text-align: left;">
								<input id="keywordForSearchQuestionType" placeholder="题型名称或编号"/>
								<button id="searchQuestionTypeBtn">查询</button>
							</div>
							<table id="allQuestionTypeDg" class="easyui-datagrid" style="width:450px;height:240px;" data-options="url:'${ctx}/questionType/queryQuestionTypes',fitColumns:true,singleSelect:true,pagination:true,onClickRow:questionTypeToRight">
    							<thead>
							        <tr>
							        	<th data-options="field:'id',width:50">id</th>
							            <th data-options="field:'code',width:50">code</th>
							            <th data-options="field:'name',width:300">名称</th>
							            <th data-options="field:'defaultScore',width:50">默认分值</th>
							            <!--  <th data-options="field:'statusName',width:60">状态</th>-->
							        </tr>   
    							</thead>
							</table>
						</td>
						<td valign="middle" align="center">
							<div style="margin-bottom: 30px;">
								<input type="button" value="&gt;" style="width: 30px;" id="addQuestionTypeBtn"/>
							</div>
							<div>
								<input type="button" value="&lt;" style="width: 30px;" id="delQuestionTypeBtn"/>
							</div>
						</td>
						
						<td align="right" valign="bottom">
							<table id="chosenQuestionTypeDg" class="easyui-datagrid" style="width:320px;height:240px" data-options="fitColumns:true,singleSelect:true,onClickRow:questionTypeToLeft">
							    <thead>   
							        <tr>
							        	<th data-options="field:'id',width:50">id</th>
							            <th data-options="field:'code',width:50">code</th>
							            <th data-options="field:'name',width:160">名称</th>
							            <th data-options="field:'defaultScore',width:60">默认分值</th>
							            <!--  <th data-options="field:'inCourseStatus',width:80,formatter: inCourseStatusFormatter,editor:{type: 'combobox', options: { data: inCourseStatusMap,valueField: 'key', textField: 'text',required: true,editable:false} }">课程中状态</th>-->
							        </tr>   
							    </thead>   
							</table>
						</td>
    				</tr>
    				<tr>
						<td colspan="3" style="padding-top: 10px;" align="center"><button style="margin-right: 50px;" id="saveLinkQuestionTypeBtn">保存</button><button id="cancleLinkQuestionTypeBtn">取消</button></td>
					</tr>
    			</table>
    		</form>
    	</div>
    </div>

		<div id="importCourseDiv" title="导入课程" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:500px;height:300px;padding:10px;">
			<div style="display: inline;   padding: 2px;">
				<span id="spanButtonPlaceholder"></span> 
				
				<div style="padding-top: 25px;" >
				  	<div id="success" style="display:none;"></div>
				  	
					  <div id="error" style="display:none;">
					  <div>
				  		<span>行数据存在错误信息无法导入:</span>
				  		</div>
				        <table style="border-collapse: collapse;" class="tongjiTab">
				        	<tr>
				        		<td class="first">行号</td>
				        		<td class="second">错误信息</td>
				        	</tr>
				        	<tr style="color: red;">
				        		<td class="first" id="firstTd"></td>
				        		<td class="second" id="secondTd"></td>
				        	</tr>
				        	<!-- <tr>
				        		<td class="first">22</td>
				        		<td class="second">22</td>
				        	</tr> -->
				        </table>
	    			</div>
    			</div>
			</div>
		</div>
</div>
</body>
</html>

<script type="text/javascript">
$(function(){
	loadSwfUpload();	//首先加载swfupload();
	$("#importCourseBtn").on('click',function(){
		$("#importCourseDiv").window('open');
		$("#error").hide();
	});
});
var swfUpload = null;
function loadSwfUpload() {
	swfUpload = new SWFUpload({
		 upload_url :"${ctx}/attachment/upload",
		 post_params: {"userId":"${sessionScope.web_session_user.id}"},
		 use_query_string : false,
		  
		// File Upload Settings
		file_size_limit : "50 MB",	// 50MB
		file_types : "*.xls;*.xlsx",
		file_types_description : "Excel文件",
		file_upload_limit 	:	0,

		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		
		// Button Settings
		button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
		button_placeholder_id : "spanButtonPlaceholder",
		button_width: 180,
		button_height: 18,
		button_text : '<span class="button">导入课程信息<span class="buttonSmall"></span></span>',
		button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12px; } .buttonSmall { font-size: 10px; color: #ff0000;}',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
		
		
		// Flash Settings
		flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',

		custom_settings : {
			upload_target : "importDivFileProgressContainer"
		},
		// Debug Settings
		debug: false //是否显示调试窗口
	});
};

function uploadSuccess(file, serverData) {
	serverData=eval('(' + serverData + ')');
	if(serverData.flag=='success'){
		//文件信息保存到数据库后需要对文件进行解析处理
		var param={
				"attId":serverData.att.id
		}
		$.ajax({
			type : "POST",
			url : "${ctx}/course/upLoadCourse",
			data : param,
			dataType : "json",
			success : function(res) {
				$(document).unmask();
				if(res.result=='fail'){ 
					$("#success").hide();
					$("#firstTd").html(res.lineNum);
					$("#secondTd").html(res.msg);
					$("#error").show();
				}else if(res.result=='success'){
					$("#success").html("成功导入"+res.successNum+"条记录");
					$("#success").show();
					$("#error").hide();
					$('#dg').datagrid('reload');
				}else{
					$("#error").show();
					$("#firstTd").html("-");
					$("#secondTd").html(res.msg);
				}
			}
		});
	}else{
		$(document).unmask();
		$.messager.alert('提示',serverData.msg,'error');
	}
}
</script>




