<%+header%>

<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
        XHR.poll(10, '<%=luci.dispatcher.build_url("admin", "services", "modbus_master", "data_window")%>/get_data' + '/' + "dummy", null,
                                                                                                        
        function(x, mArray)                                                                    
                {                                                                        
                        var status = document.getElementById('data_text');   
                        if (mArray.modbus)                                                                                                      
                        {                                                                                                                       
                                status.innerHTML = String.format('%s', mArray.modbus[0]);                                                       
                        }                                                                                                                       
                        else                                                                                                                    
                        {                                                                                                                       
                                status.innerHTML = 'No information available';                                                                  
                        }                                                                                                                       
                }                                                                                                                               
        );     
    function showdata()
    {
        var group_num = document.getElementById("group_num").value;
        var stxhr = new XHR();
        stxhr.get('<%=luci.dispatcher.build_url("admin", "services", "modbus_master","data_window")%>/get_data' + '/' + group_num, null,
                                                                                             
                        function(x, mArray)                                                  
                        {        
                                var status = document.getElementById('data_text');               
                            if (mArray.modbus)                                               
                            {                                                                            
                                    status.innerHTML = String.format('%s', mArray.modbus[0]);        
                            }                                                                            
                            else                                                                         
                            {                                                                            
                                    status.innerHTML = 'No information available';                                    
                            }                                                                            
                        }                                                                                                     
               );    
        
    }
    function stop_start_data(val)                                                              
        {
		document.getElementById('start').disabled=true 
                var stxhr = new XHR();                                        
                stxhr.get('<%=luci.dispatcher.build_url("admin", "services", "modbus_master","data_window")%>/stop_start_data' + '/' +val, null,
                                                                                                                                                
                        function(x, mArray)                                                                                                     
                        {                                                                                                                       
                        }                                                                        
               );                                                                                
                                                                                                 
        } 
	function myFunction() {
		document.getElementById("start").disabled=false
	}
//]]></script>

<div id="data_window">
    <fieldset class="cbi-section">
       <input type="button" value="<%:Enable Data Window%>" class="cbi-button cbi-button-apply" id="start" onclick="stop_start_data('start'),setTimeout(myFunction, 320000);" /></br></br>
        Polling Group:</br>
        <select class="cbi-input-select" style="width: 100px;" id="group_num" name="group_num">                                                                                
            <option value="1" id=1>1</option>                                                                                                          
            <option value="2" id=2>2</option>
            <option value="3" id=3>3</option>
            <option value="4" id=4>4</option>
            <option value="5" id=5>5</option>
            <option value="6" id=6>6</option>
        </select>
        <input type="button" value="<%:Show Data%>" class="cbi-button cbi-button-apply" onclick="showdata()" /></br>
        </br>
        <textarea readonly  style="margin: 0px; width: 387px; height: 418px;"  rows="20" id="data_text">
                </textarea>
</table>
    </fieldset>
</div>
<%+footer%>
