{% load projecttags %}
<!-- component to display a generic table -->
    <script>
    function showhideTableColumn(clname, sh) {
        if (sh) $('.' + clname).show(100);
        else $('.' + clname).hide(100);

	// save cookie for all checkboxes
	save = '';
	$('.chbxtoggle').each(function() { if ($(this).attr('id') != undefined) { save += ';' + $(this).attr('id') +':'+ $(this).is(':checked')} })
	$.cookie('_displaycols_{{objectname}}',  save);
	save = '';
    }


    function filterTableRows(test) {
        if (test.length > 0) {
            var r = test.split(/[ ,]+/).map(function (e) { return new RegExp(e, 'i') });
            $('tr.data').map( function (i, el) {
                (! r.map(function (j) { return j.test($(el).html())}).reduce(function (c, p) { return c && p;} )) ? $(el).hide() : $(el).show();
            });
        } else
        {
            $('tr.data').show();
        }
    }
    </script>

<!-- control header -->
<div class="navbar">
    <div class="navbar-inner">
        <form class="navbar-search input-append pull-left" id="searchform">
	<div class="input-append" style="padding-right:1em">
            <input class="input-xxlarge" id="search" name="search" type="text" placeholder="Search {{objectname}}" value="{{request.GET.search}}"/>{% if request.GET.search %}<a href="javascript:$('#search').val('');searchform.submit()" class="add-on"><i class="icon-remove"></i></a>{%endif%}
	</div>
	    <input type="hidden" name="orderby" value="{{request.GET.orderby}}">
	    <input type="hidden" name="page" value="1">
            <input class="btn" type="submit" value="Search"/>
        </form>
        <div class="pull-right">
{% if tablecols %}
            <div class="btn-group">
                <button class="btn dropdown-toggle" data-toggle="dropdown">Edit columns
                    <span class="caret"></span>
                </button>
<!--
	{{tablecols|sortcols}}
-->
                <ul class="dropdown-menu">{% for i in tablecols|sortcols %}
                    <li>
                        <label class="checkbox">
                            <input type="checkbox" class="chbxtoggle" {% if i.clclass %}id="{{i.clclass}}" value="ct{{i.name}}" {% if not i.hidden %}checked="checked"{%endif%} onchange="showhideTableColumn($(this).attr('id'), $(this).is(':checked'))" {%else%} checked disabled{% endif %}/>   {{i.name}}
                        </label>
                    </li>{% endfor %}
                </ul>
            </div>
{% endif %}
            <div style="display:inline">
                <span class="divider-vertical"></span>
                <span class="help-inline" style="padding-top:5px;">Show rows:</span>
                <select style="margin-top:5px;margin-bottom:0px;" class="pagesize">
  {% with "2 5 10 25 50 100" as list%}
{% for i in list.split %}                    <option{%if i == request.GET.count %} selected{%endif%}>{{i}}</option>
    {% endfor %}
  {% endwith %}
                </select>
           </div>
        </div>
    </div> <!-- navbar-inner -->
</div>

<!-- the actual rows of the table -->
    <table class="table table-bordered table-hover tablesorter" id="otable">
    <thead>
        <!-- Table header row; generated from "tablecols" entry in the context dict -->
        <tr>
            {% for tc in tablecols %}<th class="{{tc.dclass}} {{tc.clclass}}">
                {%if tc.qhelp%}<i class="icon-question-sign get-help" data-toggle="tooltip" title="{{tc.qhelp}}"></i>{%endif%}
                {%if tc.orderfield%}<a {%if tc.ordericon%} class="sorted" {%endif%}href="javascript:reload_params({'orderby' : '{{tc.orderfield}}' })" >{{tc.name}}</a>{%else%}<span class="muted">{{tc.name}}</span>{%endif%}
                {%if tc.ordericon%} <i class="icon-caret-{{tc.ordericon}}"></i>{%endif%}
                {%if tc.filter%}<div class="btn-group pull-right">
                    <a href="#filter_{{tc.filter.class}}" role="button" class="btn btn-mini {%if request.GET.filter%}{{tc.filter.options|filtered_icon:request.GET.filter}} {%endif%}" {%if request.GET.filter%} title="{{tc.filter.options|filtered_tooltip:request.GET.filter}}"{%endif%} data-toggle="modal"> <i class="icon-filter filtered"></i> </a>
                </div>{%endif%}
            </th>{% endfor %}
        </tr>
    </thead>
    <tbody>

