<%@ 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/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>
<title>文件后缀设置</title>

<script language="javascript">
var editIndex = undefined;
var rowIndex;
function endEditing(){
    if (editIndex == undefined){return true;}
    if ($('#dg').datagrid('validateRow', editIndex)){
    	rowIndex=editIndex;
        
        $('#dg').datagrid('endEdit', editIndex);
        editIndex = undefined;
        return true;
    } else {
        return false;
    }
}

function append(){
    if (endEditing()){
        $('#dg').datagrid('appendRow',{status:'P'});
        editIndex = $('#dg').datagrid('getRows').length-1;
        $('#dg').datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex);
    }
}


function accept(){
	 if (endEditing()){
        var suffix=$('#dg').datagrid('getRows')[rowIndex]['suffix'];
        obj = {
				"suffix" : suffix
			};
        var Suffix = JSON.stringify(obj);
        $.ajax({
    		type : "POST",
    		url : "${ctx}/examSetting/saveSuffix",
    		data : Suffix,
    		contentType : "application/json; charset=utf-8",
    		dataType : "json",
    		success : function(callback) {
    			callback=eval(callback);
    			if(callback.result=="fail"){
    				$.messager.alert("操作提示", "文件后缀名不能输入重复,请修改后再进行保存!","error");
    				$('#dg').datagrid('selectRow', rowIndex).datagrid('beginEdit', rowIndex);
    			}else{
    				$('#dg').datagrid('reload');
    			}
    		}
    	});
	}
}

function removeSuffix(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		var obj={
        		"id" : row.id
        	};
		var Suffix=JSON.stringify(obj);
		$.ajax({
			type : "POST",
			url : "${ctx}/examSetting/delSuffix",
			data :  Suffix ,
			contentType : "application/json; charset=utf-8",
			dataType : "json",
			success : function(callback) {
				callback=eval(callback);
				if(callback.result=="success"){
					$.messager.alert('提示','删除成功','info');
					$('#dg').datagrid('reload');
				}else{
					$.messager.alert('提示','删除失败','error');
					$('#dg').datagrid('reload');
				}
			}
		});
	}else{
		$.messager.alert('提示','请选择要删除的行');
	}
}
function reject(){
    $('#dg').datagrid('rejectChanges');
    editIndex = undefined;
}
</script>
</head>
<body>
<div class="container-fluid">
	<%@ include file="../common/header.jsp"%>
	<div class="row-fluid">
		<%@ include file="../common/sub_menu.jsp"%>
		
		<div class="span10">
			<ul class="breadcrumb">
	            <li class="active">文件后缀设置</li>
            </ul>

			<div style="padding-top: 20px;"><p style="font-size: 16px;color: red">提示:文件后缀名因为涉及到卷库操作正确性,所以设置好后再进行卷库管理操作</p></div>
			
			<div class="page-body" style="width: 600px;margin-top:10px;" >

				<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}/examSetting/querySuffix'
	                     ,toolbar: '#tb'
	                     ,fitColumns:true
	                     ,singleSelect:true
	                     ,striped:true
	                     ,pagination:true">
	                     <thead>
	                         <tr class="title">
	                             <th data-options="field:'id',width:60">ID</th>
	                             <th data-options="field:'suffix',width:100, editor:{
	                                   type:'validatebox',
	                                   options:{
	                                       required:true
	                                       }
	                                   }">需要保留的文件后缀名</th>
	                         </tr>
	                     </thead>
	                   </table>
	                   
	                   <div id="tb" style="height:auto">
                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-add',plain:true" onclick="append()">添加</a>
                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-save',plain:true" onclick="accept()">保存</a>
					        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-undo',plain:true" onclick="reject()">撤销</a>
					        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-remove',plain:true" onclick="removeSuffix()">删除</a>
                        </div>
	               </div>
	               
	            </div>
			</div>
		</div>
	</div>
</div>
<div id="footer">版权所有：武汉启明泰和软件服务有限公司</div>
</body>
</html>