forked from verdnatura/hedera-web
213 lines
3.5 KiB
JavaScript
Executable File
213 lines
3.5 KiB
JavaScript
Executable File
|
|
Db.Form = new Class
|
|
({
|
|
Extends: Vn.Object
|
|
,Tag: 'db-form'
|
|
,Child: 'model'
|
|
,Properties:
|
|
{
|
|
/**
|
|
* The model associated to this form.
|
|
**/
|
|
model:
|
|
{
|
|
type: Db.Model
|
|
,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;
|
|
}
|
|
}
|
|
|
|
,onRowUpdate: function (model, row, column)
|
|
{
|
|
if (row == this._row)
|
|
this.iterChanged ();
|
|
}
|
|
|
|
,refresh: function ()
|
|
{
|
|
if (this._model)
|
|
this._model.refresh ();
|
|
}
|
|
|
|
/**
|
|
* Emits the 'iter-changed' signal on the form.
|
|
**/
|
|
,iterChanged: function ()
|
|
{
|
|
this.signalEmit ('iter-changed');
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
**/
|
|
,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.
|
|
**/
|
|
,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
|
|
**/
|
|
,get: function (columnName)
|
|
{
|
|
return this._model.get (this._row, columnName);
|
|
}
|
|
|
|
/**
|
|
* Sets a value on the form.
|
|
*
|
|
* @param {String} columnName The column name
|
|
* @param {Object} value The new value
|
|
**/
|
|
,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
|
|
**/
|
|
,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
|
|
**/
|
|
,setByIndex: function (column, value)
|
|
{
|
|
return this._model.setByIndex (this._row, column, value);
|
|
}
|
|
|
|
/**
|
|
* Gets a param from the form.
|
|
*
|
|
* @param {String} columnName The column name
|
|
* @return {Db.Param} The new parameter
|
|
**/
|
|
,getParam: function (columnName)
|
|
{
|
|
return new Db.Param
|
|
({
|
|
form: this
|
|
,column: columnName
|
|
});
|
|
}
|
|
});
|
|
|