<%@ 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 url      = '<c:url value="/onl/admin/service/eaiMsgMan.json"/>';
var url_view = '<c:url value="/onl/admin/service/eaiMsgMan.view"/>';
var roleString	= "<%=SessionManager.getRoleIdString(request)%>";

var isClone = false;	
var isDetail = false;
var selectName = "eaiBzwkDstcd,flowCtrlRoutName,gstatSysAdptrBzwkGroupName";	// selectBox Name

var key ="${param.eaiSvcName}";

function init(key,callback){
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=eaiBzwkDstcd]"              )).setData(json.bizRows            ).setFormat(codeName3OptionFormat).rendering();//업무구분코드             		
			new makeOptions("CODE","NAME").setObj($("select[name=svcHmsEonot]"               )).setData(json.svcTimeExistRows   ).setFormat(codeName3OptionFormat).rendering();//업무운영 시간여부        		
			new makeOptions("CODE","NAME").setObj($("select[name=svcMotivUseDstcd]"          )).setData(json.svcSameTimeTypeRows).rendering();//인터페이스 사용유형      		
			new makeOptions("CODE","NAME").setObj($("select[name=svcPrcesDsticName]"         )).setData(json.svcProcessTypeRows ).rendering();//서비스 처리유형          		
			new makeOptions("CODE","NAME").setObj($("select[name=flowCtrlRoutName]"          )).setData(json.flowControlRows    ).rendering();//Flow Control 라우팅명    		
			new makeOptions("CODE","NAME").setObj($("select[name=intgraDsticName]"           )).setData(json.unitTypeRows       ).rendering();//거래유형                 		
			//new makeOptions("CODE","NAME").setObj($("select[name=svcBfClmnLogYn]"            )).setData(json.svcWholeColLogRows ).setFormat(codeName3OptionFormat).rendering();//보조 로그 사용여부       		
			new makeOptions("CODE","NAME").setObj($("select[name=internalExternalDvcd]"      )).setData(json.internalExternalDvcdRows ).setFormat(codeName3OptionFormat).rendering();//내외부구분코드
			new makeOptions("ADPTRBZWKGROUPNAME","ADPTRBZWKGROUPDESC").setObj($("select[name=gstatSysAdptrBzwkGroupName]")).setNoValueInclude(true).setNoValue("", "<%=localeMessage.getString("combo.noChoice")%>").setData(json.inAdapterRows).setFormat(codeName3OptionFormat).rendering();//기동 인터페이스 유형     		
			new makeOptions("CODE","NAME").setObj($("select[name=sevrLogLvelNo]"             )).setData(json.serverLogLevelRows ).setFormat(codeName3OptionFormat).rendering();//서버로그 레벨            		
			new makeOptions("CODE","NAME").setObj($("select[name=svcLogLvelNo]"              )).setData(json.svcLogLevelRows    ).setFormat(codeName3OptionFormat).rendering();//서비스 로그레벨          		
			//EAI서버구분코드
			new makeOptions("CODE","NAME").setObj($("select[name=eaiSevrDstCd]"               )).setData(json.inoutTypeRows).setFormat(codeName3OptionFormat).rendering();
			//EAI그룹회사코드
			new makeOptions("CODE","NAME").setObj($("select[name=eaiGroupCoCd]"               )).setNoValueInclude(true).setNoValue("", "<%=localeMessage.getString("combo.noChoice")%>").setData(json.groupCoCdRows).setFormat(codeName3OptionFormat).rendering();
			//거래처리구분
			new makeOptions("CODE","NAME").setObj($("select[name=tranType]"                   )).setData(json.tranTypeRows).setFormat(codeName3OptionFormat).rendering();
			new makeOptions("CODE","NAME").setObj($("select[name=useYn]"                   )).setData(json.useYnRows).setFormat(codeName3OptionFormat).rendering();
			
			if(key == "") setSearchable(selectName);	// 콤보에 searchable 설정
			
			if(typeof callback === 'function') {
				callback(key);
    		}
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}
function detail(key){
	if (!isDetail)return;
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'DETAIL', eaiSvcName : key},
		success:function(json){
			var data = json;
			$("input[name=eaiSvcName]").attr('readonly',true);
			$("#ajaxForm input[type!=radio],#ajaxForm select,#ajaxForm textarea").each(function(){
				var name = $(this).attr("name");
				var tag  = $(this).prop("tagName").toLowerCase();
				$(tag+"[name="+name+"]").val(data[name.toUpperCase()]);
				console.debug(tag + ":" + name + " : " + data[name.toUpperCase()]);
				console.debug($(tag+"[name="+name+"]").val())
				console.debug($(tag+"[name="+name+"]"))
			});
			
			setSearchable(selectName);	// 콤보에 searchable 설정
		},
		error:function(e){
			alert(e.responseText);
		}
	});
	var postData = {};
	postData["cmd"]="LIST_SVC";
	postData["eaiSvcName"]=key;
	$("#grid").setGridParam({ url : url, postData: postData }).trigger("reloadGrid");
}
function gridRendering(){
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		rowNum: 10000,
		colNames:['<%= localeMessage.getString("eaiMessage.eaiSvcName")%>',
				  '<%= localeMessage.getString("eaiMessage.proOrder")%>',
				  '<%= localeMessage.getString("eaiMessage.mIF")%>',
				  '<%= localeMessage.getString("eaiMessage.mWorkName")%>',
				  '<%= localeMessage.getString("eaiMessage.mSysIFCls")%>',
				  '<%= localeMessage.getString("eaiMessage.failoverWhether")%>',
				  '<%= localeMessage.getString("eaiMessage.nextSvcSeq")%>',
				  '<%= localeMessage.getString("eaiMessage.ObRoutName")%>'
                  ],
		colModel:[
				{ name : 'EAISVCNAME'               , align:'left' , hidden: true },
				{ name : 'SVCPRCSSNO'               , align:'left' },
				{ name : 'PSVINTFACDSTICNAME'       , align:'left' },
				{ name : 'PSVSYSBZWKDSTCD'          , align:'left' },
				{ name : 'PSVSYSADPTRBZWKGROUPNAME' , align:'left' },
				{ name : 'FLOVRYN'                  , align:'left' },
				{ name : 'NEXTSVCPRCSSNO'           , align:'left' },
				{ name : 'OUTBNDROUTNAME'           , align:'left' }
				],
        jsonReader: {
             repeatitems:false
        },	   
        loadComplete : function (d) {
        },
        ondblClickRow: function(rowId) {
	    	var rowData = $(this).getRowData(rowId); 
	    	var url2 = url_view;
			url2 += '?cmd=SVC';
			url2 += '&page='+$(this).getGridParam("page");
			url2 += '&returnUrl='+getReturnUrl();
			url2 += '&menuId='+'${param.menuId}';
			//검색값
			url2 += '&'+getSearchUrlForReturn();
			//key값
			url2 += '&eaiSvcName='+rowData['EAISVCNAME'];
			url2 += '&svcPrcssNo='+rowData['SVCPRCSSNO'];
			
			
	        goNav(url2);        
        },
	    onSelectRow: function(rowid,status){

	    },        
               
	    height: '300',
		autowidth: true,
		viewrecords: true
	});	
}

function isValid(){
	if ($('input[name=eaiSvcName]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert2")%>");
		$('input[name=eaiSvcName]').focus();
		return false;
	}
	if ($('select[name=eaiBzwkDstcd]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert3")%>");
		return false;
	}
	if ($('select[name=svcHmsEonot]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert4")%>");
		return false;
	}
	if ($('select[name=svcMotivUseDstcd]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert5")%>");
		return false;
	}
	if ($('select[name=svcPrcesDsticName]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert6")%>");
		return false;
	}
	if ($('select[name=flowCtrlRoutName]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert7")%>");
		return false;
	}
	if ($('select[name=intgraDsticName]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert8")%>");
		return false;
	}
	//if ($('select[name=svcBfClmnLogYn]').val()==""){
	//	alert("< %= localeMessage.getString("eaiMessage.alert9")% >");
	//	return false;
	//}
	if ($('select[name=internalExternalDvcd]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert14")%>");
		return false;
	}
	if ($('select[name=gstatSysAdptrBzwkGroupName]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert10")%>");
		return false;
	}
	if ($('select[name=sevrLogLvelNo]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert11")%>");
		return false;
	}
	if ($('select[name=svcLogLvelNo]').val()==""){
		alert("<%= localeMessage.getString("eaiMessage.alert12")%>");
		return false;
	}
	
	return true;
}

$(document).ready(function() {	
	var returnUrl = getReturnUrlForReturn();
	if (key != "" && key !="null"){
		isDetail = true;
	}
	gridRendering();
	
	//init(key,detail);
	
	$("#btn_clone").click(function(){
		// 복제할 서비스코드
		var newEaiSvcName = $("input[name=newEaiSvcName]").val();
		
		// 복제할 서비스코드 입력여부 체크.
		if(newEaiSvcName == "")
		{
			alert("<%= localeMessage.getString("eaiMessage.alert13")%>");
			return;
		}else{
			alert("복제시 데이터는 수정버튼을 클릭해야 DB에 저장됩니다."); 
			$("input[name=eaiSvcName]").val(newEaiSvcName);
			$("input[name=newEaiSvcName]").val("");
			$('#grid').jqGrid('clearGridData');
			
			//초기화 삭제버튼 숨김처리
			$("#btn_initialize , #btn_delete, #btn_new").hide();
			
		}
		
		$('#ajaxForm input[readonly]').each(function(){
			$(this).prop('readonly','');
		}); 
		
		$('#ajaxForm select[disabled]').each(function(){
			$(this).prop('disabled','');
		}); 
		
		isClone = true;

	});
	
	
	$("#btn_modify").click(function(){
		
		var postData = $('#ajaxForm').serializeArray();
		
		if (!isValid())return;
		
		if (isDetail && isClone) {
			if ( confirm( "복제하시겠습니까?" ) != true ) return;
		} else if (isDetail) {
			if ( confirm( '<%=localeMessage.getString("common.checkModify")%>' ) != true ) return;
		} else {
			if ( confirm( '<%=localeMessage.getString("common.checkInsert")%>' ) != true ) return;
		}
		
		if (isDetail && isClone){
			postData.push({ name: "cmd" , value:"INSERT"});
		} else if (isDetail) {
			postData.push({ name: "cmd" , value:"UPDATE"});
		} else {
			postData.push({ name: "cmd" , value:"INSERT"});
		}
		
		$.ajax({
			type : "POST",
			url:url,
			data:postData,
			success:function(args){
				alert("<%= localeMessage.getString("common.saveMsg")%>");
				goNav(returnUrl);//LIST로 이동
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	});
	$("#btn_delete").click(function(){
		if(confirm("<%= localeMessage.getString("common.confirmMsg")%>")){  
			var postData = $('#ajaxForm').serializeArray();
			postData.push({ name: "cmd" , value:"DELETE"});
			$.ajax({
				type : "POST",
				url:url,
				data:postData,
				success:function(args){
					alert("<%= localeMessage.getString("common.deleteMsg")%>");
					goNav(returnUrl);//LIST로 이동
	
				},
				error:function(e){
					alert(e.responseText);
				}
			});
		}
	});	
	$("#btn_previous").click(function(){
		goNav(returnUrl);//LIST로 이동
	});
	$("#btn_new").click(function(){
		if (!isDetail){
			alert("<%= localeMessage.getString("eaiMessage.alert15")%>");
			return;
		}
		
		var url2 = url_view;
		url2 += '?cmd=SVC';
		url2 += '&page='+$(this).getGridParam("page");
		url2 += '&returnUrl='+getReturnUrl();
        url2 += '&menuId='+'${param.menuId}';
		//검색값
		url2 += '&'+getSearchUrlForReturn();
		//key값
		url2 += '&eaiSvcName='+key;
		//generator key
		
		var rows = $("#grid")[0].rows;
		var index = Number($(rows[rows.length-1]).attr("id"));
		if (isNaN(index)) index=0;
	    var rowid = index + 1;
		
		
		url2 += '&svcPrcssNoForIndex='+rowid;
        goNav(url2);
	});
	
	$("#btn_initialize").click(function(){
		$.ajax({  
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'INITIALIZE',eaiSvcName:$("input[name=eaiSvcName]").val()},
			success:function(json){
				alert(json.message);
			},
			error:function(e){
				alert(e.responseText);
			}
		});		
		
	});		
	
	resizeJqGridWidth('grid','title','1000');

	buttonControl(isDetail);
	titleControl(isDetail);
	setBtnHide(roleString, "admin", "btn_initialize");
});

$(window).on("load", function() {
	init(key,detail);
});
 
</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="title">
				<div class="search_wrap">
					<button type="button" class="cssbtn" id="btn_initialize" level="W" status="DETAIL"><i class="material-icons">restart_alt</i> <%= localeMessage.getString("button.reset") %></button>
					<button type="button" class="cssbtn" id="btn_delete" level="W" status="DETAIL,NEW"><i class="material-icons">delete</i> <%= localeMessage.getString("button.delete") %></button>
					<button type="button" class="cssbtn" id="btn_modify" level="W" status="DETAIL,NEW"><i class="material-icons">save</i> <%= localeMessage.getString("button.modify") %></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>
				</div>
				<div class="title"><%= localeMessage.getString("eaiMessage.detailTitle")%></div>						
				
				<form id="ajaxForm">
					<div class="table_row_title"><%= localeMessage.getString("eaiMessage.detailTitle2")%></div>
					<table id="detail" class="table_row"  cellspacing="0"  >
						<tr level="W" >
							<td colspan="4">
								<input type="text" name="newEaiSvcName" style="width:200px;"> 
								<button type="button" class="cssbtn smallBtn2" id="btn_clone" style="vertical-align:middle; font-weight:bold;" level="W" status="DETAIL,NEW"><i class="material-icons">content_copy</i><%= localeMessage.getString("button.clone2") %></button>
							</td>
						</tr>
					</table>	
					<table id="detail" class="table_row"  cellspacing="0"  >
						<tr>
							<th style="width:20%;"><%= localeMessage.getString("eaiMessage.eaiSvcName")%></th>
							<td style="width:30%;"><input type="text" name="eaiSvcName"> </td>
							<th style="width:20%;"><%= localeMessage.getString("eaiMessage.searchBzwkDstCd")%> </th>
							<td style="width:30%;">
								<div style="position:relative;">
									<div class="select-style">
										<select name="eaiBzwkDstcd">											
										</select>
									</div>
								</div>
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.svcHmsEonot")%> </th>
							<td >
								<div class="select-style">
									<select name="svcHmsEonot"></select>
								</div>
							</td>
							<th><%= localeMessage.getString("eaiMessage.svcMotivUsedStcd")%> </th>
							<td >
								<div class="select-style">
									<select name="svcMotivUseDstcd"></select>
								</div>
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.svcPrcesDsticName")%> </th>
							<td >
								<div class="select-style">
									<select name="svcPrcesDsticName"></select>
								</div>
							</td>
							<th><%= localeMessage.getString("eaiMessage.flowCtrlRoutName")%> </th>
							<td >
								<div style="position:relative;">
									<div class="select-style">
										<select name="flowCtrlRoutName">									
									</select>
									</div>
								</div>
							</td>
						</tr>
						<tr><!-- 거래유형 -->
							<th><%= localeMessage.getString("eaiMessage.intgraDsticName")%> </th>
							<td >
								<div class="select-style">
									<select name="intgraDsticName"></select>
								</div>
							</td>
							<th><%= localeMessage.getString("eaiMessage.internalExternalDvcd")%> </th>
							<td >
								<div class="select-style">
									<select name="internalExternalDvcd"></select>
								</div>
								<input type="hidden" name="svcBfClmnLogYn" value="0">
							</td>
							<!--
							<th>< %= localeMessage.getString("eaiMessage.svcBfClmnLogYn")% > </th>
							<td >
								<div class="select-style">
									<select name="svcBfClmnLogYn"></select>
								</div>
							</td>
							-->
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.gstaSysAdptBzwkGroupName")%> </th>
							<td >
								<div style="position:relative;">
									<div class="select-style">
										<select name="gstatSysAdptrBzwkGroupName">
									</select>
									</div>
								</div>	
							</td>
							<th><%= localeMessage.getString("eaiMessage.sevrLogLvelNo")%> </th>
							<td >
								<div class="select-style">
									<select name="sevrLogLvelNo"></select>
								</div>
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.svcLogLvelNo")%> </th>
							<td >
								<div class="select-style">
									<select name="svcLogLvelNo"></select>
								</div>
							</td>
							<th><%= localeMessage.getString("eaiMessage.errEaiSvcName")%> </th>
							<td >
								<input type="text" name="errEAISvcName">
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.dmndErrChngIdName")%> </th>
							<td>
								<input type="text" name="dmndErrChngIdName">
							</td>
							<th><%= localeMessage.getString("eaiMessage.dmndErrFldName")%> </th>
							<td >
								<input type="text" name="dmndErrFldName">
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.rspnErrChngIdName")%> </th>
							<td >
								<input type="text" name="rspnsErrChngIdName">
							</td>
							<th><%= localeMessage.getString("eaiMessage.rspnErrFldName")%> </th>
							<td>
								<input type="text" name="rspnsErrFldName">
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.eaiSvcDesc")%> </th>
							<td colspan="3">
								<textarea name="eaiSvcDesc" style="width:100%;height:50px"></textarea>
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.eaiSevrDstcd")%> </th>
							<td >
								<div class="select-style">
									<select name="eaiSevrDstCd"></select>
								</div>
							</td>
							<th><%= localeMessage.getString("eaiMessage.eaiGroupCoCd")%> </th>
							<td >
								<div class="select-style">
									<select name="eaiGroupCoCd"></select>
								</div>
							</td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.tranType")%> </th>
							<td>
								<div class="select-style">
									<select name="tranType"></select>
								</div>
							</td>	
							<th><%= localeMessage.getString("combo.useYn")%> </th>
							<td>
								<div class="select-style">
									<select name="useYn"></select>
								</div>
							</td>							
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.verInfo")%></th>
							<td colspan="3">
								<input type="text" name="verInfo" readonly>
							</td>						
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.tranId")%> </th>
							<td>
								<input type="text" name="txId">
							</td>	
							<th><%= localeMessage.getString("eaiMessage.refKey")%> </th>
							<td>
								<input type="text" name="refKey">
							</td>							
						</tr>
						<tr>
							<th><%= localeMessage.getString("eaiMessage.extBizDivCd")%> </th>
							<td>
								<input type="text" name="extBizCd">
							</td>	
							<th><%= localeMessage.getString("eaiMessage.auth")%> </th>
							<td>
								<input type="text" name="author">
							</td>							
						</tr>												
					</table>
					</form>
					
					<div class="table_row_title">
						<table><tr><td class="table_row_title"><%= localeMessage.getString("eaiMessage.ifSvcMsgList")%> </td>
						<td>&nbsp;</td>
						<td>
						<!-- img id="btn_new" src="<c:url value="/img/btn_pop_new.png" />"  level="W" status="DETAIL,NEW" class="btn_img" / -->
						<button type="button" class="cssbtn smallBtn2" id="btn_new" style="vertical-align:middle; font-weight:bold;" level="W" status="DETAIL,NEW"><i class="material-icons">add</i><%= localeMessage.getString("button.new") %></button>
						</td></tr></table>		
					</div>
					<!-- grid -->
					<table id="grid" ></table>
			</div><!-- end content_middle -->
		</div><!-- end right_box -->	
	</body>
</html>

