<%@ 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_custom.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>

<script language="javascript" >
var url      = '<c:url value="/onl/admin/adapter/snaAdapterMan.json" />';
var url_view = '<c:url value="/onl/admin/adapter/snaAdapterMan.view" />';

var isDetail = false;

var colN = new Array();
var colM = new Array();

var checked = "<c:url value='/images/icon_checkbox_checked.png'/>";
var unChecked ="<c:url value='/images/icon_checkbox.png'/>";
function detail(key){
	var apCode = $("input[name=searchAppCode]").val();
	
	var instStr  = "";
	var idx=0;
	$("input[name^=EAI]").each(function(){
		$(this).val();
		if( $(this).prop("checked")==true){
			if(idx==0){
				instStr +=$(this).val();
			}else{
				instStr +=","+$(this).val();
			}
			idx++;
		}
	});
	$.ajax({
		url : url,
		dataType : 'json',
		type : 'POST',
		data:{cmd: 'DETAIL2', ADPTRBZWKGROUPNAME : key, apCode : apCode,  instStr : instStr},
		success : function(json){
			if(json){
				if(!json.Error){
					var colD = json.data;
					$("#grid")[0].addJSONData(colD);
				}
			}
		},
		error : function(xhr, ajaxOptions,thrownError){
			
		},
		complete : function(){
			
		}
	}); 
}

function chkFormatter(cellvalue, options, rowObject){
	var rowId = options["rowId"];
	var colum  = rowObject[options["colModel"]["name"]];
	if( colum == 1){
		return '<img src="'+checked+'" style="width:16px;" />';
	}else{
		return '<img src="'+unChecked+'" style="width:16px;" />';
	}
}
function gridRendering(){
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=EAISEVRINSTNCNAME]")).setData(json.instanceRows).rendering();	
			var result = "";
			var code = "";
			colN.push("APPCODE");
			var colMStr = {name : 'apCode',  align:'center' , width:'80px'};
			colM.push(colMStr);
			for(var i=0; i<json.instanceRows.length; i++){
				code = json.instanceRows[i]["CODE"];
				if(code=='ALL'){
					result += '<span id="allSpan">&nbsp; <img src="<c:url value="/images/icon_checkbox_checked.png"/>" style="width:16px;" id="all" />&nbsp;' + code+"</span>";
					result += " "+'<input type="checkbox" id="all" name="ALL" value="'+ code+'" checked style="visibility: hidden;">';
				}else{
					result += '<span name="'+json.instanceRows[i]["NAME"]+'" >&nbsp; <img src="<c:url value="/images/icon_checkbox.png"/>" style="width:16px;" />&nbsp;' + code+"</span>";
					result += " "+'&nbsp;<input type="checkbox" name="'+json.instanceRows[i]["NAME"]+'" value="'+ code+'"  style="visibility: hidden;">&nbsp;';
					if(i==8)result+="<br>";
					var instName = code.split("_");
					colNStr = "i"+instName[0].substr(instName[0].length-1,1)+instName[1].substr(instName[1].length-1,1);
					colN.push(colNStr);
					colMStr = {name : code,  align:'center' ,formatter: chkFormatter , width:'50px'};
					colM.push(colMStr);
				}
			}
			
			$("#svrInst").html(result);
			$('#grid').jqGrid({
				datatype:"local",
			    editurl : "clientArray",
				loadonce: true,
				rowNum: 10000,
				autoencode:false,
				colNames: colN,
				colModel: colM,
		        jsonReader: {
		             repeatitems:false
		        },	   
		        loadComplete : function (data) {
				
		        },
		        gridComplete : function(){
					
		        },
			    onSelectRow: function(rowid,status){
			    	var rowData = $(this).getRowData(rowid);
			    },        
		        onSortCol : function(){
		        },         
			    height: '500',
				autowidth: true,
				viewrecords: true
			});	
						
		},
		error:function(e){
			alert(e.responseText);
		}
	});
	
	
	resizeJqGridWidth('grid','content_middle','1000');
}

$(document).ready(function() {	
	var returnUrl = getReturnUrlForReturn();
	
	var key ="${param.adptrBzwkGroupName}";
	if (key != "" && key !="null"){
		isDetail = true;
	}
	gridRendering();	
	detail(key);
	
	
	$("#btn_previous").click(function(){
		goNav(returnUrl);//LIST·Î ÀÌµ¿
	});
	$("#btn_search").click(function(){
		detail(key);
	});
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	//checkBox event
	$(document).on("click","#allSpan",function(){
		$("input[name^=EAI]").prop("checked","");
		$("span[name^=EAI]").children("img").attr("src",unChecked);
		$("#all").attr("src",checked);
	});

	$(document).on("click","span[name^=EAI]",function(){
		var thisName = $(this).attr("name");
		if($(this).children("img").attr("src")==checked){
			$(this).children("img").attr("src",unChecked);
			$("input[name="+thisName+"]").prop("checked","");
		}else{
			$(this).children("img").attr("src",checked);
			$("input[name="+thisName+"]").prop("checked","checked");
		}
		$("#all").attr("src",unChecked);
		if($("input[name^=EAI]:checked").length==0){
			$("#all").attr("src",checked);
		}
	});
	

	buttonControl(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" id="content_middle">
				<div class="search_wrap">
					<img src="<c:url value="/img/btn_search.png"/>" alt="" name="img_search" id="btn_search" level="R" 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("snaAdapterMan.detail2Title")%></div>						
				
					<table id="detail" class="table_row"  cellspacing="0"  >
						<tr>
							<th style="width:180px;"><%=localeMessage.getString("adapterDetail.adptrbzwkgroupname")%></th>
							<td><input type="text" name="ADPTRBZWKGROUPNAME" value="${param.adptrBzwkGroupName}" readonly></td>
						</tr>
						<tr>
							<th style="width:180px;">APP CODE</th><td ><input type="text" name="searchAppCode"/> </td>
						</tr>
						<tr>
							<th ><%=localeMessage.getString("snaAdapterMan.svrInst")%></th>
							<td>
								<div id="svrInst"></div> 
							</td>
						</tr>
					</table>
					<table id="grid" ></table>
			</div><!-- end content_middle -->
		</div><!-- end right_box -->	
	</body>
</html>

