<%@ 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" %>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>

<%@ page import="com.eactive.eai.common.util.SystemUtil"%>
<%
	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/c2rServiceMan.json" />';
var url_view = '<c:url value="/onl/admin/service/c2rServiceMan.view" />';
var url_excel= '<c:url value="/onl/admin/service/c2rServiceMan.excel" />';

var roleString	= "<%=SessionManager.getRoleIdString(request)%>";
var devSvr		= <%=SystemUtil.isDevServer()%>;

var select_FLOVRYN     	= new Array();
var select_UseYn     	= new Array();
var select_EaiSevrDstCd = new Array();
var selectName = "searchPsvSysBzwkDstcd";

function init(callback) {
	$.ajax({
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=searchFailOverYn]")).setNoValueInclude(true).setNoValue("", "전체").setData(json.useYnRows).setFormat(codeName3OptionFormat).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=searchUseYn]")).setNoValueInclude(true).setNoValue("", "전체").setData(json.useYnRows).setFormat(codeName3OptionFormat).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=searchPsvSysBzwkDstcd]"    )).setNoValueInclude(true).setNoValue("", "전체").setData(json.bizRows).setFormat(codeName3OptionFormat).rendering();//수동업무구분
			
			setSearchable(selectName);
			
			select_FLOVRYN['value']      = ": ;"+getGridSelectText("CODE","NAME",json.failOverClsRows);
			select_UseYn['value']    	 = ": ;"+getGridSelectText("CODE","NAME",json.useYnRows);
			select_EaiSevrDstCd['value'] = ": ;"+getGridSelectText("CODE","NAME",json.inoutTypeRows);
			if (typeof callback === 'function') {
				callback();
			}
		},
		error:function(e){
			alert(e.responseText);
		}
	});	
}
function gridRendering(){
    var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,
		colNames:[
				'<%= localeMessage.getString("c2r.bizCode") %>',
		        '<%= localeMessage.getString("c2r.procNo") %>',
	            '<%= localeMessage.getString("c2r.recvIfTp") %>',
	            '<%= localeMessage.getString("c2r.recvBizSysNm") %>',
	            '<%= localeMessage.getString("c2r.recvSysIfTp") %>',
	            '<%= localeMessage.getString("c2r.failOver") %>',
	            '<%= localeMessage.getString("c2r.nextOrder") %>',
	            '<%= localeMessage.getString("c2r.outRouting") %>',
				'<%= localeMessage.getString("c2r.useYn") %>',
				'<%= localeMessage.getString("c2r.sevrDstCd") %>'
                  ],
		colModel:[
				{ name : 'EXTNLINSTIIDNFINAME'      , align:'left'	,width : '120px;',sortable:false },
				{ name : 'SVCPRCSSNO'               , align:'center' 	,width : '80px;'},
				{ name : 'PSVINTFACDSTICNAME'       , align:'center' 	,width : '100px;'},
				{ name : 'PSVSYSBZWKDSTCD'          , align:'center'	,width : '100px;'},
				{ name : 'PSVSYSADPTRBZWKGROUPNAME' , align:'left' 					 	},
				{ name : 'FLOVRYN'                  , align:'center'	,width : '80px;' , edittype:'select',editoptions:select_FLOVRYN, formatter:"select"},
				{ name : 'NEXTSVCPRCSSNO'           , align:'center' 	,width : '80px;'},
				{ name : 'OUTBNDROUTNAME'           , align:'left' },
				{ name : 'USEYN'           			, align:'center' 	,width : '80px;', edittype:'select',editoptions : select_UseYn, formatter:"select"},
				{ name : 'EAISEVRDSTCD'           	, align:'center' 	,width : '80px;', edittype:'select',editoptions : select_EaiSevrDstCd, formatter:"select"}
				],
        jsonReader: {
             repeatitems:false
        },	          
		pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		multiselect: true,
		multiboxonly: false,
		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 key = rowData['EXTNLINSTIIDNFINAME'];
            var key2 = rowData['SVCPRCSSNO'];
            var url2 = url_view;
            url2 += '?cmd=DETAIL';
            url2 += '&page='+$(this).getGridParam("page");
            url2 += '&returnUrl='+getReturnUrl();
            url2 += '&menuId='+'${param.menuId}';
			//검색값
            url2 += '&'+getSearchUrl();
            //key값
            url2 += '&extnlInstiIdnfiName='+key;
            url2 += '&svcPrcssNo='+key2;
            goNav(url2);
        },loadError: function (jqXHR, textStatus, errorThrown) {
        	
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	}
	});
	
	resizeJqGridWidth('grid','content_middle','1000');
}

$(document).ready(function() {	
	init(gridRendering);
	//엑셀 2020.06.18 W > R 권한으로 변경요청 김소희차장님
	$("#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("b2bService.title")%>');
		return false;
	});
	$("#btn_search").click(function(){
		var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
		$("#grid").setGridParam({ postData: postData ,page : "1" }).trigger("reloadGrid");
	});
	$("#btn_new").click(function(){
		var url2 = url_view;
		url2 += '?cmd=DETAIL';
		url2 += '&page='+$("#grid").getGridParam("page");
		url2 += '&returnUrl='+getReturnUrl();
        url2 += '&menuId='+'${param.menuId}';
		//검색값
        url2 += '&'+getSearchUrl();

        goNav(url2);
	});
	
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	$("#btn_initialize").click(function(){
		$.ajax({  
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'INITIALIZES'},
			success:function(json){
				alert(json.message);
			},
			error:function(e){
				alert(e.responseText);
			}
		});		
	});			
	
	$('#btn_clone').click(onclickBtnClone);
	
	buttonControl();
	
	if(!devSvr) {
		setBtnHide(" ", "admin", "btn_clone");	
	}
   	
});

function onclickBtnClone() {
	var sel = $('#grid').jqGrid('getGridParam', 'selarrrow');
	if (sel.length == 0) {
		alert('먼저 복제할 데이터를 선택해주세요.');
		return;
	}
	
	var args = new Object();
	var url2 = '<c:url value="/onl/admin/service/comm.view" />'
	url2 += '?cmd=SYSCD POPUP CALENDAR';
	showModal(url2, args, 540, 200, 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;
	    cloneToProd(args.returnValue, sel);
	});
	/*
	if(confirm('선택한 데이터가 TEST로 이관 후 즉시 적용됩니다.\n이 작업은 동작시 취소 할 수 없습니다.')) {
		cloneToProd({}, sel);
	}
	*/
}

function cloneToProd(ret, sel) {
	var params = ret;
	params['cmd'] = 'CLONETOPROD'; 
	var selectedList = [];
	$(sel).each(function(index, i) {
		var name = $('#grid').getCell(i, 'EXTNLINSTIIDNFINAME');
		selectedList.push(name);
	});
	params['selectedList'] = selectedList.join('&');
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:params,
		success:function(json){
			alert(json.message);
			$("#btn_search").trigger('click');
		},
		error:function(xhr,status,error){
			if (xhr.responseText != null) {
				try {
					alert(JSON.parse(xhr.responseText).errorMsg);	
				} catch (e) {
					alert(error);
				}
			}
		}
	});
}
 
</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_clone" level="W"><i class="material-icons">file_copy</i> <%= localeMessage.getString("button.clone") %></button>
					<button type="button" class="cssbtn" id="btn_initialize" level="W"><i class="material-icons">restart_alt</i> <%= localeMessage.getString("button.reset") %></button>
					<button type="button" class="cssbtn" id="btn_new" level="W"><i class="material-icons">add</i> <%= localeMessage.getString("button.new") %></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_clone.png"/>" alt="" id="btn_clone"  level="W" style="height:32px;"/> --%>
					<!-- <img src="<c:url value="/img/btn_excel.png"/>" id="btn_excel" level="R"/> -->
<%-- 					<img src="<c:url value="/img/btn_initialize.png"/>" alt="" id="btn_initialize" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_new.png"/>" alt="" id="btn_new" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />	 --%>
				</div>
				<div class="title"><%= localeMessage.getString("c2r.title") %></div>
				<form id="ajaxForm"  onsubmit="return false;">
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th style="width:12%; min-width:140px;"><%= localeMessage.getString("c2r.bizCode") %></th>
							<td style="width:20%;"> 
								<input type="text" name="searchExtnlInstiIdnfiName" value="${param.searchExtnlInstiIdnfiName}">
							</td>
							<th style="width:12%; min-width:130px;"><%= localeMessage.getString("b2bService.psvSysAdptBzwkGroupName")%></th>
							<td colspan=3>
								<input type="text" name="searchPsvSysAdptBzwkGroupName" value="${param.searchPsvSysAdptBzwkGroupName}">
							</td>							
						</tr>		
						<tr>
							<th><%= localeMessage.getString("c2r.recvBizSysNm") %></th>
							<td>
								<div class="select-style">
									<select name="searchPsvSysBzwkDstcd" value="${param.searchPsvSysBzwkDstcd}"/>
								</div>
							</td>
							<th><%= localeMessage.getString("c2r.failOver") %></th>
							<td>
								<div class="select-style">
									<select name="searchFailOverYn" value="${param.searchEaiSevrDstcd}"/>
								</div>
							</td>
							<th style="width:8%; min-width:90px;"><%= localeMessage.getString("c2r.useYn") %></th>
							<td>
								<div class="select-style">
									<select name="searchUseYn" value="${param.searchUseYn}"/>
								</div>
							</td>							
						</tr>						
						
					</tbody>
				</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

