2015-07-03 05:49:45 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
var Model = require ('./model');
|
|
|
|
|
|
|
|
module.exports = new Class
|
2015-07-03 05:49:45 +00:00
|
|
|
({
|
2017-04-08 11:42:27 +00:00
|
|
|
Implements: Vn.Lot
|
|
|
|
,Properties:
|
2015-07-03 05:49:45 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The model associated to this form.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
model:
|
|
|
|
{
|
2016-09-26 09:28:47 +00:00
|
|
|
type: Model
|
2015-07-03 05:49:45 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The row where the form positioned, has -1 if the row is unselected.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
row:
|
|
|
|
{
|
|
|
|
type: Number
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The number of rows in the form.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
numRows:
|
|
|
|
{
|
|
|
|
type: Number
|
|
|
|
},
|
2017-04-08 11:42:27 +00:00
|
|
|
/**
|
|
|
|
* The current row parameters.
|
|
|
|
*/
|
|
|
|
params:
|
|
|
|
{
|
|
|
|
type: Object
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this.assign (x);
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
var params = {};
|
|
|
|
var keys = this.keys ();
|
|
|
|
|
|
|
|
for (var i = 0; i < keys.length; i++)
|
|
|
|
{
|
|
|
|
var key = keys[i];
|
|
|
|
params[key] = this.get (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
},
|
2015-07-03 05:49:45 +00:00
|
|
|
/**
|
|
|
|
* Checks if the form data is ready.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
ready:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_model: null
|
|
|
|
,_row: -1
|
|
|
|
|
|
|
|
,refresh: function ()
|
|
|
|
{
|
|
|
|
if (this._model)
|
|
|
|
this._model.refresh ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the index of the column from its name.
|
|
|
|
*
|
|
|
|
* @param {String} columnName The column name
|
|
|
|
* @return {integer} The column index or -1 if column not exists
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
,getColumnIndex: function (columnName)
|
|
|
|
{
|
|
|
|
if (this._model)
|
|
|
|
return this._model.getColumnIndex (columnName);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
,insertRow: function ()
|
|
|
|
{
|
|
|
|
if (this._model)
|
|
|
|
this.row = this._model.insertRow ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,performOperations: function ()
|
|
|
|
{
|
|
|
|
if (this._model)
|
|
|
|
this._model.performOperations ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the current row.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
,deleteRow: function ()
|
|
|
|
{
|
|
|
|
if (this._row >= 0)
|
|
|
|
this._model.deleteRow (this._row);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value from the form.
|
|
|
|
*
|
|
|
|
* @param {String} columnName The column name
|
|
|
|
* @return {Object} The value
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
,get: function (columnName)
|
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
if (this._model)
|
|
|
|
return this._model.get (this._row, columnName);
|
|
|
|
|
|
|
|
return undefined;
|
2015-07-03 05:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a value on the form.
|
|
|
|
*
|
|
|
|
* @param {String} columnName The column name
|
|
|
|
* @param {Object} value The new value
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
,set: function (columnName, value)
|
|
|
|
{
|
|
|
|
return this._model.set (this._row, columnName, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value from the form using the column index.
|
|
|
|
*
|
|
|
|
* @param {String} columnName The column index
|
|
|
|
* @return {Object} The value
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
,getByIndex: function (column)
|
|
|
|
{
|
|
|
|
return this._model.getByIndex (this._row, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a value on the form using the column index.
|
|
|
|
*
|
|
|
|
* @param {String} columnName The column index
|
|
|
|
* @param {Object} value The new value
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-03 05:49:45 +00:00
|
|
|
,setByIndex: function (column, value)
|
|
|
|
{
|
|
|
|
return this._model.setByIndex (this._row, column, value);
|
|
|
|
}
|
2017-03-30 11:44:53 +00:00
|
|
|
|
|
|
|
,keys: function ()
|
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
if (this._model && this._model.ready)
|
2017-03-30 11:44:53 +00:00
|
|
|
return Object.keys (this._model.columnMap);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
2017-04-08 11:42:27 +00:00
|
|
|
|
|
|
|
,getParams: function ()
|
|
|
|
{
|
|
|
|
var params = {};
|
|
|
|
var keys = this.keys ();
|
|
|
|
|
|
|
|
for (var i = 0; i < keys.length; i++)
|
|
|
|
{
|
|
|
|
var key = keys[i];
|
|
|
|
params[key] = this.get (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
2015-07-03 05:49:45 +00:00
|
|
|
});
|
|
|
|
|