<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>
<%@ 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 $ = jQuery.noConflict();
var bzwkDstCd = "";

var returnUrl = getReturnUrlForReturn();
var roleString	= "<%=SessionManager.getRoleIdString(request)%>";

function init(url){
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_EAISVCNAME_COMBO'},
		success:function(json){
			var cnvsnTypeData	= json.cnvsnTypeRows;
			var inoutTypeData	= json.inoutTypeRows;
			new makeOptions("CODE","NAME").setObj($("select[name=cnvsnType]")).setData(cnvsnTypeData).setFormat(codeName3OptionFormat).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=eaiSevrDstcd]")).setData(inoutTypeData).setFormat(codeName3OptionFormat).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=useYn]")).setData(json.useYnRows).setFormat(codeName3OptionFormat).rendering();		
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}
$(document).ready(function() {	
	$("input[name=eaiSvcName]").focus();
	var url ='<c:url value="/onl/admin/rule/transformMan.json" />';
	init(url);

	$("#btn_regist").click(function(){
		if(!$("input[name='eaiSvcName']").val()){
			alert("<%=localeMessage.getString("transformMan.alert1")%>");
			return;
		}
		var postData = $('#ajaxForm').serializeArray();
		
		$("select[name=eaiSevrDstcd]").attr("disabled",false);
		var eaiSevrDstcd = $("select[name=eaiSevrDstcd]").val();
		// 서버구분코드 없고, role이 admin일때 서버구분코드 9로 셋팅
		if((eaiSevrDstcd=='' || eaiSevrDstcd ==null) && roleString=='admin'){
			eaiSevrDstcd = '9';
		}
		postData.push({ name: "cmd" , value:"INSERT"},{name : "eaiSevrDstcd", value : eaiSevrDstcd},{name : "verInfo", value : "00000"});
		$.ajax({ 
			type : "POST",
			url:url,
			data:postData,
			success:function(args){
				alert("<%=localeMessage.getString("common.saveMsg")%>");
				goNav(returnUrl);//LIST로 이동
			},
			error:function(e){
				alert(e.responseJSON.errorMsg);
			}
		});
	});
	
	$("#btn_search").click(function(){
		var key = "";
		var args = new Object();
    	args['eaiSvcName'] = $('input[name=eaiSvcName]').val();
	    var url='<c:url value="/onl/transaction/extnl/interfaceMan.view"/>';
	    url = url + "?cmd=POPUP";
	    var ret = showModal(url,args,1020,630, 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;
	        console.log("ret",ret);
			key = ret['key'];
			
			$("input[name=eaiSvcName]").val(key);
			$("input[name=eaiSvcDesc]").val(ret['eaiSvcDesc']);
			bzwkDstCd = ret['eaiBzwkDstCd'];
			
			$("input[name=eaiSvcName]").change();
			$("select[name=eaiSevrDstcd]").val(ret['eaiSevrDstcd']);
			$("select[name=eaiSevrDstcd]").attr("disabled",true);
	    });
	});

	$("#btn_previous").click(function(){
		goNav(returnUrl);//LIST로 이동
	});	
	$("input[name=eaiSvcName],select[name=cnvsnType]").change(function(){
		var eaiSvcName = $("input[name=eaiSvcName]").val();
		var idx = eaiSvcName.length;
		eaiSvcName = eaiSvcName.substring(0,idx-2);
		
		var str = "TRANSFORM_"+bzwkDstCd.trim()+"_"+eaiSvcName+"_"+$("select[name=cnvsnType]").val();
		$("input[name=cnvsnName]").val(str);
		
		var str2 = $("input[name=eaiSvcDesc]").val();
		$("textarea[name=cnvsnDesc]").val(str2);
		
	});	
	
	$("input[name=eaiSvcName]").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">
				<div class="search_wrap">				
					<button type="button" class="cssbtn" id="btn_regist" level="W" status="DETAIL,NEW"><i class="material-icons">save</i> <%= localeMessage.getString("button.register") %></button>
					<button type="button" class="cssbtn" id="btn_previous" level="R" status="DETAIL,NEW"><i class="material-icons">arrow_back</i> <%= localeMessage.getString("button.previous") %></button>
<%-- 					<img src="<c:url value="/img/btn_regist.png"/>" alt="" id="btn_regist" level="W" status="DETAIL,NEW" />				 --%>
<%-- 					<img src="<c:url value="/img/btn_previous.png"/>" alt="" id="btn_previous" level="R" status="DETAIL,NEW"/> --%>
				</div>
				<div class="title"><%=localeMessage.getString("transformMan.titleNew")%><span class="tooltip"><%=localeMessage.getString("transformMan.tooltipNew")%></span></div>				
				
				<table id="grid" ></table>
				<div id="pager"></div>
				
				<!-- detail -->
				<form id="ajaxForm">
					<table class="table_row" cellspacing="0">
						<tr>
							<th style="width:25%;"><%=localeMessage.getString("transformMan.ifSvcCd")%> </th>
							<td colspan="3">
								<input type="text" name="eaiSvcName" style="width:calc(100% - 60px);" readonly> <%-- <img id="btn_search" src="<c:url value="/img/btn_pop_search.png" />" level="R" class="btn_img" /> --%>
								<button type="button" class="cssbtn smallBtn2" id="btn_search" style="vertical-align:middle; font-weight:bold;" level="R"><i class="material-icons">search</i><%= localeMessage.getString("button.search") %></button>
							</td>
						</tr>
						<tr>
							<th><%=localeMessage.getString("transformMan.ifSvcDesc")%></th>
							<td colspan="3">
								<input type="text" name="eaiSvcDesc" readOnly>
							</td>
						</tr>
						<tr>
							<th><%=localeMessage.getString("transformMan.eaiSvrDiv")%></th>
							<td colspan="3">
								<div class="select-style">
									<select name="eaiSevrDstcd" />
								</div>	
							</td>
						</tr>
						<tr>
							<th><%=localeMessage.getString("transformMan.cnvsnType")%></th>
							<td>
								<div class="select-style">
									<select name="cnvsnType" />
								</div>	
							</td>
							<th><%=localeMessage.getString("combo.useYn")%></th>
							<td>
								<div class="select-style">
									<select name="useYn" />
								</div>	
							</td>
						</tr>
						<tr>
							<th><%=localeMessage.getString("transformMan.telCngMappCd")%></th>
							<td colspan="3"><input type="text"  name="cnvsnName" readonly="readonly"/></td>
						</tr>
						
						<tr height="100px">
							<th><%=localeMessage.getString("transformMan.cnvsnDesc")%></th><td colspan="3"><textarea  name="cnvsnDesc" style="width:100%;height:100px"></textarea></td>
						</tr>
					</table>
					</form>				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->	
	</body>
</html>

