hedera-web/web/js/db/calc-sum.js

60 lines
810 B
JavaScript
Raw Normal View History

/**
* Computes a sum of data in the model.
**/
Db.CalcSum = new Class
({
Extends: Db.Calc
,Tag: 'db-calc-sum'
,getRowValue: function (row)
{
var value;
if (this._func)
{
this.form.row = row;
value = this._func (this.form);
}
else
value = this._model.getByIndex (row, this.columnIndex);
return value;
}
,before: function (row)
{
var value = this.getRowValue (row)
if (value !== null)
{
this.sum -= value;
this.numbersCount--;
}
}
,after: function (row)
{
var value = this.getRowValue (row);
if (value !== null)
{
this.sum += value;
this.numbersCount++;
}
}
,init: function ()
{
this.sum = 0;
this.numbersCount = 0;
}
,done: function ()
{
if (this.numbersCount > 0)
this.value = this.sum;
else
this.value = null;
}
});