<%@ 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" />';
var url_excel= '<c:url value="/common/acl/mmiLog/mmiLogMan.excel" />';

function detail(_page){
	var page = "${param.page}";
	if(_page == "1") page = "1";
	var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"");
	start = start + $("input[name=searchStartHHMM]").val();
	
	var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"");
	end = end + $("input[name=searchEndHHMM]").val();
	
	if(start > end){
		alert("조회기간을 확인해주세요.");
		return false;
	}
	
	$("input[name=searchStartTime]").val(start);
	$("input[name=searchEndTime]").val(end);
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
	$("#grid").setGridParam({ url:url,postData: postData ,datatype:'json',page : page }).trigger("reloadGrid");
}
function init(callback){
	$.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=searchEaiSevrDstcd]")).setNoValueInclude(true).setNoValue("", "<%= localeMessage.getString("combo.all")%>").setData(inoutTypeData).setFormat(codeName3OptionFormat).rendering();
			
			if (typeof callback === 'function') {
				callback();
			}
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}
function dateFormater(cellvalue, options, rowObject){
	if (cellvalue==null|| cellvalue==undefined) return "";
	if (cellvalue.trim().length <16) return "";
	var display = "";
	display=display+cellvalue.substr(0,4)+"-";
	display=display+cellvalue.substr(4,2)+"-";
	display=display+cellvalue.substr(6,2)+" ";

	display=display+cellvalue.substr(8,2)+":";
	display=display+cellvalue.substr(10,2)+":";
	display=display+cellvalue.substr(12,2)+".";
	display=display+cellvalue.substr(14,2);
	
	return display;
}	

$(document).ready(function() {	
	$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").inputmask("yyyy-mm-dd",{'autoUnmask':true});
	$("input[name=searchStartHHMM],input[name=searchEndHHMM]").inputmask("hh:mm:ss",{'autoUnmask':true});
	
	if(!("${param.searchStartTime}"&&"${param.searchEndTime}")) {
		$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").each(function(){
			if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
				$(this).val(getToday());
			}
		});
		$("input[name=searchStartHHMM]").each(function(){
			if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
				$(this).val("00000000");
			}
		});
		$("input[name=searchEndHHMM]").each(function(){
			if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
				$(this).val("23595959");
			}
		});
		$("input[name=searchStartTime]").val(getToday()+'00000000');
		$("input[name=searchEndTime]").val(getToday()+'23595959');
	}else{
		$("input[name=searchStartYYYYMMDD]").val("${param.searchStartYYYYMMDD}");
		$("input[name=searchEndYYYYMMDD]").val("${param.searchEndYYYYMMDD}");
		$("input[name=searchStartHHMM]").val("${param.searchStartHHMM}");
		$("input[name=searchEndHHMM]").val("${param.searchEndHHMM}");
		$("input[name=searchStartTime]").val("${param.searchStartTime}");
		$("input[name=searchEndTime]").val("${param.searchEndTime}");
	}
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,
		colNames:[
					'<%= localeMessage.getString("mmiLog.msgDpstHms")%>',
					'<%= localeMessage.getString("mmiLog.msgDpstHms")%>',
					'<%= localeMessage.getString("mmiLog.ifId")%>',
					'<%= localeMessage.getString("mmiLog.eaiSvcName")%>',
					'<%= localeMessage.getString("mmiLog.eaiSvrDstcd")%>',
					'<%= localeMessage.getString("mmiLog.cnvsnName")%>',
					'<%= localeMessage.getString("mmiLog.loutName")%>',
					'<%= localeMessage.getString("mmiLog.disId")%>',
					'<%= localeMessage.getString("mmiLog.DepResu")%>'
                  ],
		colModel:[
				{ name : 'MSGDPSTHMS' 	, align:'left'	,width:"50"	,sortable:false ,formatter : dateFormater },
				{ name : 'MSGDPSTHMS' 	, align:'left'	,hidden : true },
				{ name : 'INTERFACEID' 	, align:'left'	,width:"50"},
				{ name : 'EAISVCNAME' 	, align:'left'	,width:"50"},
				{ name : 'EAISEVRDSTCD' , align:'left'	,width:"30" },
				{ name : 'CNVSNNAME' 	, align:'left'	,width:"80"},
				{ name : 'LOUTNAME' 	, align:'left'	},
				{ name : 'DEPLOYID' 	, align:'left'	,width:"20"},
				{ name : 'RETURNCD' 	, align:'left'	,width:"20"}
				],
        jsonReader: {
             repeatitems:false
        },	          
        pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		rowList : eval('[${rmsDefaultRowList}]'),
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
		},			
		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 += '&'+getSearchUrl();
            //key값
            url2 += '&msgDpstHMS='+rowData['MSGDPSTHMS'];
            url2 += '&eaiSvcName='+rowData['EAISVCNAME'];
            
            goNav(url2);
        },loadError: function (jqXHR, textStatus, errorThrown) {
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
    	}		
	});
	init(detail);
	
	resizeJqGridWidth('grid','content_middle','1000');

	$("#btn_search").click(function(){
		detail();
	});

	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	$("#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)
		gridToExcelSubmit2(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'mmi');
		return false;
	});

	$("#startDatepicker").datepicker();
	$("#endDatepicker").datepicker();
	
	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">
					<button type="button" class="cssbtn" id="btn_excel" level="W"><i class="material-icons">table_view</i> <%= localeMessage.getString("button.excel") %></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="W"/> --%>
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />	 --%>
				</div>
				<div class="title"><%= localeMessage.getString("mmiLog.title")%></div>
				<form id="ajaxForm"  onsubmit="return false;">
					<table class="search_condition" cellspacing=0;>
						<tbody>
							<tr>
								<th class="search_td_title" style="width:10%; min-width:100px;"><%= localeMessage.getString("mmiLog.msgDpstHms")%></th>
								<td colspan="3" style="width:25%">
									<input type="text" name="searchStartYYYYMMDD" id="startDatepicker" value="${param.searchStartYYYYMMDD }" 
										readonly="readonly" size="10" style="width:80px;"> 
									<input type="text" name="searchStartHHMM" value="" size="8" style="width:70px;" value="${param.searchStartHHMM }" >
									~<input type="text" name="searchEndYYYYMMDD" id="endDatepicker" value="${param.searchEndYYYYMMDD }"
										size="10" readonly="readonly" style="width:80px;">
									<input type="text" name="searchEndHHMM" value="" size="8" style="width:70px;" value="${param.searchEndHHMM }" >
									<input type="hidden" name="searchStartTime" value="20170202000000">
									<input type="hidden" name="searchEndTime" value="20170202235959">
								</td>
								<th class="search_td_title" style="width:10%; min-width:95px;"><%=localeMessage.getString("mmiLog.ifId")%></th>
								<td><input type="text" name="searchInterfaceId" value="${param.searchInterfaceId}"></td>
								<th class="search_td_title" style="width:10%; min-width:110px;"><%= localeMessage.getString("mmiLog.loutName")%></th>
								<td><input type="text" name="searchLoutName" value="${param.searchLoutName}"></td>
							</tr>
							<tr>
								<th class="search_td_title" ><%= localeMessage.getString("mmiLog.eaiSvrDstcd")%></th>
								<td style="width:7%; min-width:70px;">
									<div class="select-style">
										<select name="searchEaiSevrDstcd" value="${param.searchEaiSevrDstcd}">
										</select>
									</div>
								</td>
								<th class="search_td_title" style="width:7%; min-width:70px;"><%=localeMessage.getString("mmiLog.disId")%></th>
								<td style="width:10%; min-width:100px;"><input type="text" name="searchDeployId" value="${param.searchDeployId}"></td>
								<th class="search_td_title"><%= localeMessage.getString("mmiLog.cnvsnName")%></th>
								<td><input type="text" name="searchCnvsnName" value="${param.searchCnvsnName}"></td>
								<th class="search_td_title"><%= localeMessage.getString("mmiLog.eaiSvcName")%></th>
								<td><input type="text" name="searchEaiSvcName" value="${param.searchEaiSvcName}"></td>
							</tr>							
						</tbody>
					</table>
				</form>
				<table id="grid" width="100%"></table>
				<div id="pager"></div>				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->
	</body>	
</html>