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

var roleString	= "<%=SessionManager.getRoleIdString(request)%>";
var stgSvr		= <%=SystemUtil.isStagingServer()%>;

console.log( "rmsMenuAuth : "+ "${rmsMenuAuth}" )

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=searchTranType]")).setData(json.tranTypeRows).rendering();
			if (typeof callback === 'function') {
				callback();
			}
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}

function setBtnControl(roleString, condiVal, compoId)
{
	var strRole		= roleString;
	var strVal		= condiVal;
	var arrRoleID	= strRole.split(',');
	var arrVal		= strVal.split(',');
	var flag		= false;
	
	$(arrRoleID).each(function(i, role) {
		$(arrVal).each(function(j, val) {
			if (role == val) {
				flag = true;
				return false;
			}
		});
	});
	if(flag)
		$("#"+compoId).show();
	else
		$("#"+compoId).hide();
}


$(document).ready(function() {	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 

	init();
	
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST', 		
		postData : gridPostData,
 		colNames:[
 				  '<%= localeMessage.getString("eaiMsg.bizCode")%> ',
                  '<%= localeMessage.getString("eaiMessage.eaiSvcName")%> ',
                  '<%= localeMessage.getString("eaiMessage.eaiSvcDesc")%> ',
                  '<%= localeMessage.getString("eaiMessage.svcMotivUsedStcd")%>',
                  '<%= localeMessage.getString("eaiMessage.psvintfacdsticName")%>',
                  '<%= localeMessage.getString("eaiMessage.queueName")%> ',
                  '<%= localeMessage.getString("eaiMessage.flowCtrlRoutName")%> ',
                  '<%= localeMessage.getString("eaiMessage.tranType")%> ',
                  'TRANTYPE'
                  ],
		colModel:[
				{ name : 'EAIBZWKDSTCD'     , align:'center'	,sortable:false, width:20  },
				{ name : 'EAISVCNAME'       , align:'left', width:50  },
				{ name : 'EAISVCDESC'       , align:'left'  },
				{ name : 'SVCMOTIVUSEDSTCD', align:'center', width:50  },
				{ name : 'PSVINTFACDSTICNAME', align:'center', width:50  },
				{ name : 'NONMOTIVROUTURINAME' , align:'left', width:90   },
				{ name : 'FLOWCTRLROUTNAME' , align:'center', width:40  },
				{ name : 'TRANTYPE', align:'center', width:30  },
				{ name : 'TRANTYPE_CODE', align:'center', width:30 , hidden:true}
				],
        jsonReader: {
             repeatitems:false
        },	       
        multiselect:true,
        multiboxonly: 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)		
			}
		
		},			
		loadComplete:function (d){
		},
        loadError: function (jqXHR, textStatus, errorThrown) {
        	if(jqXHR.status == 401) {
	    		alert('HTTP status code: ' + jqXHR.status + '\n' +
	                    '에러:  세션이 종료되었습니다. ');
	    		parent.location.href='<%=request.getContextPath()%>/';	
	    	}
        	
    	},		
		ondblClickRow: function(rowId) {
			
        }		
	});
	
	
	resizeJqGridWidth('grid','content_middle','1000');
	$("#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)
		gridToExcelSubmit(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'eaiMsgDev');
		return false;
	});
	//거래처리 update
	$("#btn_modify").click(function(){
		var id = "grid";
		var params = new Array();
		var ids = $("#grid").jqGrid('getDataIDs');
		var chkTranType = "";
		var tranNm = "일반거래";
		var chkcnt = 0;
		
		for(var i=0;i<ids.length;i++){
			if($("input:checkbox[id='jqg_"+id+"_"+ids[i]+"']").is(":checked")){
				var rowObject = $("#grid").getRowData(ids[i]);
				params.push(rowObject['EAISVCNAME'])
				chkTranType = rowObject['TRANTYPE_CODE'];
				chkcnt++;
			}
		}
		
		if(chkcnt == 0){
			alert("서비스를 선택해 주세요");
			return false;
		}
		
		//console.log("cur Type : "+chkTranType)
		//check trantype
		chkTranType = (chkTranType=="R"?"S":"R");
		if(chkTranType == "S"){
			tranNm = "EAI 중단거래";
		}
		//console.log("update Type : "+chkTranType)
		
		if(confirm("선택한 서비스를 "+tranNm+"로 수정하시겠습니까?")){
			var postData = [];
			postData.push({ name: "cmd" , value:"CHANGE_TRANTYPE"});
			postData.push({ name: "tranType" , value:chkTranType});
			postData.push({ name: "eaiSvcName" , value:params});
				
			$.ajax({
				type : "POST",
				url : url,
				dataType : "json",
				data : postData,
				success : function(json) {
					alert(json.message);
					$("#btn_search").click();
				},
				error : function(e) {
					alert("error"+e.responseText);
				}
			});
		}else{
			return false;
		}
		
		
	});
	
	$("#btn_search").click(function(){
		var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
		$("#grid").setGridParam({ url: url, 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);
	});
	//검색값  enter시  조회
	$("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);
			}
		});		
		
	});	
 */
 
	buttonControl();
	if(stgSvr) {
		setBtnControl(roleString, "admin,svc_tranMng", "btn_modify");
	} 
});
 
</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_modify" level="W"><i class="material-icons">expand_circle_down</i> <%= localeMessage.getString("button.operate") %></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_operate.png"/>" alt="" id="btn_modify" level="W" /> --%>
					<%-- <img src="<c:url value="/img/btn_initialize.png"/>" alt="" id="btn_initialize" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" /> --%>
				</div>
				<div class="title"><%= localeMessage.getString("eaiMessage.title3")%></div>
				
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th ><%= localeMessage.getString("eaiMessage.tranType")%></th>
							<td>
								<div style="position: relative; width: 100%;">
									<select name="searchTranType" value="${param.searchTranType}" ></select>
								</div>
							</td>
							<th style="width:180px;"><%= localeMessage.getString("eaiMessage.eaiSvcName")%></th>
							<td>
								<input type="text" name="searchEaiSvcName" value="${param.searchEaiSvcName}">
							</td>
							<th style="width:180px;"><%= localeMessage.getString("eaiMessage.searchBzwkDstCd")%></th>
							<td>
								<input type="text" name="searchEaiBzwkDstcd" value="${param.searchEaiBzwkDstcd}">
							</td>
						</tr>	
					</tbody>
				</table>
				
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

