KanonConductor

changeset 56:bfd9bb1a175f

fixed QueryWebUiAddin(TimingAndEstimation plugin)
author kanu.orz
date Tue, 05 Apr 2011 21:12:45 +0900
parents 0f0c182b1bf3
children d39149910d35
files resource/trac-plugins/timingandestimationplugin/timingandestimationplugin/htdocs/query.js resource/trac-plugins/timingandestimationplugin/timingandestimationplugin/query_webui.py
diffstat 2 files changed, 75 insertions(+), 70 deletions(-) [+]
line diff
     1.1 --- a/resource/trac-plugins/timingandestimationplugin/timingandestimationplugin/htdocs/query.js	Tue Apr 05 18:45:35 2011 +0900
     1.2 +++ b/resource/trac-plugins/timingandestimationplugin/timingandestimationplugin/htdocs/query.js	Tue Apr 05 21:12:45 2011 +0900
     1.3 @@ -1,74 +1,79 @@
     1.4  (function(){
     1.5 -   function AddEventListener( elem, evt, func, capture){
     1.6 -      capture = capture || false;
     1.7 -      if(elem.addEventListener) elem.addEventListener( evt, func, capture);
     1.8 -      else elem.attachEvent('on'+evt, func);
     1.9 -      return func;
    1.10 -   };
    1.11 -   var InitQuery = function(){
    1.12 -      function createTableRow( numTds ){
    1.13 -	 var tr = document.createElement('tr');
    1.14 -	 var td = document.createElement('td');
    1.15 -	 td.style.backgroundColor="#EEF";
    1.16 -	 for(var i=0 ; i < numTds ; i++){
    1.17 -	    tr.appendChild(td.cloneNode(true));
    1.18 -	 }
    1.19 -	 return tr;
    1.20 -      }
    1.21 +	function AddEventListener( elem, evt, func, capture){
    1.22 +		capture = capture || false;
    1.23 +		if(elem.addEventListener) elem.addEventListener( evt, func, capture);
    1.24 +		else elem.attachEvent('on'+evt, func);
    1.25 +		return func;
    1.26 +	};
    1.27 +	var InitQuery = function(){
    1.28 +		function createTableRow( numTds ){
    1.29 +			var tr = document.createElement('tr');
    1.30 +			var td = document.createElement('td');
    1.31 +			td.style.backgroundColor="#EEF";
    1.32 +			for(var i=0 ; i < numTds ; i++){
    1.33 +				tr.appendChild(td.cloneNode(true));
    1.34 +			}
    1.35 +			return tr;
    1.36 +		}
    1.37  
    1.38 -      var _tbls = document.getElementsByTagName('table');
    1.39 -      var tbls = [], tbl, cell;
    1.40 -      // filter so that we only get ticket listing tables
    1.41 -      for(var i=0 ; tbl = _tbls[i] ; i++ ){
    1.42 -	 if(tbl.className == 'listing tickets') tbls.push(tbl);
    1.43 -      }
    1.44 +		var _tbls = document.getElementsByTagName('table');
    1.45 +		var tbls = [], tbl, cell;
    1.46 +		// filter so that we only get ticket listing tables
    1.47 +		for(var i=0 ; tbl = _tbls[i] ; i++ ){
    1.48 +			if(tbl.className == 'listing tickets') tbls.push(tbl);
    1.49 +		}
    1.50  
    1.51 -      // find numerical columns
    1.52 -      tbl = tbls[0];
    1.53 -      
    1.54 -      var cells = tbl.tBodies[0].rows[0].cells;
    1.55 -      var cellIdxs = [], columnNames = {};
    1.56 -      for(var i=0 ; cell = cells[i] ; i++ ){
    1.57 -	 if(cells[i].textContent!="" && !isNaN(Number(cells[i].textContent))){
    1.58 -	    cellIdxs.push(i);
    1.59 -	    if(tbl && tbl.tHead.rows.length > 0)
    1.60 -	       columnNames[i] = tbl.tHead.rows[0].cells[i].textContent;
    1.61 -	 }
    1.62 -      }
    1.63 +		// find numerical columns
    1.64 +		tbl = tbls[0];
    1.65  
    1.66 -      // total the numerical columns and add a total row to each table
    1.67 -      var totals, total_totals =[], idx;
    1.68 -      for(var i=0 ; tbl = tbls[i] ; i++ ){
    1.69 -	 totals = [];
    1.70 -	 for(var k=0 ; row = tbl.tBodies[0].rows[k] ; k++){
    1.71 -	    for(var j=0 ; idx = cellIdxs[j] ; j++){
    1.72 -	       if(totals[idx] == null) totals[idx] = 0;
    1.73 -	       if(total_totals[idx] == null) total_totals[idx] = 0;
    1.74 -	       if(row.cells[idx].textContent!="" && !isNaN(Number(row.cells[idx].textContent))){
    1.75 -		  var val = Number(row.cells[idx].textContent);
    1.76 -		  total_totals[idx] += val
    1.77 -                  totals[idx] += val;
    1.78 -	       }
    1.79 -	    }
    1.80 -	 }
    1.81 -	 if(tbl.tBodies[0].rows.length > 0){
    1.82 -	    var tr = createTableRow(tbl.tBodies[0].rows[0].cells.length);
    1.83 -	    for(var j=0 ; idx = cellIdxs[j] ; j++){
    1.84 -	       tr.cells[idx].appendChild(document.createTextNode(totals[idx])); 
    1.85 -	    }
    1.86 -	    tbl.tBodies[0].appendChild(tr);
    1.87 -	 }
    1.88 -      }
    1.89 -      // If we are grouping by things, we are going to want to add a complete total to the bottom
    1.90 -      if(tbls.length > 1){
    1.91 -	 var totalHtml = document.createElement('div');
    1.92 -	 totalHtml.style.backgroundColor="#EEF";
    1.93 -	 for(var j=0 ; idx = cellIdxs[j] ; j++){
    1.94 -	    totalHtml.appendChild(document.createTextNode("Total "+columnNames[idx]+": "+total_totals[idx])); 
    1.95 -	    totalHtml.appendChild(document.createElement('br'));
    1.96 -	 }
    1.97 -	 tbls[0].parentNode.appendChild(totalHtml);
    1.98 -      }
    1.99 -   }
   1.100 -   AddEventListener(window, 'load', InitQuery)
   1.101 +		var cells = tbl.tBodies[0].rows[0].cells;
   1.102 +		var cellIdxs = [], columnNames = {};
   1.103 +		for(var i=0 ; cell = cells[i] ; i++ ){
   1.104 +			if(cells[i].textContent!="" && !isNaN(Number(cells[i].textContent))){
   1.105 +				cellIdxs.push(i);
   1.106 +				if(tbl && tbl.tHead.rows.length > 0)
   1.107 +				 columnNames[i] = tbl.tHead.rows[0].cells[i].textContent;
   1.108 +			}
   1.109 +		}
   1.110 +
   1.111 +		// total the numerical columns and add a total row to each table
   1.112 +		var totals, total_totals =[], idx;
   1.113 +		for(var i=0 ; tbl = tbls[i] ; i++ ){
   1.114 +			totals = [];
   1.115 +			for(var l=0 ; bdy = tbl.tBodies[l] ; l++){
   1.116 +				for(var k=0 ; row = tbl.tBodies[l].rows[k] ; k++){
   1.117 +					if(row.className != 'trac-group' && row.className != 'trac-columns'){
   1.118 +						for(var j=0 ; idx = cellIdxs[j] ; j++){
   1.119 +							if(totals[idx] == null) totals[idx] = 0;
   1.120 +							if(total_totals[idx] == null) total_totals[idx] = 0;
   1.121 +							if(row.cells[idx].textContent!="" && !isNaN(Number(row.cells[idx].textContent))){
   1.122 +								var val = Number(row.cells[idx].textContent);
   1.123 +								total_totals[idx] += val
   1.124 +								totals[idx] += val;
   1.125 +							}
   1.126 +						}
   1.127 +					}
   1.128 +				}
   1.129 +				if(tbl.tBodies[l].rows.length > 0){
   1.130 +					if(tbl.tBodies[l].rows[0].className != 'trac-group' && tbl.tBodies[l].rows[0].className != 'trac-columns'){
   1.131 +						var tr = createTableRow(tbl.tBodies[l].rows[0].cells.length);
   1.132 +						for(var j=0 ; idx = cellIdxs[j] ; j++){
   1.133 +							tr.cells[idx].appendChild(document.createTextNode(totals[idx]));
   1.134 +							totals[idx] = 0;
   1.135 +						}
   1.136 +						tbl	.tBodies[l].appendChild(tr);
   1.137 +					}
   1.138 +				}
   1.139 +			}
   1.140 +		}
   1.141 +		// If we are grouping by things, we are going to want to add a complete total to the bottom
   1.142 +		var totalHtml = document.createElement('div');
   1.143 +		totalHtml.style.backgroundColor="#EEF";
   1.144 +		for(var j=0 ; idx = cellIdxs[j] ; j++){
   1.145 +			totalHtml.appendChild(document.createTextNode("Total "+columnNames[idx]+": "+total_totals[idx])); 
   1.146 +			totalHtml.appendChild(document.createElement('br'));
   1.147 +		}
   1.148 +		tbls[0].parentNode.appendChild(totalHtml);
   1.149 +	}
   1.150 +	AddEventListener(window, 'load', InitQuery)
   1.151  })()
     2.1 --- a/resource/trac-plugins/timingandestimationplugin/timingandestimationplugin/query_webui.py	Tue Apr 05 18:45:35 2011 +0900
     2.2 +++ b/resource/trac-plugins/timingandestimationplugin/timingandestimationplugin/query_webui.py	Tue Apr 05 21:12:45 2011 +0900
     2.3 @@ -10,6 +10,6 @@
     2.4  
     2.5      def post_process_request(self, req, template, data, content_type):
     2.6          if template == 'query.html':
     2.7 -            add_script(req, req.href.chrome("Billing/query.js"))        
     2.8 +            add_script(req, "Billing/query.js")
     2.9              
    2.10          return (template, data, content_type)