<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	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=euc-kr">
<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/transaction/simpleinterface/simpleInterfaceMan.json" />';
var url_view = '<c:url value="/onl/transaction/simpleinterface/simpleInterfaceMan.view" />';

var selectName = "searchEaiBzwkDstcd";	// selectBox Name
	function init( callback) {
		$.ajax({
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'LIST_COMBO'},
			success:function(json){
				new makeOptions("BIZCODE","BIZNAME").setObj($("select[name=searchEaiBzwkDstcd]")).setNoValueInclude(true).setNoValue("","전체").setData(json.bizList).setFormat(codeName3OptionFormat).rendering();
				
				setSearchable(selectName);	// 콤보에 searchable 설정

				if (typeof callback === 'function') {
					callback();
				}
			},
			error:function(e){
				alert(e.responseText);
			}
		});
		
	}

	function detail(){
		var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
		$("#grid").setGridParam({ url:url,postData: postData }).trigger("reloadGrid");
	}
	
	function search(){
		var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
		$("#grid").setGridParam({ url:url,postData: postData ,page:1 }).trigger("reloadGrid");
	}
	function ioFormatter(cellvalue,options,rowObject){
		var serviceType = sessionStorage["serviceType"];
		if(cellvalue == "I"){
			return "타발";
		}else if(cellvalue =="O"){
			return "당발";	
		}
	}
	function adapterNameShortFormatter(cellvalue,options,rowObject){
		if(cellvalue == null || cellvalue == '')
			return ''
		return cellvalue.substring(1, 4);
	}
	
	function list(){
		detail()
		var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
		$('#grid').jqGrid({
			datatype : "json",
			mtype : 'POST',
			url : url,
			postData : gridPostData,
			colNames : [ '업무구분',
			             '<%= localeMessage.getString("eaiMessage.eaiSvcName")%>',
			             '<%= localeMessage.getString("eaiMessage.eaiSvcDesc")%>',
			             '요청',
			             '응답',
			             '작성자',
			             '가상응답여부',
				         'SyncAsyncType',
			              ],
			colModel : [ { name : 'eaiBzwkDstcd'            , align : 'center' , width:'40', sortable:false},
			             { name : 'eaiSvcName'              , align : 'left'   , width:'100'},
			             { name : 'eaiSvcDesc'              , align : 'left'   },
			             { name : 'fromAdapter'                , align : 'center' , width:'40', formatter:adapterNameShortFormatter },
			             { name : 'toAdapter'                  , align : 'center' , width:'40', formatter:adapterNameShortFormatter },
			             { name : 'author'                , align : 'center' , width:'60' },
			             { name : 'simYn'                   , align : 'center' , width:'40' },
				         { name : 'syncAsyncType'           , align : 'center' , width:'40', hidden: true },
						],
			jsonReader : {
				repeatitems : false
			},
			pager : $('#pager'),
			page : '${param.page}',
			rowNum : '${rmsDefaultRowNum}',
			autoheight : true,
			height : $("#container").height(),
			autowidth : true,
			viewrecords : true,
			rowList : eval('[${rmsDefaultRowList}]'),
			loadComplete:function (d){
				var colModel = $(this).getGridParam("colModel");
				for(var i = 0 ; i< colModel.length; i++){
					$(this).setColProp(colModel[i].name, {sortable : false});
				}
			},		
			ondblClickRow : function(rowId) {
				var rowData = $(this).getRowData(rowId);
				let key = rowData['eaiSvcName'];
				const syncAsyncType = rowData['syncAsyncType'];
				if(syncAsyncType === 'syncAsync'){
					const sendRecvType = key.charAt(key.length - 2); // 끝에서 두 번째 문자 추출
					if(sendRecvType === 'R'){
						// 문자열의 시작 부분부터 끝에서 세 번째 문자까지 추출
						var start = key.substring(0, key.length - 2);
						// 문자열의 마지막 문자 추출
						var end = key.charAt(key.length - 1);
						// 시작 부분, 새로운 문자 'S', 그리고 마지막 부분을 결합
						key = start + 'S' + end;
					}
				}

				var url2 = url_view;
				url2 += '?cmd=DETAIL';
				url2 += '&page=' + $(this).getGridParam("page");
				url2 += '&returnUrl=' + getReturnUrl();
				url2 += '&menuId=' + '${param.menuId}';
				//검색값
				url2 += '&' + getSearchUrl();
				//key값
				url2 += '&eaiSvcName=' + key;
				goNav(url2);
			}
		});
		
	}
	
	$(document).ready(function() {

		init(list);
		
		resizeJqGridWidth('grid','content_middle','1000');
	
		$("#btn_search").click(function(){
			search();
		});
		$("#btn_new").click(function(){
			var url2 = url_view;
			url2 += '?cmd=DETAIL';
			url2 += '&page='+$("#grid").getGridParam("page");
			url2 += '&returnUrl='+getReturnUrl();
	        url2 += '&menuId='+'${param.menuId}';
			//검색값
	        url2 += '&'+getSearchUrl();
			//key값
	        url2 += '&eaiSvcName=';
			
	        goNav(url2);
		});
		
		$("input[name^=search]").keydown(function(key){
			if (key.keyCode == 13){
				$("#btn_search").click();
			}
		});
		
		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">
					<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" id="title" >${rmsMenuName}</div>
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th style="width:180px;">업무구분명</th>
							<td>
								<select name="searchEaiBzwkDstcd" value="${param.searchEaiBzwkDstcd}">
								</select>
							</td>
							<th style="width:180px;">IF서비스코드</th>
							<td>
								<input type="text" name="searchEaiSvcName" value="${param.searchEaiSvcName}">
							</td>
						</tr>
					</tbody>
				</table>
				<table id="grid" ></table>
				<div id="pager"></div>				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

