source: timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/htdocs/query.js

Last change on this file was 17019, checked in by Russ Tyndall, 6 years ago

Fix extra footer TD by waiting a little before totalling. re #13270

File size: 1.8 KB
Line 
1function queryScreenTotaler(){
2  // Fields we will total
3  var columns = ['totalhours','estimatedhours'];
4  var tbodies = $('table.listing.tickets tbody.trac-query-results');
5  // console.log('Found ', tbodies.length, 'tables to sum');
6  var addFooter = false;
7  var totalsRowTemp = $('table.listing.tickets tbody.trac-query-results tr').first()
8        .clone().attr('class', 'total-row');
9  // Build footer row
10  $('td',totalsRowTemp).empty()
11    .css({'background-color':'#dde',
12          'text-align':'right',
13          'font-weight': 'bold',
14          'padding':'0.1em 0.5em',
15          'border':'1px solid #DDD'});
16
17  tbodies.each(function(idx, tbody){
18    // console.log('Handling tbody ', idx, 'kids:', $('tr', tbody).length);
19    tbody = $(tbody);
20    if(tbody.has('tr').length == 0) return true;
21    // true tfeet render at teh bottom
22    var tfoot = tbody.next('tbody.foot.totals');
23    if(tfoot.length==0){
24      tfoot = $('<tbody class="foot totals"></tbody>');
25    }
26    var totalsRow = $('.total-row', tfoot);
27    if(totalsRow.length == 0){
28      totalsRow = totalsRowTemp.clone();
29    }
30
31    $.each(columns,function(idx, field){
32      // count totals
33      var total = 0;
34      $('td.'+field, tbody).each(function(cidx, cell){
35    $(cell).css('text-align','right');
36    var val = Number($(cell).text());
37    if(!isNaN(val)) total += val;
38      });
39      //set total text in each footer row
40      if(!isNaN(total) && total ){
41        addFooter = true;
42        // console.log('Setting total', total,' tblIdx: ', idx, 'field:', field);
43        $('td.'+field,totalsRow).text(total.toString());
44      }
45    });
46    if(addFooter){
47      // console.log('Adding tfoot');
48      tbody.after(tfoot);
49      tfoot.append(totalsRow);
50    }
51  });
52};
53// queryScreenTotaler();
54$(document).ready(function(){window.setTimeout(queryScreenTotaler, 125);});
Note: See TracBrowser for help on using the repository browser.