2015-01-23 13:09:30 +00:00
|
|
|
|
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
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
2017-04-24 07:47:56 +00:00
|
|
|
Extends: Iterator
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'db-form'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
model:
|
|
|
|
{
|
2017-05-22 07:08:21 +00:00
|
|
|
type: ModelIface
|
2015-01-23 13:09:30 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this.link ({_model: x},
|
|
|
|
{
|
|
|
|
'status-changed': this.onModelChange
|
2017-05-22 07:08:21 +00:00
|
|
|
,'row-updated': this.onModelRowUpdate
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
,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
|
|
|
*/
|
2015-01-23 13:09:30 +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 ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
,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);
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,onModelChange: function ()
|
|
|
|
{
|
|
|
|
var ready = this._model && this._model.ready;
|
|
|
|
|
2017-04-24 07:47:56 +00:00
|
|
|
if (ready != this._lastReady)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
if (this._row != -1)
|
2017-04-24 07:47:56 +00:00
|
|
|
this._lastRow = this._row;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2017-04-24 07:47:56 +00:00
|
|
|
this._lastReady = ready;
|
2017-04-19 06:16:37 +00:00
|
|
|
this.emit ('status-changed');
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
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');
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 07:08:21 +00:00
|
|
|
,onModelRowUpdate: function (model, row)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
if (row == this._row)
|
2017-05-11 15:38:31 +00:00
|
|
|
this.rowChanged();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|