2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
var Iterator = require('./iterator');
|
|
|
|
var Model = require('./model');
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
module.exports = new Class({
|
2015-07-03 05:49:45 +00:00
|
|
|
Extends: Vn.Object
|
2016-09-26 09:28:47 +00:00
|
|
|
,Implements: Iterator
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'db-form'
|
2022-05-28 15:49:46 +00:00
|
|
|
,Properties: {
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* The model associated to this form.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-05-28 15:49:46 +00:00
|
|
|
model: {
|
2016-09-26 09:28:47 +00:00
|
|
|
type: Model
|
2022-11-16 01:46:44 +00:00
|
|
|
,set(x) {
|
2022-05-28 15:49:46 +00:00
|
|
|
this.link({_model: x}, {
|
2015-01-23 13:09:30 +00:00
|
|
|
'status-changed': this.onModelChange
|
|
|
|
,'row-updated': this.onRowUpdate
|
|
|
|
});
|
|
|
|
}
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2015-01-23 13:09:30 +00:00
|
|
|
return this._model;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The row where the form positioned, has -1 if the row is unselected.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-05-28 15:49:46 +00:00
|
|
|
row: {
|
2015-01-23 13:09:30 +00:00
|
|
|
type: Number
|
2022-11-16 01:46:44 +00:00
|
|
|
,set(x) {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (!this._model || this._model.numRows <= x || x < -1)
|
|
|
|
x = -1;
|
|
|
|
if (x == this._row)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._row = x;
|
2022-05-28 15:49:46 +00:00
|
|
|
this.iterChanged();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2015-01-23 13:09:30 +00:00
|
|
|
return this._row;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The number of rows in the form.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-05-28 15:49:46 +00:00
|
|
|
numRows: {
|
2015-01-23 13:09:30 +00:00
|
|
|
type: Number
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (this._model)
|
|
|
|
return this._model.numRows;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Checks if the form data is ready.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-05-28 15:49:46 +00:00
|
|
|
ready: {
|
2015-01-23 13:09:30 +00:00
|
|
|
type: Boolean
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2015-01-23 13:09:30 +00:00
|
|
|
return this._ready;
|
|
|
|
}
|
2022-05-28 15:49:46 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The row object.
|
|
|
|
*/
|
|
|
|
$: {
|
|
|
|
type: Object
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2022-05-30 01:30:33 +00:00
|
|
|
return this._model && this._model.getObject(this._row);
|
2022-05-28 15:49:46 +00:00
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,lastRow: 0
|
|
|
|
,_model: null
|
|
|
|
,_row: -1
|
|
|
|
,_ready: false
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onModelChange() {
|
2015-01-23 13:09:30 +00:00
|
|
|
var ready = this._model && this._model.ready;
|
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
if (ready != this._ready) {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (this._row != -1)
|
|
|
|
this.lastRow = this._row;
|
|
|
|
|
|
|
|
this._ready = ready;
|
2022-05-30 01:30:33 +00:00
|
|
|
this.emit('status-changed');
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (this._row == -1)
|
|
|
|
this.row = this.lastRow;
|
2015-07-15 13:39:07 +00:00
|
|
|
|
|
|
|
if (ready)
|
2022-05-30 01:30:33 +00:00
|
|
|
this.emit('ready');
|
2016-05-04 14:36:51 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
this.iterChanged();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onRowUpdate(model, row) {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (row == this._row)
|
2022-05-28 15:49:46 +00:00
|
|
|
this.iterChanged();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|