<%@ 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" %>
<%
	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="/common/acl/bizKeyTran/bizKeyTranMan.json" />';
var url_view = '<c:url value="/common/acl/bizKeyTran/bizKeyTranMan.view" />';
var isDetail = false;
var selectName = "eaiBzwkDstcd,apCode";
	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.listEAICodeRows).setFormat(codeName3OptionFormat).rendering();
				new makeOptions("CODE","NAME").setObj($("select[name=apCode]")).setData(json.listApCodeRows).setFormat(codeName3OptionFormat).rendering();
				setSearchable(selectName);
				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',
				eaiBzwkDstcd : key
			},
			success : function(json) {
				var data = json;
				$("select[name=eaiBzwkDstcd]").val(data["EAIBZWKDSTCD"].trim()).attr('disabled','disabled');
				$("select[name=apCode]").val(data["APCODE"]);
			},
			error : function(e) {
				alert(e.responseText);
			}
		});
	}
	$(document).ready(function() {
		var returnUrl = getReturnUrlForReturn();
		
		var key ="${param.eaiBzwkDstcd}";
		if (key != "" && key !="null"){
			isDetail = true;
		}	

		init(key,detail);

		$("#btn_previous").click(function() {
			goNav(returnUrl);//LIST로 이동
		});
		
		$("#btn_modify").click(function(){
			
			if (isDetail) {
				if ( confirm( '<%=localeMessage.getString("common.checkModify")%>' ) != true ) return;
			} else {
				if ( confirm( '<%=localeMessage.getString("common.checkInsert")%>' ) != true ) return;
			}
			
			$("select[name=eaiBzwkDstcd]").removeAttr('disabled');
			$("select[name=apCode]").removeAttr('disabled');
			var postData = $('#ajaxForm').serializeArray();
			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")%>") != true)
			return;
			
			var postData = $('#ajaxForm').serializeArray();
			postData.push({ name: "cmd" , value:"DELETE"});
			postData.push({ name: "eaiBzwkDstcd" , value: key});
			$.ajax({
				type : "POST",
				url:url,
				data:postData,
				success:function(args){
					alert("<%= localeMessage.getString("common.deleteMsg") %>");
					goNav(returnUrl);//LIST로 이동

				},
				error:function(e){
					alert(e.responseText);
				}
			});
		});	
		buttonControl(isDetail);
		titleControl(isDetail);
	});
</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_delete" level="W" status="DETAIL"><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>
<%-- 				<img src="<c:url value="/img/btn_delete.png"/>" alt="" id="btn_delete" level="W" status="DETAIL"/> --%>
<%-- 					<img src="<c:url value="/img/btn_modify.png"/>" alt="" id="btn_modify" 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("bizKeyTranMan.title2")%></div>						
			<form id="ajaxForm">
				<table class="table_row" cellspacing="0">
					<tr>
						<th width="30%" class="detail_title"><%= localeMessage.getString("bizKeyTranMan.eaiBzwkDstcd")%></th>
						<td>
							<div class = "select-style">
								<select name = "eaiBzwkDstcd" ></select>	
							</div>
						</td>
					</tr>
					<tr>
						<th class="detail_title"><%= localeMessage.getString("bizKeyTranMan.apCode")%></th>
						<td>
							<div class = "select-style">
								<select name = "apCode"></select>
							</div>
						</td>
					</tr>
				</table>
			</form>
		</div><!-- end content_middle -->
	</div><!-- end right_box -->
</body>
</html>