aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toaster/toastergui/templates/basetable_top.html
blob: 1231e1f92415e9ce7ab38a773ccb038169f6e62c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{% load projecttags %}
<!-- component to display a generic table -->
    <script>

    //
    // most of the following javascript is for managing the 'Edit Columns'
    // pop-up dialog and actions. the idea is that there are 2 types
    // of actions: immediate - performed while the dialog is still
    // visible - hide/show columns, and delayed - performed when the
    // dialog becomes invisible - any resorting if necessary.
    //
    // When the dialog is open, an interval timer is set up to
    // determine if the dialog is still visible. when the dialog
    // closes - goes invisible, the delayed actions are performed.
    //
    // the interval timer and interrupt handler is a way of simulating
    // an onclose event. there is probably a simpler way to do this
    // however the pop-up window id was elusive.
    //

    var editColTimer;
    var editColAction;

    //
    // this is the target function of the interval timeout.
    // check to see if the dialog is visible. if the dialog
    // has gone invisible since the last check, take any delayed
    // actions indicated in the action list and clear the timer.
    //

    function checkVisible( ) {
        editcol = document.getElementById( 'editcol' );
        if ( editcol.offsetWidth <= 0 ) {
            clearInterval( editColTimer );
            editColTimer = false;
            hideshowColumns( );
            editColAction = [ ];
        }
    }

    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();
        }
    }

    //
    // determine the value of the indicated url arg.
    // this is needed to determine whether a resort
    // is necessary. it looks like a lot of gorp stuff
    // but its actually pretty simple.
    //

    function getURLParameter( name ) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' +
          '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g,
          '%20'))||null
    }

    //
    // when the dialog box goes invisible
    // this function is called to interpret
    // the action list and take any delayed actions necessary.
    // the editColAction list is a hash table with
    // the column name as the hash key, the hash value
    // is a 2 element list. the first element is a flag
    // indicating whether the column is on or off. the
    // 2nd element is the sort order indicator for the column.
    //

    function hideshowColumns( ) {
        for( var k in editColAction ) {
            showhideDelayedTableAction( k, editColAction[ k ][ 0 ], editColAction[ k ][ 1 ]);
        }
    }

    //
    // this function actually performs the delayed table actions
    // namely any resorting if necessary
    //

    function showhideDelayedTableAction( clname, sh, orderkey ) {
        if ( !sh ) {
            p = getURLParameter( "orderby" ).split( ":" )[ 0 ];
            if ( p == orderkey ) {
                reload_params({ 'orderby' : '{{default_orderby}}'});
            }
        }
    }

    //
    // this function actually performs the immediate table actions
    // namely any colums that need to be hidden/shown
    //

    function showhideImmediateTableAction( clname, sh, orderkey ) {
        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 = '';
    }

    //
    // this is the onclick handler for all of the check box
    // items in edit columns dialog
    //

    function showhideTableColumn( clname, sh, orderkey ) {
        editcol = document.getElementById( 'editcol' );
        if ( editcol.offsetWidth <= 0 ) {

            //
            // this path is taken when the page is first
            // getting initialized - no dialog visible,
            // perform both the immediate and delayed actions
            //

            showhideImmediateTableAction( clname, sh, orderkey );
            showhideDelayedTableAction( clname, sh, orderkey );
            return;
        }
        if ( !editColTimer ) {

            //
            // we don't have a timer active so set one up
            // and clear the action list
            //

            editColTimer = setInterval( checkVisible, 250 );
            editColAction = [ ];
        }

        //
        // save the action to be taken when the dialog closes
        //

        editColAction[ clname ] = [ sh, orderkey ];
        showhideImmediateTableAction( clname, sh, orderkey );
    }

    </script>

<!-- control header -->
<div class="navbar">
    <div class="navbar-inner">
        <form class="navbar-search input-append pull-left" id="searchform">
            <input class="input-xxlarge" id="search" name="search" type="text" placeholder="Search {%if object_search_display %}{{object_search_display}}{%else%}{{objectname}}{%endif%}" value="{{request.GET.search}}"/>{% if request.GET.search %}<a href="javascript:$('#search').val('');searchform.submit()" class="add-on btn" tabindex="-1"><i class="icon-remove"></i></a>{%endif%}
            <input type="hidden" name="orderby" value="{{request.GET.orderby}}">
            <input type="hidden" name="page" value="1">
            <button class="btn" type="submit" value="Search">Search</button>
        </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 id='editcol' class="dropdown-menu">
                  {% for i in tablecols|sortcols %}
                    <li>
                        <label {% if not i.clclass %} class="checkbox muted" {%else%} class="checkbox" {%endif%}>
                            <input type="checkbox" class="chbxtoggle"
                                   {% if i.clclass %}
                                       id="{{i.clclass}}"
                                       value="ct{{i.name}}"
                                       {% if not i.hidden %}
                                           checked="checked"
                                       {%endif%}
                                       onclick="showhideTableColumn(
                                           $(this).attr('id'),
                                           $(this).is(':checked'),
                                           '{{i.orderkey}}' )"
                                   {%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" title="{{tc.qhelp}}"></i>{%endif%}
                {%if tc.orderfield%}<a {%if tc.ordericon%} class="sorted" {%endif%}href="javascript:reload_params({'page': 1, '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 and tc.filter.options|filtered_tooltip:request.GET.filter %} title="<p>{{tc.filter.options|filtered_tooltip:request.GET.filter}}</p><p><a class='btn btn-small btn-primary' href=javascript:reload_params({'filter':''})>Show all {% if filter_search_display %}{{filter_search_display}}{% else %}{{objectname}}{% endif %}</a></p>" {%endif%} data-toggle="modal"> <i class="icon-filter filtered"></i> </a>
                </div>{%endif%}
            </th>{% endfor %}
        </tr>
    </thead>
    <tbody>