<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*,javax.sql.*,javax.naming.*,java.text.*,com.eactive.eai.rms.onl.common.util.*,com.eactive.eai.rms.common.datasource.*,com.eactive.eai.rms.common.util.CommonUtil"%>
<%@ page import="com.eactive.eai.rms.common.context.MonitoringContext"%>
<%@ 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 type="text/javascript">
var url      = '<c:url value="/onl/transaction/tracking/cmResultMan.json" />';
var url_view = '<c:url value="/onl/transaction/tracking/cmResultMan.view" />';

var cmPath = "/fscm/iomap/";
var hpPath = "/fslog/eai/iocm";
var resPath = "/fslog/eai/dynamiclog/IoMapLoaderController/";

var pkgArr = new Array();
$(document).ready(function() {
	
	$('#cmgrid').jqGrid({
		datatype:'json',
	    loadui: "disable",
	    mtype: 'POST',
		colNames : [
					'서버구분코드', 
					'타입', 
					'파일명',
					'FILEPATH'
					],
		colModel : [				
					{ name : 'SVRDSTCD'    , align:'left'  , width:'200'},
		   	    	{ name : "TYPE"},
			    	{ name : 'FILENAME'    , align:'left'  , width:'200'},
			    	{ name : 'FILEPATH'    , hidden:true}
				   ],
		jsonReader: {
			root : "cmList",
            repeatitems:false
        },
        rowNum : 10000,
        width: '540',
		height: '150',
		viewrecords: true,
		loadError: function(jqXHR, textStatus, errorThrown){
			if(jqXHR.status == 401) {
 	    		alert('HTTP status code: ' + jqXHR.status + '\n' +
 	                    '에러:  세션이 종료되었습니다. ');
 	    		parent.location.href='<%=request.getContextPath()%>/';	
 	    	}
        },
		
		gridComplete:function (d){
		
		},
        ondblClickRow: function(rowId) {			
			var rowData = $(this).getRowData(rowId);
			fileView(rowData.FILENAME, 'cmgrid');
        },
        onSelectRow : function(rowId){
        	var rowData = $(this).getRowData(rowId);
        	$("input[name=cmgridPath]").val(rowData['FILEPATH']);
        }
	});
	//HTTP 전송로그 GRID
	$('#hpgrid').jqGrid({
		datatype:'json',
	    loadui: "disable",
	    mtype: 'POST',
		colNames : [
					'파일명',
					'FILEPATH'
					],
		colModel : [				
		    	{ name : 'FILENAME'    , align:'left'  , width:'200'},
		    	{ name : 'FILEPATH'    , hidden:true}
				],
		jsonReader: {
			root : "cmList",
            repeatitems:false
        },
        rowNum : 10000,
        width: '530',
		height: '150',		
		viewrecords: true,
		
		loadComplete: function(data) { // JqGrid 조회 후 한번만 실행. (화면 초기 셋팅 사용.)
			
		},
		loadError: function(jqXHR, textStatus, errorThrown){
			if(jqXHR.status == 401) {
 	    		alert('HTTP status code: ' + jqXHR.status + '\n' +
 	                    '에러:  세션이 종료되었습니다. ');
 	    		parent.location.href='<%=request.getContextPath()%>/';	
 	    	}
        },
		
		gridComplete:function (d){

		},
        ondblClickRow: function(rowId) {			
			var rowData = $(this).getRowData(rowId);
			fileView(rowData.FILENAME, 'hpgrid');
        },
        onSelectRow : function(rowId){
        	var rowData = $(this).getRowData(rowId);
        	$("input[name=hpgridPath]").val(rowData['FILEPATH']);
        }
	});
	
	//결과 로그 GRID
	$('#regrid').jqGrid({
		datatype:'json',
	    loadui: "disable",
	    mtype: 'POST',
		colNames : [
					'파일명',
					'FILEPATH'
					],
		colModel : [				
				{ name : 'FILENAME'    , align:'left'  , width:'200'},
		    	{ name : 'FILEPATH'    , hidden:true}
				],
		jsonReader: {
			root : "cmList",
            repeatitems:false
        },
        rowNum : 10000,
        width: '540',
		height: '150',
		viewrecords: true,
		
		loadError: function(jqXHR, textStatus, errorThrown){
			if(jqXHR.status == 401) {
 	    		alert('HTTP status code: ' + jqXHR.status + '\n' +
 	                    '에러:  세션이 종료되었습니다. ');
 	    		parent.location.href='<%=request.getContextPath()%>/';	
 	    	}
        },
		
		gridComplete:function (d){
		},
		ondblClickRow: function(rowId) {			
			var rowData = $(this).getRowData(rowId);
			fileView(rowData.FILENAME, 'regrid');
        },
        onSelectRow : function(rowId){
        	var rowData = $(this).getRowData(rowId);
        	$("input[name=regridPath]").val(rowData['FILEPATH']);
        }
	});
	
	$("#bzwkDstcd").change(function(){
		$("#pkgName").empty();
		for(var i=0; i<pkgArr.length; i++){
			var val1 = $("#bzwkDstcd").val();
			var val2 = pkgArr[i].dir;
			var pkgDir = pkgArr[i].pkgDir;
			if(val1==val2){
				for(var j=0; j<pkgDir.length; j++){
					var option = $("<option>"+pkgDir[j]+"</option>");
					$("#pkgName").append(option);
				}
				break;
			}
		}
		
	});
	$("#btn_search").click(function(){
		$("input[name=cmgridPath]").val(cmPath);
		$("input[name=hpgridPath]").val(hpPath);
		$("input[name=regridPath]").val(resPath);
		$("textarea[name=cmgrid]").text('');
		$("textarea[name=hpgrid]").text('');
		$("textarea[name=regrid]").text('');
		var cmPathTmp = cmPath + $("#bzwkDstcd").val()+"/";
		
		$("#cmgrid").setGridParam( {url :url ,postData: { cmd : 'LIST', mode: "cmFile", logPath: cmPathTmp, pkgName : $("#pkgName").val() } }).trigger("reloadGrid");
		$("#hpgrid").setGridParam( {url :url ,postData: { cmd : 'LIST', mode: "httpLog", logPath: hpPath, pkgName : $("#pkgName").val() } }).trigger("reloadGrid");
		$("#regrid").setGridParam( {url :url ,postData: { cmd : 'LIST', mode: "procRes", logPath: resPath, pkgName : $("#pkgName").val() } }).trigger("reloadGrid");
	});
	init();
	buttonControl();

});

function init(){
	
	var postData = new Array();
	postData.push({ name: "cmd"        , value:"LIST_INIT_COMBO"});
	postData.push({ name: "filePath"   , value:"/fscm/iomap/"});
	
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data: postData,
		success:function(json){
			var bzwkDstcd = json.dirList;
			for(var i=0; i<bzwkDstcd.length; i++){
				var option = $("<option>"+bzwkDstcd[i]+"</option>");
				$("select[name=searchBzwkDstcd]").append(option);
			}
			pkgArr = json.pkgList;
			$("#bzwkDstcd").change();
			
			var cmPathTmp = cmPath + $("#bzwkDstcd").val()+"/";
			$("#cmgrid").setGridParam( {url :url ,postData: { cmd : 'LIST', mode: "cmFile", logPath: cmPathTmp, pkgName : $("#pkgName").val() } }).trigger("reloadGrid");
			$("#hpgrid").setGridParam( {url :url ,postData: { cmd : 'LIST', mode: "httpLog", logPath: hpPath, pkgName : $("#pkgName").val() } }).trigger("reloadGrid");
			$("#regrid").setGridParam( {url :url ,postData: { cmd : 'LIST', mode: "procRes", logPath: resPath, pkgName : $("#pkgName").val() } }).trigger("reloadGrid");
		},
		error:function(e){
			alert(e.responseText);
		}
	});	
}

function fileView(f,g){
	
	var logPath = $("input[name="+g+"Path]").val();
	
	var postData = new Array();
	postData.push({ name: "cmd" , value:"DETAIL"});
	postData.push({ name: "logPath" , value:logPath});
	
	$.ajax({
		type : "POST",
		url: url,
		dataType:"json",
		data:postData,
		success:function(json){
			$("textarea[name="+g+"]").text(json.fileView);
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}

</script>

<style type="text/css">
.gridtitle { display:block; text-align:left; font-size: 10pt; font-weight: bold; }
</style>

</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_search.png"/>" alt="" id="btn_search" level="R" />				
		</div>
		<div class="title">CM 결과조회</div>
		<form id="ajaxForm"  onsubmit="return false;">
			<table class="search_condition" cellspacing=0;>
				<tbody>
					<tr>
						<th style="width:180px;">업무코드</th>
						<td>
							<div class="select-style">
								<select id="bzwkDstcd" name = "searchBzwkDstcd"></select>
							</div>
						</td>
						<th style="width:180px;">패키지명</th>
						<td>
							<div class="select-style">
								<select id = "pkgName" name = "searchPkgName"></select>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</form>	
		
		<div style="font-size:0;">
		<div style="display:inline-block; width:calc(34% - 20px); vertical-align:top;">
			<div id="grid1" >
				<span class="gridtitle">CM 대상파일</span>
				<table id="cmgrid" ></table>
			</div>
			<table class="table_row" style="margin-top:10px;">
				<tr>
					<th style="width:30px">파일<br>경로</th>
					<td><input type="text" name="cmgridPath" value="/fscm/iomap/" readonly></td>
				</tr>
				<tr>
					<th style="width:30px">파일<br>내용</th>
					<td><textarea name="cmgrid" style="width:100%;height:400px"></textarea></td>
				</tr>				
			</table>
		</div>
		
		<div style="display:inline-block; width:15px;"></div>			
		
		<div style="display:inline-block; width:calc(33% - 20px); vertical-align:top;">
			<div id="grid2">
				<span class="gridtitle">HTTP전송로그</span>
				<table id="hpgrid" ></table>
			</div>
			<table class="table_row" style="margin-top:10px;">
				<tr>
					<th style="width:30px">파일<br>경로</th>
					<td><input type="text" name="hpgridPath" value="/fslog/eai/iocm/" readonly></td>
				</tr>
				<tr>
					<th style="width:30px">파일<br>내용</th>
					<td><textarea name="hpgrid" style="width:100%;height:400px"></textarea></td>
				</tr>				
			</table>
		</div>
		
		<div style="display:inline-block; width:15px;"></div>
		
		<div style="display:inline-block; width:calc(34% - 20px); vertical-align:top;">
			<div id="grid3">
				<span class="gridtitle">처리결과</span>
				<table id="regrid" ></table>
			</div>
			<table class="table_row" style="margin-top:10px;">
				<tr>
					<th style="width:30px">파일<br>경로</th>
					<td><input type="text" name="regridPath" value="/fslog/eai/dynamiclog/IoMapLoaderController/" readonly></td>
				</tr>
				<tr>
					<th style="width:30px">파일<br>내용</th>
					<td><textarea name="regrid" style="width:100%;height:400px" ></textarea></td>
				</tr>				
		</table>
		</div>
		</div>
	</div><!-- end content_middle -->
</div><!-- end right_box -->				
</body>
</html>