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

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

function init(){
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT', codeGroupArr : 'TRAN_TYPE_DEV'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=searchTranType]")).setData(json.list).rendering();
		},
		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() {
	
	init();
	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	gridPostData['searchTranType'] = 'R';
	
	$('#grid').jqGrid({
		url : url,
		datatype:"json",
		mtype: 'POST', 		
		postData : gridPostData,
 		colNames:[
 				  '<%= localeMessage.getString("eaiMessage.eaiBzwkDstCd")%> ',
 				 '<%= localeMessage.getString("eaiMessage.extBizCd")%> ',
 				 '<%= localeMessage.getString("eaiMessage.ifIdKeyVal")%>',
                  '<%= 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 : 'EXTBIZCD'			, align:'center', width: 30 },
				{ name : 'REFKEY'			, align:'left'	, width: 50 },
				{ name : 'EAISVCNAME'       , align:'left'	, width:50  },
				{ name : 'EAISVCDESC'       , align:'left'	, width: 100  },
				{ name : 'SVCMOTIVUSEDSTCD'	, align:'center', width:50  },
				{ name : 'PSVINTFACDSTICNAME', align:'center', width:50  },
				{ name : 'NONMOTIVROUTURINAME' , align:'left', width:90   },
				{ name : 'FLOWCTRLROUTNAME' , align:'center', width:50  },
				{ 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');
	//거래처리 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'];
				chkcnt++;
			}
		}
		
		if(chkcnt == 0){
			alert("서비스를 선택해 주세요");
			return false;
		}
		
		//check trantype
		chkTranType = (chkTranType == "R" ? "T" : "R");
		tranNm = (chkTranType == "R" ? "일반거래" : "시뮬레이터 거래");
		
		if(confirm("선택한 서비스를 "+tranNm+"로 수정하시겠습니까?")){
			var postData = [];
			postData.push({ name: "cmd" , value:"CHANGE_TRANTYPE"});
			postData.push({ name: "tranType" , value:chkTranType});
			postData.push({ name: "eaiSvcName" , value:params.join(',')});
				
			$.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(){
		$("#grid").setGridParam({ postData: getSearchForJqgrid("cmd", "LIST"), page : "1" }).trigger("reloadGrid");
	});
	//검색값  enter시  조회
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	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_modify" level="R" ><i class="material-icons">change_circle</i> <%= localeMessage.getString("button.convert") %></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_convert.png"/>" alt="" id="btn_modify" level="R" /> --%>
					<!-- <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.title4")%></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:120px;"><%= localeMessage.getString("eaiMessage.eaiBzwkDstCd")%></th>
							<td>
								<input type="text" name="searchEaiBzwkDstcd" value="${param.searchEaiBzwkDstcd}">
							</td>
							<th style="width: 120px;"><%= localeMessage.getString("eaiMessage.extBizCd")%></th>
							<td>
								<input type="text" name="searchExtBizCd" value="${param.searchExtBizCd}" />
							</td>
							<th style="width: 120px;"><%= localeMessage.getString("eaiMessage.ifIdKeyVal")%></th>
							<td>
								<input type="text" name="searchRefKey" value="${param.searchRefKey}" />
							</td>
						</tr>	
						<tr>
							<th style="width:120px;"><%= localeMessage.getString("eaiMessage.eaiSvcName")%></th>
							<td colspan="3">
								<input type="text" name="searchEaiSvcName" value="${param.searchEaiSvcName}">
							</td>
							<th style="width:120px;"><%= localeMessage.getString("eaiMessage.eaiSvcDesc")%></th>
							<td colspan="3">
								<input type="text" name="searchEaiSvcDesc" value="${param.searchEaiSvcDesc}">
							</td>
						</tr>
					</tbody>
				</table>
				
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

