<h2>Requests with $status status</h2>
<hr/>
<script>
var requests = $requests;
</script>

<div id="requests">

$filter_sort_table
<hr/>

<div id="container"></div>
</div> <!-- end of requests section -->

<script>
var _order=1; // global variable to keep track of asc/desc order on web UI
function BuildList(tag, data) {
    if(_order%2) {
        data.reverse();
    }
    _order += 1;
    var container = document.getElementById('container');
    container.innerHTML="";
    var listContainer = document.createElement('div');
    container.appendChild(listContainer);
    var listElement = document.createElement("ul");
    listContainer.appendChild(listElement);
    data.forEach(function(item) {
        var html = '<div>';
        var rid = 'request-'+item.RequestName;
        html += '<b>Request:</b> <span class="record"><a href="$base/fetch?rid='+rid+'">'+item.RequestName+'</a></span><br/>';
        html += '<b>Status:</b> <span style="color:'+genColor(item.RequestStatus)+';background-color:#fff;padding:3px;">'+item.RequestStatus+'</span>&nbsp;';
        html += '<b>Date:</b> <code>'+item.RequestDate+'</code>&nbsp;';
        html += '<b>User:</b> '+item.Requestor+'&nbsp;';
        html += '<b>Group:</b> '+item.Group+'&nbsp;';
        html += '<b>Campaign:</b> '+item.Campaign;
        html += '</div><hr/>'
        var listItem = document.createElement("li");
        listItem.innerHTML = html;
        listElement.appendChild(listItem);
    });
    // change CSS
    var items = document.getElementsByClassName('menu-item');
    for (var i = 0; i < items.length; i++ ) {
        items[i].className='menu-item';
    }
    tag.className='menu-item underline';
}
// Put data into container
BuildList(document.getElementsByClassName('menu-item')[0], requests.filter(FilterPattern).sort(ByDate));
</script>
