<%@ 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"/>
<style type="text/css">
.ui-jqgrid-hbox, .ui-jqgrid-bdiv { overflow-x: hidden; }
.cmtable_wrapper { display: flex; justify-content: center; }
.cmtable { width: 100%; }
.cmtable .tdlabel { width: 150px; vertical-align: top; text-align: center; }
.cmtable .label { background-color: lightgray; font-size: 10pt; font-weight: bold; margin-right: 10px; text-align: center; }
.cmtable .count { display:inline-block; }
</style>
<script type="text/javascript">
var gridwidth = '250'
var gridheight = '220'
var flag = window.dialogArguments['flag'];
var fileName = window.dialogArguments['fileName'];
$(document).ready(function() {
	
	$('#grid1').jqGrid({
		datatype : "local",
		colNames : [ '어댑터' ],
		colModel : [ { name: 'CODE', align: 'center' } ],
		jsonReader : {
			repeatitems : false
		},
		rowNum: 10000,
		width: gridwidth,
		height: gridheight,
		beforeSelectRow: function(rowId, e) {
			$(this).jqGrid('resetSelection');
		}
	});
	
	$('#grid2').jqGrid({
		datatype : "local",
		colNames : [ 'B2B서비스' ],
		colModel : [ { name: 'CODE', align: 'center' } ],
		jsonReader : {
			repeatitems : false
		},
		rowNum: 10000,
		width: gridwidth,
		height: '90',
		beforeSelectRow: function(rowId, e) {
			$(this).jqGrid('resetSelection');
		}
	});
	
	$('#grid3').jqGrid({
		datatype : "local",
		colNames : [ 'C2R서비스' ],
		colModel : [ { name: 'CODE', align: 'center' } ],
		jsonReader : {
			repeatitems : false
		},
		rowNum: 10000,
		width: gridwidth,
		height: '90',
		beforeSelectRow: function(rowId, e) {
			$(this).jqGrid('resetSelection');
		}
	});
	
	$('#grid4').jqGrid({
		datatype : "local",
		colNames : [ 'B2B라우팅' ],
		colModel : [ { name: 'CODE', align: 'center' } ],
		jsonReader : {
			repeatitems : false
		},
		rowNum: 10000,
		width: gridwidth,
		height: '90',
		beforeSelectRow: function(rowId, e) {
			$(this).jqGrid('resetSelection');
		}
	});
	
	$('#btn_close').click(function(){
		window.close();
	});
	
	init();
});

function init() {
	
	var postData = new Array();
	postData.push({ name: "cmd"      , value:(flag == 'FTP' ? 'DETAIL_FTP_FILE' : 'DETAIL_LOCAL_FILE')});
	postData.push({ name: "fileName"   , value:fileName});
	
	$.ajax({  
		dataType:"json",
		type : "POST",
		url  : '<c:url value="/onl/admin/service/eaiMsgCmFtp.json" />',
		data : postData,
		success:function(json) {
			
			var o = json.Detail;
			
			$('#grid1').jqGrid('setGridParam', { data: o.AdapterGroupName }).trigger('reloadGrid');
			$('#grid2').jqGrid('setGridParam', { data: o.B2BSvc }).trigger('reloadGrid');
			$('#grid3').jqGrid('setGridParam', { data: o.C2RSvc }).trigger('reloadGrid');
			$('#grid4').jqGrid('setGridParam', { data: o.B2BExt }).trigger('reloadGrid');
			
			$('#cnt1').html((o.AdapterGroupName)?o.AdapterGroupName.length:0);
			$('#cnt2').html((o.B2BSvc)?o.B2BSvc.length:0);
			$('#cnt3').html((o.C2RSvc)?o.C2RSvc.length:0);
			$('#cnt4').html((o.B2BExt)?o.B2BExt.length:0);
			
		},
		error:function(xhr,status,error){
			if (xhr.responseText != null) {
				try {
					alert(JSON.parse(xhr.responseText).errorMsg);	
				} catch (e) {
					alert(error);
				}
			}
		}
	});
}

</script>
</head>
	<body>
		<div class="popup_box">
			<div class="search_wrap">
				<img src="<c:url value="/img/btn_close.png"/>" alt="" id="btn_close" level="R" status="DETAIL,NEW"/>	
			</div>
			<div class="title">CM자원 상세내역</div>
			<div class="cmtable_wrapper">
				<form id="ajaxForm">
					<table class="cmtable">
						<tr>
							<td class="tdlabel">
								<div class="label">어댑터</div>
								<span class="count">총:&nbsp;&nbsp;<span id="cnt1">0</span>&nbsp;개</span>
							</td>
							<td>
								<table id="grid1"></table>
							</td>
						</tr>
						<tr style="height: 10px;"></tr>
						<tr style="height:220px;">
							<td class="tdlabel">
								<ul>
									<li style="height:120px;">
										<div class="label">B2B서비스</div>
										<span class="count">총:&nbsp;&nbsp;<span id="cnt2">0</span>&nbsp;개</span>
									</li>
									<li style="height:10px;"></li>
									<li style="height:120px;">
										<div class="label">C2R서비스</div>
										<span class="count">총:&nbsp;&nbsp;<span id="cnt3">0</span>&nbsp;개</span>
									</li>
									<li style="height:10px;"></li>
									<li>
										<div class="label">B2B라우팅</div>
										<span class="count">총:&nbsp;&nbsp;<span id="cnt4">0</span>&nbsp;개</span>
									</li>
								</ul>
							</td>
							<td style="vertical-align:top;">
								<ul>
									<li>
										<table id="grid2"></table>
									</li>
									<li style="height:10px;"></li>
									<li>
										<table id="grid3"></table>
									</li>
									<li style="height:10px;"></li>
									<li>
										<table id="grid4"></table>
									</li>
								</ul>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</body>
</html>