2015-01-23 13:09:30 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
var Iterator = require ('./iterator');
|
|
|
|
var Model = require ('./model');
|
|
|
|
|
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
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'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The model associated to this form.
|
|
|
|
**/
|
|
|
|
model:
|
|
|
|
{
|
2016-09-26 09:28:47 +00:00
|
|
|
type: Model
|
2015-01-23 13:09:30 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this.link ({_model: x},
|
|
|
|
{
|
|
|
|
'status-changed': this.onModelChange
|
|
|
|
,'row-updated': this.onRowUpdate
|
|
|
|
});
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._model;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The row where the form positioned, has -1 if the row is unselected.
|
|
|
|
**/
|
|
|
|
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;
|
|
|
|
this.iterChanged ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._row;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The number of rows in the form.
|
|
|
|
**/
|
|
|
|
numRows:
|
|
|
|
{
|
|
|
|
type: Number
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
if (this._model)
|
|
|
|
return this._model.numRows;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Checks if the form data is ready.
|
|
|
|
**/
|
|
|
|
ready:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._ready;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,lastRow: 0
|
|
|
|
,_model: null
|
|
|
|
,_row: -1
|
|
|
|
,_ready: false
|
|
|
|
|
|
|
|
,onModelChange: function ()
|
|
|
|
{
|
|
|
|
var ready = this._model && this._model.ready;
|
|
|
|
|
|
|
|
if (ready != this._ready)
|
|
|
|
{
|
|
|
|
if (this._row != -1)
|
|
|
|
this.lastRow = this._row;
|
|
|
|
|
|
|
|
this._ready = ready;
|
|
|
|
this.signalEmit ('status-changed');
|
|
|
|
|
|
|
|
if (this._row == -1)
|
|
|
|
this.row = this.lastRow;
|
2015-07-15 13:39:07 +00:00
|
|
|
|
|
|
|
if (ready)
|
|
|
|
this.signalEmit ('ready');
|
2016-05-04 14:36:51 +00:00
|
|
|
|
|
|
|
this.iterChanged ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,onRowUpdate: function (model, row, column)
|
|
|
|
{
|
|
|
|
if (row == this._row)
|
|
|
|
this.iterChanged ();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|