}
-function totalByIndex(selector, prevUntil, prevAll) {
+function totalByIndex(selector, accessor) {
+ /*
+ aelector: the element where to display costs, and from which the index will be calculated.
+ accessor: a function to get all items that will be part of the total.
+ */
$(selector).each(function(){
var subtot = 0;
var i = $(this).index();
- if (prevUntil !== undefined && prevUntil !== null && prevUntil !== false) {
- var prevs = $(this).parent('tr').prevUntil(prevUntil);
- } else if (prevAll !== undefined && prevAll !== null && prevAll !== false) {
- var prevs = $(this).parent('tr').prevAll(prevAll);
- }
+ var prevs = accessor($(this));
prevs.each(function(){
var cell = $($(this).children('td')[i]);
var val;
$('#global-cost input[type="text"]').each(function() {
remun_line($(this));
});
- totalByIndex('#global-cost td.sous-total', ':not(.calculable)', null)
- totalByIndex('#global-cost th.total', null, '.sous-totaux')
+ totalByIndex('#global-cost td.sous-total',
+ function(x){return x.parent('tr').prevUntil(':not(.calculable)')});
+ totalByIndex('#global-cost th.total',
+ function(x){return x.parent('tr').prevAll('.sous-totaux')});
}