<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ 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/adapter/snaAdapterMan.json" />';
var url_view = '<c:url value="/onl/admin/adapter/snaAdapterMan.view" />';
var url_excel= '<c:url value="/onl/admin/adapter/snaAdapterMan.excel" />';

function init() {
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=searchAdptrUseYn]")).setNoValueInclude(true).setNoValue("","<%= localeMessage.getString("combo.all")%>").setData(json.useYnRows).setFormat(codeName3OptionFormat).rendering();			
			putSelectFromParam();
			
			if(typeof callback === 'function') {
				callback(key);
			}
						
		},
		error:function(e){
			alert(e.responseText);
		}
	});
	
}

function list(_page)
{   
	var page = "${param.page}";
	if(_page == "1") page = "1";
	
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	
	$("#grid").setGridParam({ url:url,postData: postData ,datatype:'json' }).trigger("reloadGrid");
}

function formatterFunction(cellvalue, options, rowObject) {
	var rowId = options["rowId"];
	if (cellvalue == "1") {
		return "<%= localeMessage.getString("combo.usey")%>";
	} else{
		return "<%= localeMessage.getString("combo.usen")%>";
	}
}
function unformatterFunction(cellvalue, options, rowObject){
	return "";
}

function imgFormatterFunction(cellvalue, options, rowObject){
	var rowId = options["rowId"];
	var adptrGroupName  = rowObject['ADPTRBZWKGROUPNAME'];
	
	return "<img style='width:50px' name='img_"+rowId+"' src=<c:url value='/img/btn_pop_search.png' /> onclick='fnAppCodeDetail("+'"'+adptrGroupName+'"'+")' />";
}
function fnAppCodeDetail(adptrGroupName){
	var url2 = url_view;
    url2 += '?cmd=DETAIL2';
    
    url2 += '&returnUrl='+getReturnUrl();
    url2 += '&menuId='+'${param.menuId}';        
	//검색값
    url2 += '&'+getSearchUrl();
    
    //key값
    url2 += '&adptrBzwkGroupName='+adptrGroupName;
  
	return   goNav(url2);
}

$(document).ready(function() {	
	
	init();	
	
	
    var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
    
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url, 
		postData : gridPostData,
		colNames:[
					'<%= localeMessage.getString("snaAdapterMan.adptGrpName")%>',
					'<%= localeMessage.getString("snaAdapterMan.ioType")%>',
					'<%= localeMessage.getString("snaAdapterMan.useYn")%>',
					'<%= localeMessage.getString("snaAdapterMan.apCode")%>'
                  ],
		colModel:[
				{ name : 'ADPTRBZWKGROUPNAME'   , align:'left'   	  },
				{ name : 'ADPTRIODSTCD'   		, align:'center'     ,width:70 },
				{ name : 'ADPTRUSEYN'       	, align:'center'     ,width:70 , formatter: formatterFunction},
				{ name : 'APPCODE'       		, align:'center'     ,width:100 , unfomatter : unformatterFunction, formatter: imgFormatterFunction, excelDown:'no'}
				],
        jsonReader: {
             repeatitems:false
        },	         
        pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		sortname : '${param.sortName}',
		sortorder : '${param.sortOrder}',
		rowList : eval('[${rmsDefaultRowList}]'),
		loadComplete:function (d){
	    	
	    },
	    loadError: function (jqXHR, textStatus, errorThrown) {
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	},
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
		
		},			
		ondblClickRow: function(rowId) {
			var rowData = $(this).getRowData(rowId); 
            var url2 = url_view;
            url2 += '?cmd=DETAIL';
            url2 += '&page='+$(this).getGridParam("page");
            url2 += '&returnUrl='+getReturnUrl();
            url2 += '&menuId='+'${param.menuId}';
        	url2 += '&sortName='+$("#grid").getGridParam("sortname");
        	url2 += '&sortOrder='+$("#grid").getGridParam("sortorder");            
			//검색값
            url2 += '&'+getSearchUrl();
            
            //key값
            url2 += '&adptrBzwkGroupName='+rowData['ADPTRBZWKGROUPNAME'];
            goNav(url2);
		}			
	});
	
	
	resizeJqGridWidth('grid','content_middle','1000');

	$("#btn_search").click(function(){
		list("1");
	});
	
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	
	
	$("#btn_excel").click(function(event) {
        event.stopPropagation(); // Do not propagate the event.
        // Create an object that will manage to download the file.
        var target = "excelDown" ; // iframe의 name
        //(url,cmd,gridObj,formObject,fileName,merge)
		gridToExcelSubmit2(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'<%= localeMessage.getString("snaAdapterMan.excelTitle")%>');
		return false;
	});
	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">
					<img src="<c:url value="/img/btn_excel.png"/>" id="btn_excel" level="R"/>
					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />
				</div>
				<div class="title"><%= localeMessage.getString("snaAdapterMan.title")%></div>
				<form id="ajaxForm"  onsubmit="return false;">
					<table class="search_condition" cellspacing=0;>
						<tbody>
							<tr>
								<th style="width:130px;"><%= localeMessage.getString("snaAdapterMan.useYn")%></th>
								<td>
									<div class="select-style">
										<select name="searchAdptrUseYn" value="${param.searchAdptrUseYn}">
										</select>
									</div>	
								</td>
								<th style="width:130px;"><%= localeMessage.getString("snaAdapterMan.adptGrpName")%></th>
								<td>
									<input type="text" name="searchAdptrBzwkGroupName" value="${param.searchAdptrBzwkGroupName}">
								</td>
							</tr>
						</tbody>
					</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

