hedera-web/js/db/iterator.js

134 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-07-03 05:49:45 +00:00
2022-05-24 10:18:44 +00:00
var Model = require('./model');
2016-09-26 09:28:47 +00:00
2022-05-24 10:18:44 +00:00
module.exports = new Class({
Properties: {
2015-07-03 05:49:45 +00:00
/**
* The model associated to this form.
2022-05-24 10:18:44 +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.
2022-05-24 10:18:44 +00:00
*/
row: {
2015-07-03 05:49:45 +00:00
type: Number
},
/**
* The number of rows in the form.
2022-05-24 10:18:44 +00:00
*/
numRows: {
2015-07-03 05:49:45 +00:00
type: Number
},
/**
* Checks if the form data is ready.
2022-05-24 10:18:44 +00:00
*/
ready: {
2015-07-03 05:49:45 +00:00
type: Boolean
2022-05-28 15:49:46 +00:00
},
/**
* The row object.
*/
$: {
type: Object
2015-07-03 05:49:45 +00:00
}
}
,_model: null
,_row: -1
2022-11-28 08:51:31 +00:00
,async refresh() {
2015-07-03 05:49:45 +00:00
if (this._model)
2022-11-28 08:51:31 +00:00
await this._model.refresh();
2015-07-03 05:49:45 +00:00
}
/**
2022-05-30 01:30:33 +00:00
* Emits the 'change' signal on the form.
2022-05-24 10:18:44 +00:00
*/
2022-11-16 01:46:44 +00:00
,iterChanged() {
2022-05-30 01:30:33 +00:00
this.emit('change');
2015-07-03 05:49:45 +00:00
}
/**
* 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
2022-05-24 10:18:44 +00:00
*/
2022-11-16 01:46:44 +00:00
,getColumnIndex(columnName) {
2015-07-03 05:49:45 +00:00
if (this._model)
2022-05-24 10:18:44 +00:00
return this._model.getColumnIndex(columnName);
2015-07-03 05:49:45 +00:00
return -1;
}
2022-11-16 01:46:44 +00:00
,insertRow() {
2015-07-03 05:49:45 +00:00
if (this._model)
2022-05-24 10:18:44 +00:00
this.row = this._model.insertRow();
2015-07-03 05:49:45 +00:00
}
2022-11-28 08:51:31 +00:00
,async performOperations() {
2015-07-03 05:49:45 +00:00
if (this._model)
2022-11-28 08:51:31 +00:00
await this._model.performOperations();
2015-07-03 05:49:45 +00:00
}
/**
* Removes the current row.
2022-05-24 10:18:44 +00:00
*/
2022-11-28 08:51:31 +00:00
,async deleteRow() {
2015-07-03 05:49:45 +00:00
if (this._row >= 0)
2022-11-28 08:51:31 +00:00
await this._model.deleteRow(this._row);
2015-07-03 05:49:45 +00:00
}
2022-05-24 10:18:44 +00:00
/**
* Gets the row as object.
*
* @return {Object} The row
*/
2022-11-16 01:46:44 +00:00
,getObject() {
2022-05-24 10:18:44 +00:00
return this._model.getObject(this._row);
}
2022-05-30 01:30:33 +00:00
/**
* Sets a value on the form.
*
* @param {String} columnName The column name
*/
2022-11-16 01:46:44 +00:00
,get(columnName) {
2022-05-30 01:30:33 +00:00
if (!this._model) return undefined;
return this._model.get(this._row, columnName);
}
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
2022-05-24 10:18:44 +00:00
*/
2022-11-28 08:51:31 +00:00
,async set(columnName, value) {
return await this._model.set(this._row, columnName, value);
2015-07-03 05:49:45 +00:00
}
/**
* Gets a value from the form using the column index.
*
* @param {String} columnName The column index
* @return {Object} The value
2022-05-24 10:18:44 +00:00
*/
2022-11-16 01:46:44 +00:00
,getByIndex(column) {
2022-05-24 10:18:44 +00:00
return this._model.getByIndex(this._row, column);
2015-07-03 05:49:45 +00:00
}
/**
* Sets a value on the form using the column index.
*
* @param {String} columnName The column index
* @param {Object} value The new value
2022-05-24 10:18:44 +00:00
*/
2022-11-16 01:46:44 +00:00
,setByIndex(column, value) {
2022-05-24 10:18:44 +00:00
return this._model.setByIndex(this._row, column, value);
2015-07-03 05:49:45 +00:00
}
});