0
1
Fork 0
hedera-web-mindshore/js/db/calc.js

155 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Model = require ('./model');
var SimpleIterator = require ('./simple-iterator');
/**
* Interface for handle foreach operations on the model.
2022-05-26 06:08:31 +00:00
*/
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
Extends: Vn.Param
,Tag: 'db-calc'
,Properties:
{
model:
{
2016-09-26 09:28:47 +00:00
type: Model
,set: function (x)
{
this.link ({_model: x},
{
'status-changed': this.onModelChange
,'row-deleted-before': this.onRowDeleteBefore
,'row-updated': this.onRowUpdate
,'row-updated-before': this.onRowUpdateBefore
,'row-inserted': this.onRowInsert
});
2016-09-26 09:28:47 +00:00
var set = new SimpleIterator ({model: x});
this.link ({_set: set});
}
,get: function ()
{
return this._model;
}
},
columnIndex:
{
type: Number
,set: function (x)
{
this.reset ();
this._columnIndex = x;
this.onModelChange ();
}
,get: function ()
{
return this._columnIndex;
}
},
columnName:
{
type: String
,set: function (x)
{
this.reset ();
this._columnName = x;
this.onModelChange ();
}
,get: function ()
{
return this._columnName;
}
},
func:
{
type: Function
,set: function (x)
{
this.reset ();
this._func = x;
this.onModelChange ();
}
,get: function ()
{
return this._func;
}
}
}
,_model: null
,reset: function ()
{
delete this._columnIndex;
delete this._columnName;
delete this._func;
}
,onModelChange: function ()
{
this.init ();
if (this._model)
{
if (this._model.ready && this._columnName)
this._columnIndex = this._model.getColumnIndex (this._columnName);
var rows = this._model.numRows;
for (var i = 0; i < rows; i++)
this.after (i);
}
this.done ();
}
,onRowInsert: function (model, row)
{
this.after (row);
this.done ();
}
,onRowUpdateBefore: function (model, row)
{
this.before (row);
}
,onRowUpdate: function (model, row)
{
this.after (row);
this.done ();
}
,onRowDeleteBefore: function (model, row)
{
this.before (row);
this.done ();
}
/**
* Called before each update or delete row operation.
* You don't need to define it if model isn't updatable.
*
* @param {integer} row The row number
2022-05-26 06:08:31 +00:00
*/
,before: function (row) {}
/**
* Called after each update or insert row operation.
*
* @param {integer} row The row number
2022-05-26 06:08:31 +00:00
*/
,after: function (row) {}
/**
* Called before each model refresh.
2022-05-26 06:08:31 +00:00
*/
,init: function () {}
/**
* Called when an operation in the model is complete.
2022-05-26 06:08:31 +00:00
*/
,done: function () {}
});