<%@ 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"/>
<script language="javascript" >
var url      = '<c:url value="/onl/admin/common/inboundErrorInfoMan.json" />';
var url_view = '<c:url value="/onl/admin/common/inboundErrorInfoMan.view" />';
var selectName = "searchAdptrBzwkGroupName";	// selectBox Name

function getStartTime(){
	var now = new Date();
	var tm = right("0" + now.getHours(), 2);
	tm += right("0" + now.getMinutes(), 2);

	tm = (Math.floor(tm.substr(0, 2)) * 60) + Math.floor(right(tm, 2)) - 5;
	tm = right("0" + parseInt(tm/60), 2) + right("0" + tm%60, 2);
	return tm + '00';	
}
function getEndTime(){
	var now = new Date();
	var tm = right("0" + now.getHours(), 2);
	tm += right("0" + now.getMinutes(), 2);
	return tm + '59';
}

function init(callback) {
	$.ajax({
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=searchAdptrBzwkGroupName]")).setNoValueInclude(true).setNoValue("", "전체").setData(json.adapterList).setFormat(codeName3OptionFormat).rendering();
			putSelectFromParam();
			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 ,datatype:'json' }).trigger("reloadGrid");
}
function search(){
	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=searchStartDate]").val(start);
	$("input[name=searchEndDate]").val(end);
	
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$("#grid").setGridParam({ url:url,postData: postData ,datatype:'json',page:1 }).trigger("reloadGrid");
}
$(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});
	
	$("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(getStartTime());
		}
	});
	$("input[name=searchEndHHMM]").each(function(){
		if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
			$(this).val(getEndTime());
		}
	});
	
	
	init(search);
	$('#grid').jqGrid({
		datatype:"local",
		mtype: 'POST',
		//url: url,
		//postData : gridPostData,
		colNames:['<%= localeMessage.getString("inboundError.serno") %>',
				  '<%= localeMessage.getString("inboundError.bizKey") %>',
				  '<%= localeMessage.getString("inboundError.eaiSvcName") %>',
                  '<%= localeMessage.getString("inboundError.adapter") %>',
                  '<%= localeMessage.getString("inboundError.errorsection") %>',
                  '<%= localeMessage.getString("inboundError.errorCode") %>',
                  '<%= localeMessage.getString("inboundError.occurhms") %>',
                  '<%= localeMessage.getString("inboundError.instncName") %>'
                  ],
		colModel:[
				{ name : 'EAISVCSERNO'        , align:'left', sortable:false },
				{ name : 'BZWKSVCKEYNAME'     , align:'left' , width:"50px" },
				{ name : 'EAISVCNAME' 		  , align:'left' , width:"100px" },
				{ name : 'ADPTRBZWKGROUPNAME' , align:'left' , width:"100px" },
				{ name : 'EAIERRDSTCD'        , align:'left' , width:"50px" },
				{ name : 'EAIERRCD'           , align:'left' , width:"50px" },
				{ name : 'ERROCCURHMS'        , align:'left' , width:"100px" ,formatter: timeStampFormat},
				{ name : 'EAISEVRINSTNCNAME'  , align:'left' , width:"100px" }
				],
        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){
		},
  		
		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 += '&eaiSvcSerno='+rowData['EAISVCSERNO']; 
            goNav(url2);
        },
 		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});			
			}
		
		},	       
        loadError: function(jqXHR, textStatus, errorThrown){
        	//alert(JSON.parse(xhr.responseText).errorMsg);
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        }		
	});
	
	
	resizeJqGridWidth('grid','content_middle','10000');

	$("#btn_search").click(function(){
		search();
	});
	
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			search();
		}
	});
	
	//검색조건 달력
	$("#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_search" level="R" ><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %></button>		
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" /> --%>
				</div>
				<div class="title"><%= localeMessage.getString("inboundError.title") %></div>
				
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th style="width:100px;"><%= localeMessage.getString("inboundError.search1") %></th>							
							<td style="width:400px;">
								<input type="text" name="searchStartYYYYMMDD" id="startDatepicker" readonly="readonly" value="" size="10" style="width:80px; border:1px solid #ebebec;">
								<input type="text" name="searchStartHHMM" value="" size="8" style="width:80px; border:1px solid #ebebec;">
								~ 
								<input type="text" name="searchEndYYYYMMDD" value="" id="endDatepicker" size="10" readonly="readonly" style="width:80px; border:1px solid #ebebec;">
								<input type="text" name="searchEndHHMM" value="" size="8" style="width:80px; border:1px solid #ebebec;">
								<input type="hidden" name="searchStartDate" value="" style="width:0px;">
								<input type="hidden" name="searchEndDate" value="" style="width:0px;">
							</td>
							<th style="width:100px;"><%= localeMessage.getString("inboundError.errorsection") %></th>
							<td><input type="text" name="searchEaiErrDstcd" value="${param.searchEaiErrDstcd}" maxlength=2></td>
							<th style="width:100px;"><%= localeMessage.getString("inboundError.instncName") %></th>
							<td><input type="text" name="searchEaiSevrInstncName" value="${param.searchEaiSevrInstncName}"></td>							
						</tr>
						<tr>
							<th><%= localeMessage.getString("inboundError.adapter") %></th>
							<td>
								<div style="position: relative; width: 100%;">
									<div class="select-style">	
										<select name="searchAdptrBzwkGroupName" value="${param.searchAdptrBzwkGroupName}">
										</select>	
									</div><!-- end.select-style -->	
								</div>
							</td>
							<th><%= localeMessage.getString("eaiMessage.eaiSvcName") %></th>
							<td><input type="text" name="searchEaiSvcName" value="${param.searchEaiSvcName}"></td>
							<th><%= localeMessage.getString("inboundError.errorCode") %></th>
							<td><input type="text" name="searchEaiErrCd" value="${param.searchEaiErrCd}"></td>
						</tr>
						<!-- // 필요없음 
						<tr>
							<th style="width:130px;"><%= localeMessage.getString("inboundError.serno") %></th>
							<td><input type="text" name="searchEaiSvcSerno" value="${param.searchEaiSvcSerno}"></td>
							<th style="width:130px;"></th>
							<td></td>
						</tr>
						 -->
					</tbody>
				</table>
				
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

