2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
var Calc = require ('./calc');
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* Computes a sum of data in the model.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Calc
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'db-calc-sum'
|
|
|
|
|
|
|
|
,getRowValue: function (row)
|
|
|
|
{
|
|
|
|
var value;
|
|
|
|
|
|
|
|
if (this._func)
|
|
|
|
{
|
2016-05-05 15:47:45 +00:00
|
|
|
this._set.row = row;
|
|
|
|
value = this._func (this._set);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
value = this._model.getByIndex (row, this.columnIndex);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
,before: function (row)
|
|
|
|
{
|
|
|
|
var value = this.getRowValue (row)
|
|
|
|
|
|
|
|
if (value !== null)
|
2016-05-06 12:09:15 +00:00
|
|
|
this._sum -= value;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,after: function (row)
|
|
|
|
{
|
|
|
|
var value = this.getRowValue (row);
|
|
|
|
|
|
|
|
if (value !== null)
|
2016-05-06 12:09:15 +00:00
|
|
|
this._sum += value;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,init: function ()
|
|
|
|
{
|
2016-05-06 12:09:15 +00:00
|
|
|
this._sum = 0;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,done: function ()
|
|
|
|
{
|
2016-05-06 12:09:15 +00:00
|
|
|
this.value = this._sum;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|