<%@ 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="/onl/admin/service/routingEaiMsgMan.json" />';
var url_view = '<c:url value="/onl/admin/service/routingEaiMsgMan.view" />';
var url_excel= '<c:url value="/onl/admin/service/routingEaiMsgMan.excel"/>';

function init(callback){
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT' , codeGroupArr : 'RESPONSE_TYPE'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=searchEaiSevrInstncName]")).setNoValueInclude(true).setNoValue("", "<%=localeMessage.getString("combo.all")%>").setData(json.instanceRows).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=searchSvcMotivUsedStcd]")).setNoValueInclude(true).setNoValue("", "<%=localeMessage.getString("combo.all")%>").setData(json.list).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=searchPsvIntfaCdSticName]")).setNoValueInclude(true).setNoValue("", "<%=localeMessage.getString("combo.all")%>").setData(json.list).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=searchFlowCtrlRoutName]")).setNoValueInclude(true).setNoValue("", "<%=localeMessage.getString("combo.all")%>").setData(json.listFlowControl).rendering();
			putSelectFromParam();
			if(typeof callback === 'function') {
				callback();
    		}
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}
function detail(){
	var baseYmd = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"");
	$("input[name=searchBaseYmd]").val(baseYmd);
	
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$("#grid").setGridParam({ url:url, postData: postData, datatype:"json" }).trigger("reloadGrid");
} 

$(document).ready(function() {	

	var date1 =new Date();
	var dateT = date1.getDay();
	
	var dayVal = 1; 
	
    if(dateT == 0){ //일요일
    	dayVal = 2;
    }else if(dateT == 1){ //월요일
    	dayVal = 3;
    }
	
	//전일 평일로 셋팅
	$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").inputmask("yyyy-mm-dd",{'autoUnmask':true});
	$("input[name=searchStartYYYYMMDD]").each(function(){
		
		if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
			$(this).val(getBeforeDay(dayVal));
		}
		
	});
	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
	
	var auth="${rmsMenuAuth}";
	gridPostData["rmsMenuAuth"]= auth;
	
	init();

	$('#grid').jqGrid({
		datatype:"json",
// 		mtype: 'POST',
// 		url: url,
		postData : gridPostData,
		colNames:['Flow control',
				  '<%= localeMessage.getString("routingEaiservice.routingNm")%>',	
                  '<%= localeMessage.getString("routingEaiservice.eaisevrinstncname")%>',
                  '<%= localeMessage.getString("routingEaiservice.eaisvcname")%>',
                  '<%= localeMessage.getString("routingEaiservice.eaibzwkdstcd")%>',
                  '<%= localeMessage.getString("routingEaiservice.svcmotivusedstcd")%>',
                  '<%= localeMessage.getString("routingEaiservice.psvintfacdsticname")%>',
                  '<%= localeMessage.getString("routingEaiservice.trancount")%>'
                  ],
		colModel:[
				{ name : 'FLOWCTRLROUTNAME'  	, align:'left'	 , width:50  },
				{ name : 'NONMOTIVROUTURINAME'  , align:'left'	 },
				{ name : 'EAISEVRINSTNCNAME'	, align:'center' , width:50  },
				{ name : 'EAISVCNAME'			, align:'left' , width:50  },
				{ name : 'EAIBZWKDSTCD'			, align:'center' , width:50  },
				{ name : 'SVCMOTIVUSEDSTCD' 	, align:'center' , width:40  },
				{ name : 'PSVINTFACDSTICNAME'   , align:'center' , width:40  },
				{ name : 'TOT'   				, align:'right' , width:40 ,formatter: 'integer' ,formatoptions:{thousandsSeparator:","}}
				
				],
        jsonReader: {
             repeatitems:false
        },	          
		rowNum : 10000,
	    //autoheight: true,
	    height : '550',
		autowidth: true,
		viewrecords: true,
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
		},			
		loadComplete:function (d){
		},
	  	loadBeforeSend : function (xhr,settings){
			if(this.p.url ==null || this.p.url == ""){
				this.p.loadBeforeSend = null;
				return false;
			}
		},
        loadError: function (jqXHR, textStatus, errorThrown) {
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	},		
		ondblClickRow: function(rowId) {
			
        }		
	});
	
	
	resizeJqGridWidth('grid','content_middle','1000');

	$("#btn_search").click(function(){
		var cnt = 0;
		//검색조건이 한개이상이어야함
		$("#search select,#search input").each(function(){
			var name = $(this).attr('name');
			if( (name != "searchStartYYYYMMDD" && name != "searchBaseYmd") && $(this).val() != ""){
				cnt++;
			}
		});
		
		if(cnt < 1 ) {
			alert('<%= localeMessage.getString("routingEaiservice.msg")%>');
			return;
		}else{
			detail();
		}
		
	});
	//검색값  enter시  조회
	$("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)
		gridJsonToExcelSubmit2(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'라우팅별 서비스');
		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("routingEaiservice.title")%></div>
				&nbsp;<span style="color:black;"> ※ <%= localeMessage.getString("routingEaiservice.comment")%></span>
				<form id="ajaxForm"  onsubmit="return false;">
				<table class="search_condition" id="search" cellspacing=0;>
					<tbody>
						<tr>
							<th style="width:10%; min-width:120px;"><%= localeMessage.getString("routingEaiservice.period")%></th>
							<td style="width:40%">
								<input type="text" name="searchStartYYYYMMDD" id="startDatepicker" readonly="readonly" value="" size="10" style="width:80px; border:1px solid #ebebec;">
								<input type="hidden" name="searchBaseYmd" value=""  style="width:0px;">
							</td>	
							<th style="width:10%; min-width:100px;"><%= localeMessage.getString("routingEaiservice.eaisevrinstncname")%></th>
							<td style="width:20%">
								<div class="select-style"><select name="searchEaiSevrInstncName" value="${param.searchEaiSevrInstncName}"></select>
							</td>
							<th style="width:10%; min-width:130px;"><%= localeMessage.getString("routingEaiservice.svcmotivusedstcd")%></th>
							<td style="width:20%"><div class="select-style"><select name="searchSvcMotivUsedStcd"  value="${param.searchSvcMotivUsedStcd}"></select></div></td>
						</tr>	
						<tr>
							<th><%= localeMessage.getString("routingEaiservice.eaisvcname")%></th>
							<td>
								<input type="text" name="searchEaiSvcName" value="${param.searchEaiSvcName}">
							</td>
							<th>Flow Control</th>
							<td><div class="select-style"><select name="searchFlowCtrlRoutName" value="${param.searchFlowCtrlRoutName}"></select></div></td>							
							<th><%= localeMessage.getString("routingEaiservice.psvintfacdsticname")%></th>
							<td><div class="select-style"><select name="searchPsvIntfaCdSticName" value="${param.searchPsvIntfaCdSticName}"></select></div></td>	
						</tr>	
					</tbody>
				</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

