<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>
<script language="javascript">
var url      = '<c:url value="/onl/admin/adapter/socketPortMan.json" />';
var url_view = '<c:url value="/onl/admin/adapter/socketPortMan.view" />';
var url_excel= '<c:url value="/onl/admin/adapter/socketPortMan.excel" />';

function init() {
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			//EAI서버구분코드
			new makeOptions("CODE","NAME").setObj($("select[name=searchEaiSevrDstCd]")).setData(json.inoutTypeRows).setFormat(codeName3OptionFormat).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=searchUseYn]")).setNoValueInclude(true).setNoValue("", "전체").setData(json.useYnTypeRows).setFormat(codeName3OptionFormat).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=searchOrderType]")).setData(json.orderTypeRows).setFormat(nameOptionFormat).rendering();
			
			putSelectFromParam();
			
			if(typeof callback === 'function') {
				callback(key);
			}
			
			list("1");
						
		},
		error:function(e){
			alert(e.responseText);
		}
	});
	
}

function list(_page)
{   
	var page = "${param.page}";
	if(_page) page = _page;
	
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	
	$("#grid").setGridParam({ url:url,postData: postData ,datatype:'json',page : page }).trigger("reloadGrid");
}

function formatterFunction(cellvalue, options, rowObject) {
	var rowId = options["rowId"];
	if (cellvalue == "1") {
		return "사용함";
	} else{
		return "사용안함";
	}
}

function timeStampFormat2(cellvalue, options, rowObject){
	if ( cellvalue.trim() == "" || cellvalue.length < 17 )
		return '';
	return cellvalue.substr(0,4) + '-' +
	       cellvalue.substr(4,2) + '-' +
	       cellvalue.substr(6,2) + ' ' +
	       cellvalue.substr(8,2) + ':' +
	       cellvalue.substr(10,2) + ':' +
	       cellvalue.substr(12,2);
	       
}	

$(document).ready(function() {	
	
	init();	
	
    var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
    
	$('#grid').jqGrid({
		datatype:"local",
		mtype: 'POST',
		url: url, 
		postData : gridPostData,
		colNames:[
			 	 '<%=localeMessage.getString("socketPortMan.eaisevrdstcd")%>',
				 '<%=localeMessage.getString("socketPortMan.recvadptrbzwkname")%>',
				 '<%=localeMessage.getString("socketPortMan.recvadptrdesc")%>',
				 '<%=localeMessage.getString("socketPortMan.recvtestport")%>',
				 '<%=localeMessage.getString("socketPortMan.recvportuseyn")%> ',
				 '<%=localeMessage.getString("socketPortMan.recvrealport")%>',
				 '<%=localeMessage.getString("socketPortMan.recvportlastymd")%>',
				 '<%=localeMessage.getString("socketPortMan.recvlastadmuserid")%>',
				 '<%=localeMessage.getString("socketPortMan.sendadptrbzwkname")%>',
				 '<%=localeMessage.getString("socketPortMan.sendadptrdesc")%>',
				 '<%=localeMessage.getString("socketPortMan.sendtestport")%>',
				 '<%=localeMessage.getString("socketPortMan.sendportuseyn")%>',
				 '<%=localeMessage.getString("socketPortMan.sendrealport")%>',
				 '<%=localeMessage.getString("socketPortMan.sendportlastymd")%>',
				 '<%=localeMessage.getString("socketPortMan.sendlastadmuserid")%>'
                  ],
		colModel:[
			    { name : 'EAISEVRDSTCD'         , hidden:true},
				{ name : 'RECVADPTRBZWKNAME'    , align:'left'   	 ,width:200},
				{ name : 'RECVADPTRDESC'   		, align:'left'     	 ,width:200 },
				{ name : 'RECVTESTPORT'       	, align:'center'     ,width:95 },
				{ name : 'RECVPORTUSEYN'       	, align:'left'     	 ,width:200 },
				{ name : 'RECVREALPORT'   		, align:'center'   	 ,width:95 },
				{ name : 'RECVPORTLASTYMD'   	, align:'center'     ,width:115 ,formatter: timeStampFormat2},
				{ name : 'RECVLASTADMUSERID'    , align:'center'     ,width:70 },
				{ name : 'SENDADPTRBZWKNAME'    , align:'left'   	 ,width:200},
				{ name : 'SENDADPTRDESC'   		, align:'left'     	 ,width:200 },
				{ name : 'SENDTESTPORT'       	, align:'center'     ,width:95 },
				{ name : 'SENDPORTUSEYN'       	, align:'left'     	 ,width:200 },
				{ name : 'SENDREALPORT'   		, align:'center'   	 ,width:95 },
				{ name : 'SENDPORTLASTYMD'   	, align:'center'     ,width:115 ,formatter: timeStampFormat2},
				{ name : 'SENDLASTADMUSERID'    , align:'center'     ,width:70 },
				],
        jsonReader: {
             repeatitems:false
        },	   
//        multiselect:true,
//		rowNum : '${rmsDefaultRowNum}',
//      pager : $('#pager'),
// 		page : '${param.page}',
//	    height: $("#container").height(),
		height : '600',
		rowNum : 10000,
		viewrecords: true,
		sortname : '${param.sortName}',
		sortorder : '${param.sortOrder}',
		rowList : eval('[${rmsDefaultRowList}]'),
		loadComplete:function (d){
	    	
	    },
	    loadError: function (jqXHR, textStatus, errorThrown) {
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	},
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
			$("#selectCnt").text(" [ "+$("#grid").getGridParam("reccount") + " 건] ");
			
		},			
		ondblClickRow: function(rowId) {
			var rowData = $(this).getRowData(rowId); 
            var url2 = url_view;
            
            url2 += '?cmd=DETAIL';
            url2 += '&page='+$(this).getGridParam("page");
            url2 += '&returnUrl='+getReturnUrl();
            url2 += '&menuId='+'${param.menuId}';
        	url2 += '&sortName='+$("#grid").getGridParam("sortname");
        	url2 += '&sortOrder='+$("#grid").getGridParam("sortorder");            
			//검색값
            url2 += '&'+getSearchUrl();
            
            //key값
            url2 += '&eaiSevrDstCd='+rowData['EAISEVRDSTCD'];
            url2 += '&recvTestPort='+rowData['RECVTESTPORT'];
            goNav(url2);
		}
			
	});
	
	resizeJqGridWidth('grid','content_middle','1680');
	
	
	$("select[name=searchEaiSevrDstCd],select[name=searchUseYn],select[name=searchOrderType]").change(function(){
		list("1");
	});	

	$("#btn_search").click(function(){
		list("1");
	});
	
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	$("#btn_new").click(function(){
		var url2 = '<c:url value="/onl/admin/adapter/socketPortMan.view"/>';
		var searchEaiSevrDstCd = $("#searchEaiSevrDstCd").val();
		url2 += '?cmd=DETAIL';
		url2 += '&page='+$("#grid").getGridParam("page");
		url2 += '&returnUrl='+getReturnUrl();
        url2 += '&menuId='+'${param.menuId}';
		//검색값
        url2 += '&'+getSearchUrl();
		
        goNav(url2);
	});
	
	$("#btn_excel").click(function(event) {
        event.stopPropagation(); // Do not propagate the event.
        // Create an object that will manage to download the file.
        var target = "excelDown" ; // iframe의 name
        //(url,cmd,gridObj,formObject,fileName,merge)
		gridToExcelSubmit3(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'소켓 포트 리스트');
		return false;
	});
	
	
	$("#btn_delete").click(function(){
		var params = new Array();
		var ids = $("#grid").jqGrid('getDataIDs');
		var chkcnt = 0;
		var cmd = "";
		
		
		for(var i=0;i<ids.length;i++){
			if($("input:checkbox[id='jqg_grid_"+ids[i]+"']").is(":checked")){
				var rowObject = $("#grid").getRowData(ids[i]);
				params.push(rowObject);
				chkcnt++;
			}
		}
		
		if(chkcnt == 0){
			alert("삭제할 데이터를 체크해 주세요.");
			return false;
		}
		
		//삭제 컨펌
		if (confirm("선택한 포트정보를 삭제하겠습니까?")== false){
			return;
		}
	
		var postData = [];
		postData.push({ name: "cmd" 		 , value: "DELETE_LIST"});
		postData.push({ name: "gridData" 	 , value:JSON.stringify(params)});
		$.ajax({
			type : "POST",
			url : url,
			dataType : "json",
			data : postData,
			success : function(json) {
				if(json.message == "success"){
					alert("삭제하였습니다");
					list();
				}else{
					alert("삭제중 에러가 발생했습니다.");
				}
				
			},
			error : function(e) {
				alert("error"+e.responseText);
			}
		});
	});
	
	buttonControl();
	
	
});
 
</script>
</head>
	<body>		
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li><a href="#">${rmsMenuPath}</a></li>					
				</ul>					
			</div><!-- end content_top -->
			<div class="content_middle" id="content_middle">
				<div class="search_wrap">
					&nbsp;<span style="color:blue;" id="selectCnt"></span>
					<button type="button" class="cssbtn" id="btn_excel" level="R" ><i class="material-icons">table_view</i> <%= localeMessage.getString("button.excel") %></button>
					<button type="button" class="cssbtn" id="btn_new" level="W" ><i class="material-icons">add</i> <%= localeMessage.getString("button.new") %></button>
					<button type="button" class="cssbtn" id="btn_search" level="R" ><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %></button>
<%--  					<img src="<c:url value="/img/btn_excel.png"/>" id="btn_excel" level="R"/>  --%>
<%--  					<img src="<c:url value="/img/btn_delete.png"/>" alt="" id="btn_delete" level="W"/> --%>
<%-- 					<img src="<c:url value="/img/btn_new.png"/>" alt="" id="btn_new" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" /> --%>
				</div>
				<div class="title"><%=localeMessage.getString("socketPortMan.title")%></div>
				&nbsp;<span style="color:black;"> ※ 모니터링 프라퍼티 필수등록 > <b>[adpt_port_inst]</b> : INST명 , 포트입력시 업무구분없이(수신테스트포트, 수신온라인포트기준) 조회합니다. </span>
				<form id="ajaxForm"  onsubmit="return false;">
					<table class="search_condition" cellspacing=0;>
						<tbody>
							<tr>
								<th style="width:130px;"><%=localeMessage.getString("socketPortMan.sevrdstCd")%></th>
								<td>
									<div class="select-style">
										<select name="searchEaiSevrDstCd" value="${param.searchEaiSevrDstCd}">
										</select>
									</div>	
								</td>
								<th style="width:130px;"><%=localeMessage.getString("socketPortMan.useyn")%></th>
								<td>
									<div class="select-style">
										<select name="searchUseYn" value="${param.searchUseYn}">
										</select>
									</div>	
								</td>
								<th style="width:130px;"><%=localeMessage.getString("socketPortMan.ordertype")%></th>
								<td>
									<div class="select-style">
										<select name="searchOrderType" value="${param.searchOrderType}">
										</select>
									</div>	
								</td>
							</tr>
							<tr>
								<th style="width:130px;"><%=localeMessage.getString("socketPortMan.adapterNm")%></th>
								<td><input type="text" name="searchAdptrBzwkName" value="${param.searchAdptrBzwkName}"></td>
								<th style="width:130px;"><%=localeMessage.getString("socketPortMan.bzwknamedesc")%></th>
								<td>
									<input type="text" name="searchAdptrBzwkNameDesc" value="${param.searchAdptrBzwkNameDesc}">
								</td>
								<th style="width:130px;"><%=localeMessage.getString("socketPortMan.searchport")%></th>
								<td>
									<input type="text" name="searchAdptrPort" value="${param.searchAdptrPort}">
								</td>
							</tr>
						</tbody>
					</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

