<%@ 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" %>
<%@ page import="com.eactive.eai.common.util.SystemUtil"%>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>
<%
	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/messageKeyMan.json" />';
var url_view = '<c:url value="/onl/admin/adapter/messageKeyMan.view" />';
var url_excel= '<c:url value="/onl/admin/adapter/messageKeyMan.excel"/>';
var roleString	= "<%=SessionManager.getRoleIdString(request)%>";
var devSvr		= <%=SystemUtil.isDevServer()%>;

function init(){
	$.ajax({
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=searchIoDstcd]")).setData(json.exrTypeRows).setNoValueInclude(true).setFormat(codeName3OptionFormat).rendering();
// 			new makeOptions("CODE","NAME").setObj($("select[name=searchEaiSevrDstcd]")).setData(json.sevrTypeRows).setNoValueInclude(true).setFormat(codeName3OptionFormat).rendering();
			putSelectFromParam();
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}

$(document).ready(function() {	
	var gridPostData = getSearchForJqgrid("cmd","LIST_GROUP"); //jqgrid에서는 object 로 

	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,
		colNames:['<%= localeMessage.getString("messageKey.adptrBzwkGroupName")%> ',
                  '<%= localeMessage.getString("messageKey.msgDstCd")%>',
                  '<%= localeMessage.getString("messageKey.ioDstCd")%>',
                  '<%= localeMessage.getString("messageKey.ioDstCd")%>',
                  '<%= localeMessage.getString("messageKey.groupInorNo")%>',
                  '<%= localeMessage.getString("messageKey.bzwkFldName")%>', 
                  '<%= localeMessage.getString("messageKey.nomalPrcssCtnt")%>',
                  ],
		colModel:[
				{ name : 'ADPTRBZWKGROUPNAME'   , align:'left'	,sortable:false  },
				{ name : 'MSGDSTCD'             , align:'center'  ,width:50},
				{ name : 'IODSTCD'              , hidden : true},
				{ name : 'IODSTCDTEXT'              , align:'left'  ,width:80},
				{ name : 'GROUPINORNO'          , align:'center'    ,width:50},
				{ name : 'BZWKFLDNAMETEXT'          , align:'left'  ,width:300},				
				{ name : 'NOMALPRCSSCTNT'   	, align:'center'  ,width:50}
				],
        jsonReader: {
             repeatitems:false, 
        },	          
		pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		multiselect: true,
		multiboxonly: false,
		rowList : eval('[${rmsDefaultRowList}]'),
		loadComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});
			}
		},
	  	loadError: function (jqXHR, textStatus, errorThrown) {
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	},			
		ondblClickRow: function(rowId) {
			var rowData = $(this).getRowData(rowId); 
            var url2 = url_view;
            var ioDstcd = rowData['IODSTCD'];
            url2 += '?cmd=DETAIL';
            url2 += '&page='+$(this).getGridParam("page");
            url2 += '&returnUrl='+getReturnUrl();
            url2 += '&menuId='+'${param.menuId}';
			//검색값
            url2 += '&'+getSearchUrl();
            //key값
            url2 += '&adptrBzwkGroupName='+rowData['ADPTRBZWKGROUPNAME'];
            url2 += '&msgDstcd='+rowData['MSGDSTCD'];
            url2 += '&ioDstcd='+ioDstcd;
            url2 += '&groupInorNo='+rowData['GROUPINORNO'];

            goNav(url2);
        }		
	});
	
	
	resizeJqGridWidth('grid','content_middle','1000');
	$("#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("messageKey.title")%>');
		return false;
	});
	$("#btn_search").click(function(){
		var postData = getSearchForJqgrid("cmd","LIST_GROUP"); //jqgrid에서는 object 로 
		$("#grid").setGridParam({ postData: postData ,page : "1"  }).trigger("reloadGrid");
	});
	$("#btn_new").click(function(){
		var url2 = url_view;
		url2 += '?cmd=NEW';
		url2 += '&page='+$("#grid").getGridParam("page");
		url2 += '&returnUrl='+getReturnUrl();
        url2 += '&menuId='+'${param.menuId}';
		//검색값
        url2 += '&'+getSearchUrl();
		
        goNav(url2);
	});
	
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	$("#btn_initialize").click(function(){
		$.ajax({  
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'INITIALIZES'},
			success:function(json){
				alert(json.message);
			},
			error:function(e){
				alert(e.responseText);
			}
		});		
		
	});
	
	$('#btn_clone').click(onclickBtnClone);
	
	init();
	buttonControl();
/*	
	if(devSvr){
		setBtnHide(roleString, "admin", "btn_clone");
	}else{
		setBtnHide(roleString, " ", "btn_clone");
	}
*/
	//모든조건에서 안보이게
	setBtnHide(" ", "admin", "btn_clone");
});

function onclickBtnClone() {
	var sel = $('#grid').jqGrid('getGridParam', 'selarrrow');
	if (sel.length == 0) {
		alert('<%=localeMessage.getString("eaiMessage.alert17")%>');
		return;
	}
	if(!confirm("기능구분, 그룹 상관없이 어댑터명 별로 메시지키 전체가 넘어갑니다.")){
		return;
	}
	var selectedAdapterNames = [];
	$(sel).each(function(index, i) {
		var adapterName = $('#grid').getCell(i, 'ADPTRBZWKGROUPNAME');
		selectedAdapterNames.push(adapterName);
	});
	
	var args = new Object();
	var url2 = '<c:url value="/onl/admin/adapter/adapterMan.view" />';
	url2 += '?cmd=POPUP CALENDAR';
	args['selectedAdapterName'] = selectedAdapterNames.join(',');
	showModal(url2,args,540,200, 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;
	    cloneToProd(args.returnValue);
	});
}
function cloneToProd(ret) {
	var params = ret;
	params['cmd'] = 'CLONETOPROD'; 
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:params,
		success:function(json){
			alert(json.message);
		},
		error:function(xhr,status,error){
			if (xhr.responseText != null) {
				try {
					alert(JSON.parse(xhr.responseText).errorMsg);	
				} catch (e) {
					alert(error);
				}
			}
		}
	});	
}
</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">
					<button type="button" class="cssbtn" id="btn_excel" level="W"><i class="material-icons">table_view</i> <%= localeMessage.getString("button.excel") %></button>
					<button type="button" class="cssbtn" id="btn_initialize" level="W"><i class="material-icons">restart_alt</i> <%= localeMessage.getString("button.reset") %></button>
					<button type="button" class="cssbtn" id="btn_new" level="W"><i class="material-icons">add</i> <%= localeMessage.getString("button.new") %></button>
					<button type="button" class="cssbtn" id="btn_search" level="R"><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %></button>
					<img src="<c:url value="/img/btn_clone.png"/>" alt="" id="btn_clone"  level="W" style="height:32px;"/>
<%-- 					<img src="<c:url value="/img/btn_excel.png"/>" id="btn_excel" level="W"/> --%>
<%-- 					<img src="<c:url value="/img/btn_initialize.png"/>" alt="" id="btn_initialize" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_new.png"/>" alt="" id="btn_new" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />		 --%>
				</div>
				<div class="title"><%= localeMessage.getString("messageKey.title")%></div>
				<form id="ajaxForm" onsubmit="return false;">
					<table class="search_condition" cellspacing=0;>
						<tbody>
							<tr>
								<th style="width:10%;"><%= localeMessage.getString("messageKey.adptrBzwkGroupName")%></th>
								<td style="width:40%;">
									<input type="text" name="searchAdptrBzwkGroupName" value="${param.searchAdptrBzwkGroupName}">
								</td>
								<th style="width:10%;"><%= localeMessage.getString("messageKey.ioDstCd")%></th>
								<td style="width:40%;">
									<div class="select-style">
										<select name="searchIoDstcd" value="${param.searchIoDstcd}">
										</select>
									</div>
								</td>	
								<!--  
								<th style="width:150px;">서버구분코드</th>
								<td>
									<div class="select-style">
										<select name="searchEaiSevrDstcd" value="${param.searchEaiSevrDstcd}" style="width: 100%;">
										</select>
									</div>
								</td>
								-->					
							</tr>						
						</tbody>
					</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

