Changeset 7570

Show
Ignore:
Timestamp:
09/26/11 01:26:19 (20 months ago)
Author:
jow
Message:

applications/luci-ahcp: rework status javascript to use XHR.poll()

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/applications/luci-ahcp/luasrc/view/ahcp_status.htm

    r7560 r7570  
    11<script type="text/javascript">//<![CDATA[ 
    2     var stxhr = new XHR(); 
    3     (function() { 
    4         var func = arguments.callee; 
     2    XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "ahcpd", "status")%>', null, 
     3        function(x, st) 
     4        { 
     5            var tb = document.getElementById('ahcpd_status_table'); 
     6            var tx = document.getElementById('ahcpd_status_text'); 
     7            if (st && tb && tx) 
     8            { 
     9                /* clear all rows */ 
     10                while( tb.rows.length > 1 ) 
     11                    tb.deleteRow(1); 
    512 
    6         stxhr.get('<%=luci.dispatcher.build_url("admin", "network", "ahcpd", "status")%>', null, 
    7             function(x, st) 
    8             { 
    9                 var tb = document.getElementById('ahcpd_status_table'); 
    10                 var tx = document.getElementById('ahcpd_status_text'); 
    11                 if (st && tb && tx) 
     13                for( var i = 0; i < st.leases.length; i++ ) 
    1214                { 
    13                     /* clear all rows */ 
    14                     while( tb.rows.length > 1 ) 
    15                         tb.deleteRow(1); 
     15                    var tr = tb.insertRow(-1); 
     16                        tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); 
    1617 
    17                     for( var i = 0; i < st.leases.length; i++ ) 
    18                     { 
    19                         var tr = tb.insertRow(-1); 
    20                             tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); 
    21  
    22                         tr.insertCell(-1).innerHTML = st.leases[i].addr; 
    23                         tr.insertCell(-1).innerHTML = String.format('%t', st.leases[i].age); 
    24                     } 
    25  
    26                     if( tb.rows.length == 1 ) 
    27                     { 
    28                         var tr = tb.insertRow(-1); 
    29                             tr.className = 'cbi-section-table-row'; 
    30  
    31                         var td = tr.insertCell(-1); 
    32                             td.colSpan = 2; 
    33                             td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; 
    34                     } 
    35  
    36                     if( st.uid == '00:00:00:00:00:00:00:00' ) 
    37                         tx.innerHTML = 'The AHCP Service is not running.'; 
    38                     else 
    39                         tx.innerHTML = String.format('The AHCP Service is running with ID %s.', st.uid); 
     18                    tr.insertCell(-1).innerHTML = st.leases[i].addr; 
     19                    tr.insertCell(-1).innerHTML = String.format('%t', st.leases[i].age); 
    4020                } 
    4121 
    42                 window.setTimeout(func, 5000); 
     22                if( tb.rows.length == 1 ) 
     23                { 
     24                    var tr = tb.insertRow(-1); 
     25                        tr.className = 'cbi-section-table-row'; 
     26 
     27                    var td = tr.insertCell(-1); 
     28                        td.colSpan = 2; 
     29                        td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; 
     30                } 
     31 
     32                if( st.uid == '00:00:00:00:00:00:00:00' ) 
     33                    tx.innerHTML = 'The AHCP Service is not running.'; 
     34                else 
     35                    tx.innerHTML = String.format('The AHCP Service is running with ID %s.', st.uid); 
    4336            } 
    44         ) 
    45     })(); 
     37        } 
     38    ); 
    4639//]]></script> 
    4740