2022-05-30 01:30:33 +00:00
|
|
|
|
|
|
|
var Iterator = require('./iterator');
|
|
|
|
var ModelIface = require('./model-iface');
|
|
|
|
|
|
|
|
module.exports = new Class({
|
|
|
|
Extends: Iterator
|
|
|
|
,Tag: 'db-form'
|
|
|
|
,Properties: {
|
|
|
|
model: {
|
|
|
|
type: ModelIface
|
2022-11-16 01:46:44 +00:00
|
|
|
,set(x) {
|
2022-05-30 01:30:33 +00:00
|
|
|
this.link({_model: x},
|
|
|
|
{
|
|
|
|
'status-changed': this.onModelChange
|
|
|
|
,'row-updated': this.onModelRowUpdate
|
|
|
|
});
|
|
|
|
}
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2022-05-30 01:30:33 +00:00
|
|
|
return this._model;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The row where the form positioned, has -1 if the row is unselected.
|
|
|
|
*/
|
|
|
|
row: {
|
|
|
|
type: Number
|
2022-11-16 01:46:44 +00:00
|
|
|
,set(x) {
|
2022-05-30 01:30:33 +00:00
|
|
|
if (!this._model || this._model.numRows <= x || x < -1)
|
|
|
|
x = -1;
|
|
|
|
if (x == this._row)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._row = x;
|
|
|
|
this.rowChanged();
|
|
|
|
}
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2022-05-30 01:30:33 +00:00
|
|
|
return this._row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,initialize(props) {
|
2022-05-30 01:30:33 +00:00
|
|
|
Object.assign(this, {
|
|
|
|
_lastRow: 0
|
|
|
|
,_lastReady: false
|
|
|
|
});
|
2022-06-06 16:02:17 +00:00
|
|
|
Iterator.prototype.initialize.call(this, props);
|
2022-05-30 01:30:33 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onModelChange() {
|
2022-05-30 01:30:33 +00:00
|
|
|
var ready = this._model && this._model.ready;
|
|
|
|
|
|
|
|
if (ready != this._lastReady) {
|
|
|
|
if (this._row != -1)
|
|
|
|
this._lastRow = this._row;
|
|
|
|
|
|
|
|
this._lastReady = ready;
|
|
|
|
this.emit('status-changed');
|
|
|
|
|
|
|
|
if (this._row == -1)
|
|
|
|
this.row = this._lastRow;
|
|
|
|
|
|
|
|
if (ready)
|
|
|
|
this.emit('ready');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onModelRowUpdate(model, row) {
|
2022-05-30 01:30:33 +00:00
|
|
|
if (row == this._row)
|
|
|
|
this.rowChanged();
|
|
|
|
}
|
|
|
|
});
|