<%@ 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/common/serverMan.json" />';
var url_view = '<c:url value="/onl/admin/common/serverMan.view" />';
var url_excel = '<c:url value="/onl/admin/common/serverMan.excel" />';
var $Grid ={};

function openSocketMonitoringPage(url) {	
	var w = parent.window.open(url, "Socket Monitoring"); //, "width=1280,height=1024,left=0,top=0,menubar=yes,location=yes,scrollbars=yes,resizable=yes,status=yes"
	w.focus();
}

function formatterFunction(cellvalue, options, rowObject) {
	var rowId = options["rowId"];
	var route = rowObject['CLOUDROUTERURL'];
	var ipPort = cellvalue.split(":");
	if(cellvalue != '') {
		return "Open : <a href='javascript:openSocketMonitoringPage(\"http://"+cellvalue+"/\")'>"+
					+ ipPort[1]  + "</a>";
	}
	else {
		return "";
	}
}
function formatterFunction2(cellvalue, options, rowObject) {
	var route = rowObject['CLOUDROUTERURL'];
	var ip = rowObject['EAISEVRIP'];
	var ipPort = cellvalue;
	if(cellvalue != '*') {
		if(route != null) {
			return "Open : <a href='http://"+route+":"+ipPort+"' target='_blank'>"+ ipPort  + "</a>";
		}
		else {
			return "Open : <a href='http://"+ip+":"+ipPort+"' target='_blank'>"+ ipPort  + "</a>";
		}	
	}
	else {
		return "";
	}
}

function unformatterFunction(cellvalue, options, rowObject) {
	return "";
}

$(document).ready(function() {	
	$Grid = $('#grid');
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,		
		colNames:['<%= localeMessage.getString("server.instncName") %>',
                  '<%= localeMessage.getString("server.ip") %>',
                  '<%= localeMessage.getString("server.port") %>',
                  '<%= localeMessage.getString("server.flovrsevrName") %>',
                  '<%= localeMessage.getString("server.hostname") %>',
                  'Paas Router Url',
                  '<%= localeMessage.getString("server.socketmonitoring") %>'
                  ],
		colModel:[ 
				{ name : 'EAISEVRINSTNCNAME', align:'left' , sortable:false, width:70 },
				{ name : 'EAISEVRIP',         align:'center', width:70 },
				{ name : 'SEVRLSNPORTNAME',   align:'center', width:70 , unformat : unformatterFunction,  formatter : formatterFunction2},
				{ name : 'FLOVRSEVRNAME',     align:'center', width:70 },
				{ name : 'HOSTNAME',          align:'center', width:70 },
				{ name : 'CLOUDROUTERURL',    align:'center'  },
				{ name : 'SOCKETPORT',        align:'center', unformat : unformatterFunction,  formatter : formatterFunction, width:70}
				],
		          
        jsonReader: {
             repeatitems:false
        },	          
		pager : $('#pager'),		
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		rowList : eval('[${rmsDefaultRowList}]'),		
		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 eaiSevrInstncName = rowData['EAISEVRINSTNCNAME'];
            var url2 = url_view;
            url2 += '?cmd=DETAIL';
            url2 += '&page='+$(this).getGridParam("page");
            url2 += '&returnUrl='+getReturnUrl();
            url2 += '&menuId='+'${param.menuId}';
			//검색값
            //
            //key값
            url2 += '&eaiSevrInstncName='+eaiSevrInstncName;
            goNav(url2);
            
        }
	});
	
	resizeJqGridWidth('grid','content_middle','1000');
	
	$("#btn_search").click(function(){
		var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
		$("#grid").setGridParam({ postData: postData ,page : "1"  }).trigger("reloadGrid");
	});
	$("#btn_new").click(function(){
		var url2 = url_view;
		url2 += '?cmd=DETAIL';
		url2 += '&page='+$("#grid").getGridParam("page");
		url2 += '&returnUrl='+getReturnUrl();
        url2 += '&menuId='+'${param.menuId}';
		//검색값
        //url = url + '&'+getSearchUrl();
		
        goNav(url2);
	});
	$("#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"),'server');
		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">
					<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_new" level="W" ><i class="material-icons">add</i> <%= localeMessage.getString("button.new") %></button>
<%-- 					<img src="<c:url value="/img/btn_excel.png"/>" id="btn_excel" 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("server.title") %><span class="tooltip"><%= localeMessage.getString("server.tooltip") %></span></div>

				<table id="grid" ></table>
				<div id="pager"></div>				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

