<%@ page import="java.io.*, java.util.*"%>
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="com.eactive.eai.common.routing.RoutingManager"%>
<%@ page import="com.eactive.eai.common.routing.RoutingVO"%>

<%
    RoutingManager   manager   = RoutingManager.getInstance();
    String[]         alls      = manager.getAllRoutingNames();
    String           action    = request.getParameter("actionType");

    String selectedKey = request.getParameter("selectedKey");
    if(selectedKey == null && alls.length>=1) {
    	selectedKey = alls[0];
    }
    if ("reload".equals(action)){
    	manager.reload(selectedKey);
    }else if ("reloadAll".equals(action)){
    	manager.reload();
    }else {
    	;
    }
    RoutingVO vo = null;
    
    if(selectedKey != null){ 
    	vo = manager.getRoutingVO(selectedKey);
    }
%>

<html>
    <head>
        <title>
            Routing Manager
        </title>
        <script>
        function doAction() {
            document.frm.submit();
        }
        
        function managerReload(){ 
        	document.frm.actionType.value="reload";
        	document.frm.submit();
        	
        }
        function managerReloadAll(){
        	document.frm.actionType.value="reloadAll";
        	document.frm.submit();
        }
        function doSearch(){
        	var searchValue = document.frm.searchTxt.value;
        	document.frm.selectedKey.value = searchValue;
        	document.frm.submit();
        }
        function enterEvent(){
        	if(window.event.keyCode==13){
        		doSearch();
        	}
        }
        </script>
    </head>
    <body>
        <p style="font-size:12pt;">
        <b>라우팅 관리</b> <br><br>
        </p>
        <form name="frm" action="">
        <input type="hidden" name="actionType" value="">
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td rowspan=2 align='right' width='350' bgcolor="#ccccff">라우팅명 :&nbsp;&nbsp;</td>
            <td align='left'>&nbsp;<select name="selectedKey" onchange="doAction();" style="width:98%">
            <%
                for(int i=0;i<alls.length;i++) {
            %>
                <option value="<%=alls[i]%>" <%= (alls[i].equals(selectedKey)) ? "selected" : "" %>><%=alls[i]%>
            <%           
                }
            %></select>
            </td>
                  <td width='50'><input type="button" name="reload" value="reload" onClick="managerReload()" /></td>
            <td width='70'><input type="button" name="reloadAll" value="reloadAll" onClick="managerReloadAll()" /></td>
        
        </tr>
        <tr bgcolor='white'>
            <td align='left' >&nbsp;<input type="edit" style="width:98%;" name="searchTxt" onkeydown="enterEvent()" value="<%=selectedKey%>" style="width:98%" /></td> 
            <td colspan=2 align="center"><input type="button" name="search" value="search" onClick="doSearch()" /></td>
        </tr>
        </table><br>
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td align='right' colspan=2 bgcolor="#003366">&nbsp; <font color="yellow"><b>내용</b> &nbsp;</font></td>
        </tr>
<%
    if(vo != null) {
%>  
        <tr bgcolor='white'>                                                                                                                                                                
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 라우팅명 : &nbsp;</td>                                                                                              
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="name" style="width:98%" value="<%=vo.getName()%>" readonly></td>                                                              
        </tr>   
                
        <tr bgcolor='white'>                                                                                                                                                                
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 동기 라우팅 URI : &nbsp;</td>                                                                                              
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="syncRoutingPath" style="width:98%" value="<%=vo.getSyncRoutingPath()%>" ></td>                                                              
        </tr>    
                
        <tr bgcolor='white'>                                                                                                                                                                
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 비동기 라우팅 URI : &nbsp;</td>                                                                                              
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="asynRoutingPath" style="width:98%" value="<%=vo.getAsynRoutingPath()%>"></td>                                                              
        </tr>                   
        <tr bgcolor='white'>                                                                                                                                                                
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; 레이어구분코드 : &nbsp;</td>                                                                                              
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="asynRoutingPath" style="width:98%" value="<%=vo.getLayerDstcd()%>"></td>                                                              
        </tr> 
        

 <% 
    } 
%>    
        </table>
        </form>
    </body>
</html>