0
1
Fork 0
hedera-web-mindshore/js/vn/form.js

85 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Iterator = require ('./iterator');
2017-05-22 07:08:21 +00:00
var ModelIface = require ('./model-iface');
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
2017-04-24 07:47:56 +00:00
Extends: Iterator
,Tag: 'db-form'
,Properties:
{
model:
{
2017-05-22 07:08:21 +00:00
type: ModelIface
,set: function (x)
{
this.link ({_model: x},
{
'status-changed': this.onModelChange
2017-05-22 07:08:21 +00:00
,'row-updated': this.onModelRowUpdate
});
}
,get: function ()
{
return this._model;
}
},
/**
* The row where the form positioned, has -1 if the row is unselected.
2016-12-20 09:32:17 +00:00
*/
row:
{
type: Number
,set: function (x)
{
if (!this._model || this._model.numRows <= x || x < -1)
x = -1;
if (x == this._row)
return;
this._row = x;
2017-05-22 07:08:21 +00:00
this.rowChanged ();
}
,get: function ()
{
return this._row;
}
}
}
2017-04-24 07:47:56 +00:00
,initialize: function (props)
{
Object.assign (this, {
_lastRow: 0
,_lastReady: false
});
this.parent (props);
}
,onModelChange: function ()
{
var ready = this._model && this._model.ready;
2017-04-24 07:47:56 +00:00
if (ready != this._lastReady)
{
if (this._row != -1)
2017-04-24 07:47:56 +00:00
this._lastRow = this._row;
2017-04-24 07:47:56 +00:00
this._lastReady = ready;
2017-04-19 06:16:37 +00:00
this.emit ('status-changed');
if (this._row == -1)
2017-04-24 07:47:56 +00:00
this.row = this._lastRow;
2015-07-15 13:39:07 +00:00
if (ready)
2017-04-19 06:16:37 +00:00
this.emit ('ready');
}
}
2017-05-22 07:08:21 +00:00
,onModelRowUpdate: function (model, row)
{
if (row == this._row)
2017-05-11 15:38:31 +00:00
this.rowChanged();
}
});