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

<%
    PropManager manager = PropManager.getInstance();
    String[]    alls    = manager.getAllPropGroupNames();
    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 {
    	;
    }
    
    PropGroupVO vo = null;
        
    String[] keys  = null;
    if(selectedKey!=null) {   
    	vo = manager.getPropGroupVO(selectedKey);
        keys = vo.keys();
    }
%>
<html>
    <head>
        <title>
            Property 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%>"  /></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' bgcolor="#003366">&nbsp; <font color="yellow"><b>Property Key</b> &nbsp;</font></td>
            <td align='left' bgcolor="#003366">&nbsp;<font color="yellow">&nbsp; <b>Property Value</b></font></td>
        </tr>
        <%
        if(vo!=null) {
            for (int i=0; i<keys.length; i++){
        %>
        <tr bgcolor='white'>
            <td align='right' width='360' bgcolor="#ccccff">&nbsp; <%=keys[i]%> : &nbsp;</td>
            <td align='left' style="height:40px;">&nbsp;<input type="text" name="<%=keys[i]%>" style="width:98%" value="<%=vo.getProperty(keys[i])%>"></td>
        </tr>
        <%
            }
        }
        %>
        </table>
        </form>
    </body>
</html>