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

	function dateFormater(data){
		if (data==null|| data==undefined) return "";
		if (data.trim().length <16) return "";
		var display = "";
		display=display+data.substr(0,4)+"-";
		display=display+data.substr(4,2)+"-";
		display=display+data.substr(6,2)+" ";
	
		display=display+data.substr(8,2)+":";
		display=display+data.substr(10,2)+":";
		display=display+data.substr(12,2)+".";
		display=display+data.substr(14,2);
		return display;
	}	
	function init(msgDpstHMS,eaiSvcName){
		$.ajax({  
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'LIST_INIT_COMBO'},
			success:function(json){
				var inoutTypeData	= json.inoutTypeRows;
				new makeOptions("CODE","NAME").setObj($("select[name=eaiSevrDstcd]")).setNoValueInclude(true).setNoValue("", "<%= localeMessage.getString("combo.all")%>").setData(inoutTypeData).setFormat(codeName3OptionFormat).rendering();
				
				detail(msgDpstHMS,eaiSvcName);
				
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	}
	function detail( msgDpstHMS, eaiSvcName) {
		if (!isDetail)
			return;
		$.ajax({
			type : "POST",
			url : url,
			dataType : "json",
			data : {
				cmd : 'DETAIL',
				msgDpstHMS : msgDpstHMS,
				eaiSvcName : eaiSvcName
			},
			success : function(json) {
				var data = json;
				$("input").attr('readonly', true);
				
				$("#ajaxForm input[type!=radio],#ajaxForm select,#ajaxForm textarea").each(function(){
					var name = $(this).attr("name");
					var tag  = $(this).prop("tagName").toLowerCase();
					$(tag+"[name="+name+"]").val(data[name.toUpperCase()]);
				});
				$("input[name=msgDpstHMS]").val(dateFormater(msgDpstHMS));
				$("input[name=hdn_msgDpstHMS]").val(msgDpstHMS);
				
				//서비스코드 
				$("#eaiSvcName").html(
							"<span id='"+data["EAISVCNAME"]+"'>"+data["EAISVCNAME"]
							+'</span> <img src="<c:url value="/img/btn_show_xml.png" />" class="btn_img" name="eaiSvcName_xml"/>');
				//변환
				var cnvsnName = data["CNVSNNAME"].split(",");
				var loutName = data["LOUTNAME"].split(",");
				var cnvsnStr = "" ;
				var loutStr = "" ;
				for(var i=0; i<cnvsnName.length; i++){
					if(cnvsnName[i].trim().length>0){
						if(i==cnvsnName.length-1){
							cnvsnStr+="<span id='"+cnvsnName[i]+"'>"+cnvsnName[i];
							cnvsnStr+='</span> <img src="<c:url value="/img/btn_show_xml.png" />" class="btn_img" name="cnvsnName_xml"/> ';
						}else{
							cnvsnStr+="<span id='"+cnvsnName[i]+"'>"+cnvsnName[i];
							cnvsnStr+='</span> <img src="<c:url value="/img/btn_show_xml.png" />" class="btn_img" name="cnvsnName_xml"/><br>';
						}
					}
				}
				$("#cnvsnName").html(cnvsnStr);
				for(var i=0; i<loutName.length; i++){
					if(loutName[i].trim().length>0){
						if(i==loutName.length-1){
							loutStr+="<span id='"+loutName[i]+"'>"+loutName[i];
							loutStr+='</span> <img src="<c:url value="/img/btn_show_xml.png" />" class="btn_img" name="loutName_xml"/> ';
						}else{
							loutStr+="<span id='"+loutName[i]+"'>"+loutName[i];
							loutStr+='</span>  <img src="<c:url value="/img/btn_show_xml.png" />" class="btn_img" name="loutName_xml"/><br>';
						}
					}
				}
				$("#loutName").html(loutStr);
				
				$("img[name*=xml]").each(function(){
					$(this).css("width","65px");
				});
			},
			error : function(e) {
				alert(e.responseText);
			}
		});

	}
	$(document).ready(function() {
		var returnUrl = getReturnUrlForReturn();
		var msgDpstHMS = "${param.msgDpstHMS}";
		var eaiSvcName = "${param.eaiSvcName}";

		if ((msgDpstHMS != "" && msgDpstHMS != "null")||(eaiSvcName != "" && eaiSvcName != "null")) {
			isDetail = true;
		}

		init(msgDpstHMS,eaiSvcName);

		$("#btn_previous").click(function() {
			goNav(returnUrl);//LIST로 이동
		});
		
		$(document).on("click","img[name*=xml]",function(){
			var name = $(this).attr("name");
			var key = $(this).prev('span').attr('id');
			var url = '<c:url value="/common/acl/mmiLog/mmiLogMan.json" />';
			url += "?cmd=DETAIL_XML";
			url += '&msgDpstHMS='  +$("input[name=hdn_msgDpstHMS]").val();
			url += '&eaiSvcName=' +$("input[name=eaiSvcName]").val();
			url += '&type='+name.substr(0,name.indexOf("_xml"));
			url += '&key='+key;
			var showXml = windowOpen(url,"showXML",1200,800,",location=0,menubar=0,titlebar=0,toolbar=0,status=0,directories=0,resizable=no,scrollbars=yes");
			showXml.focus();
		});

		/* $(document).on("click","img[name*=xml]",function(){
			var name = $(this).attr("name");
			var key = $(this).prev('span').attr('id');
			$.ajax({  
				type : "POST",
				url:url,
				dataType:"json",
				data:{
					cmd : 'DETAIL_XML_VIEW',
					msgDpstHMS : $("input[name=msgDpstHMS]").val(),
					eaiSvcName : $("input[name=eaiSvcName]").val(),
					type : name.substr(0,name.indexOf("_xml")),
					key : key
				},
				success:function(json){
					$("img[name="+name+"]").parent().next('textarea').val(json.xmlData);
					$("img[name="+name+"]").parent().next('textarea').css("display","block");//inline-block ?
				},
				error:function(e){
					alert(e.responseText);
				}
			});
			
		}); */
	});
</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">
			<div class="search_wrap">
				<button type="button" class="cssbtn" id="btn_previous" level="R" status="DETAIL,NEW"><i class="material-icons">arrow_back</i> <%= localeMessage.getString("button.previous") %></button>
<%-- 				<img src="<c:url value="/img/btn_previous.png"/>" alt="" id="btn_previous" level="R" status="DETAIL,NEW"/> --%>
			</div>
			<div class="title"><%= localeMessage.getString("mmiLog.titleDetail")%></div>						
			<form id="ajaxForm">
				<table class="table_row" cellspacing="0">
					<tr>
						<th style="width:13%; min-width:130px;"><%= localeMessage.getString("mmiLog.eaiSvcName")%></th>
						<td colspan="3">
							<input type="hidden" name="eaiSvcName" style="width: 100%" />
							<span id="eaiSvcName">
							</span>
							<textarea name="eaiSvcName_xml" style="width: 100% ;height:240px; margin: 10px 0px 10px 0px; display : none;" ></textarea>
						</td>
					</tr>
					<tr>
						<th><%=localeMessage.getString("mmiLog.ifId")%></th>
						<td><input type="text" name="interfaceId" style="width: 100%" /></td>
						<th style="width:13%; min-width:130px;"><%= localeMessage.getString("mmiLog.disId")%></th>
						<td><input type="text" name="deployId" style="width: 100%" /></td>
					</tr>
					<tr>
						<th><%= localeMessage.getString("mmiLog.msgDpstHms")%></th>
						<td><input type="text" name="msgDpstHMS" style="width: 100%" /><input type="hidden" name="hdn_msgDpstHMS" style="width: 100%" /></td>
						<th><%= localeMessage.getString("mmiLog.eaiSvrDstcd")%></th>
						<td><div class="select-style"><select name="eaiSevrDstcd" value="${param.eaiSevrDstcd}"disabled></select></div></td>
					</tr>
					<tr>
						<th><%= localeMessage.getString("mmiLog.cnvsnName")%></th>
						<td>
							<span id="cnvsnName"></span>
							<input type="hidden" name="cnvsnName" style="width: 100%" />
						</td>
						<th><%= localeMessage.getString("mmiLog.loutName")%></th>
						<td>
							<span id="loutName"></span>
							<input type="hidden" name="loutName" style="width: 100%" />
						</td>
					</tr>
					<tr>
						<th>
							<%= localeMessage.getString("mmiLog.reqDesc")%>
						</th>
						<td colspan="3">
							<textarea name="reqDstcd" style="width: 100% ;height:240px; margin: 10px 0px 10px 0px;" ></textarea>
						</td>
					</tr>
					<tr>
						<th>
							<%= localeMessage.getString("mmiLog.resDesc")%>
							<%-- <img id="btn_xml2" src="<c:url value="/img/btn_show_xml.png" />" class="btn_img"/> --%>
						</th>
						<td colspan="3">
							<textarea name="resDstcd" style="width: 100%;height:200px; margin: 10px 0px 10px 0px;" ></textarea>
						</td>
					</tr>
				</table>
			</form>
		</div><!-- end content_middle -->
	</div><!-- end right_box -->
</body>
</html>