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


function detail(){

	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
	$("#grid").setGridParam({ url:url,postData: postData ,page:1 }).trigger("reloadGrid");
}

function unformatterFunction(cellvalue, options, rowObject){
	return "";
}

function imgFormatterFunction(cellvalue, options, rowObject){
	var rowId = options["rowId"];
	var serverValue  = rowObject['SERVERTYPE_VALUE'];
	
	return "<img style='width:15px;cursor:pointer;' name='img_"+rowId+"' src=<c:url value='/img/icon_search.png' /> onclick='fnCompanyDetail("+'"'+serverValue+'"'+")' />";
}

function imgFormatterFunction2(cellvalue, options, rowObject){
	var rowId = options["rowId"];
	var serverValue  = rowObject['SERVERTYPE_VALUE'];
	
	return "<img style='width:15px;cursor:pointer;' name='img_"+rowId+"' src=<c:url value='/img/icon_search.png' /> onclick='fnAppCodeDetail("+'"'+serverValue+'"'+")' />";
}

function fnCompanyDetail(serverValue){
	  var args = new Object();
	    args['eaiSevrDstcd'] = serverValue;
	    
	    var url2 = url_view;
	    url2 += "?cmd=POPUP";
	    
	    var ret = showModal(url2,args,570,760, function(arg){
	    	var args = null;
	        if(arg == null || arg == undefined ) {//chrome
	            args = this.dialogArguments;
	            args.returnValue = this.returnValue;
	        } else {//ie
	            args = arg;
	        }
	        
	        if( !args || !args.returnValue ) return;
	        var ret = args.returnValue;
	        list();
	        
	    });
}

function fnAppCodeDetail(serverValue){
	 var args = new Object();
	    args['eaiSevrDstcd'] = serverValue;
	    
	    var url2 = url_view;
	    url2 += "?cmd=POPUP2";
	    
	    var ret = showModal(url2,args,570,760, function(arg){
	    	var args = null;
	        if(arg == null || arg == undefined ) {//chrome
	            args = this.dialogArguments;
	            args.returnValue = this.returnValue;
	        } else {//ie
	            args = arg;
	        }
	        
	        if( !args || !args.returnValue ) return;
	        var ret = args.returnValue;
	        list();
	        
	    });
}

function list(){
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
	$("#grid").setGridParam({ url:url,postData: postData ,datatype:'json'}).trigger("reloadGrid");
}

$(document).ready(function() {
	
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : { cmd : 'LIST'},
		colNames:[
					 '서버구분'
					,'서버구분값' 
					,'대외기관 수'
					,'대외기관 수 상세'
					,'업무 수'
					,'업무 수 상세'
                  ],
		colModel:[
					{ name : 'SERVERTYPE'		, align:'center'	,width:'30px' },
					{ name : 'SERVERTYPE_VALUE'	, hidden:true},
					{ name : 'COMPANYNUM'		, align:'center'	,width:'40px' },
					{ name : 'COMPANYPOP'       , align:'center'    ,width:'20px' , unfomatter : unformatterFunction, formatter: imgFormatterFunction, excelDown:'no'},
					{ name : 'APCODENUM'		, align:'center'	,width:'40px' },
					{ name : 'APPCODEPOP'       , align:'center'    ,width:'20px' , unfomatter : unformatterFunction, formatter: imgFormatterFunction2, excelDown:'no'}
				],
				
        jsonReader: {
             repeatitems:false
        },
//         pager : $('#pager'),
// 		page : '${param.page}',
// 		rowNum : '${rmsDefaultRowNum}',
 	    height : '200',
		rowNum : 10000,
		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)		
			}
		},		
		loadComplete:function (d){
			$("#grid").tuiTableRowSpan("0");
		},
        loadError: function (jqXHR, textStatus, errorThrown) {
        	
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	}
	});
	
	
	//resizeJqGridWidth('grid','content_middle','1400');
	
	$("#btn_search").click(function(){ 
		detail();
	});
	
	$("#btn_blacklist").click(function(){ 
		 var args = new Object();
		    
		    var url2 = url_view;
		    url2 += "?cmd=POPUPBLACK";
		    
		    var ret = showModal(url2,args,1100,750, function(arg){
		    	var args = null;
		        if(arg == null || arg == undefined ) {//chrome
		            args = this.dialogArguments;
		            args.returnValue = this.returnValue;
		        } else {//ie
		            args = arg;
		        }
		        
		        if( !args || !args.returnValue ) return;
		        var ret = args.returnValue;
		        list();
		        
		    });
	});
	
	
	$("#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"),'<%= localeMessage.getString("statisticsByCompany.titleDaily")%>');
		return false;
	});
	
	$("#btn_initialize").click(function(){
		
		if(confirm("블랙리스트에 등록된 대외기관과 업무가 삭제됩니다. 동기화 하시겠습니까?") == false) 
			return ;
		
		$.ajax({  
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'TRANSACTION_BLACKLIST_DB_SYNC'},
			success:function(json){
				if(json.result == "success"){
					alert("블랙리스트 DB 동기화가 완료되었습니다");
					detail();
					
				}else{
					alert("블랙리스트 DB 동기화중 에러가 발생했습니다.");
				}
				
			},
			error:function(e){
				alert(e.responseText);
			}
		});		
		
	});
	
	
	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">
				<div class="title">대외기관 수 업무 수 통계</div>
				<form id="ajaxForm"  onsubmit="return false;">
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>	
			</div><!-- end content_middle -->
			<div style="position:absolute; left:50px;">
			※ 블랙리스트 : INSERT 하면 안되는 예외 리스트 정의(예 : EAI소켓모니터링) <br>
			※ 동기화 : 블랙리스트에 등록된 리스트를 대외기관 및 업무  DB에서 삭제함으로서 Sync를 맞추는 기능
			</div>
			<div style="position:absolute; right:50px;">
				<span><input type="button" value="블랙리스트" id="btn_blacklist" style="width:80px"/></span>
				<span><input type="button" value="동기화" id="btn_initialize" style="width:80px"/></span>
			</div>
			
		</div><!-- end right_box -->				
	</body>	
</html>

