2017-04-19 06:16:37 +00:00
|
|
|
|
|
|
|
var VnObject = require ('./object');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Readable data model.
|
|
|
|
*/
|
|
|
|
var Klass = new Class ();
|
|
|
|
module.exports = Klass;
|
|
|
|
|
|
|
|
var Status =
|
|
|
|
{
|
|
|
|
CLEAN : 1
|
|
|
|
,LOADING : 2
|
|
|
|
,READY : 3
|
|
|
|
,ERROR : 4
|
|
|
|
};
|
|
|
|
|
|
|
|
var SortWay =
|
|
|
|
{
|
|
|
|
ASC : 1
|
|
|
|
,DESC : 2
|
|
|
|
};
|
|
|
|
|
|
|
|
Klass.extend
|
|
|
|
({
|
|
|
|
Status: Status
|
|
|
|
,SortWay: SortWay
|
|
|
|
});
|
|
|
|
|
|
|
|
Klass.implement
|
|
|
|
({
|
|
|
|
Extends: VnObject
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The number of rows in the model.
|
|
|
|
*/
|
|
|
|
numRows:
|
|
|
|
{
|
|
|
|
type: Number
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The current status of the model.
|
|
|
|
*/
|
|
|
|
status:
|
|
|
|
{
|
|
|
|
type: Number
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Checks if the model data is ready.
|
|
|
|
*/
|
|
|
|
ready:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the column exists.
|
|
|
|
*
|
|
|
|
* @param {integer} column The column index
|
2017-04-21 10:53:15 +00:00
|
|
|
* @return {boolean} %true if column exists, %false otherwise
|
2017-04-19 06:16:37 +00:00
|
|
|
*/
|
|
|
|
,checkColExists: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the row exists.
|
|
|
|
*
|
|
|
|
* @param {integer} rowIndex The row index
|
2017-04-21 10:53:15 +00:00
|
|
|
* @return {boolean} %true if row exists, %false otherwise
|
2017-04-19 06:16:37 +00:00
|
|
|
*/
|
|
|
|
,checkRowExists: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the index of the column from its name.
|
|
|
|
*
|
|
|
|
* @param {string} columnName The column name
|
|
|
|
* @return {number} The column index or -1 if column not exists
|
|
|
|
*/
|
|
|
|
,getColumnIndex: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value from the model.
|
|
|
|
*
|
|
|
|
* @param {number} rowIndex The row index
|
2017-04-21 10:53:15 +00:00
|
|
|
* @param {string} columnName The column name
|
2017-04-19 06:16:37 +00:00
|
|
|
* @return {*} The value, or %undefined
|
|
|
|
*/
|
|
|
|
,get: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value using the column index.
|
|
|
|
*
|
|
|
|
* @param {number} rowIndex The row index
|
|
|
|
* @param {number} column The column index
|
|
|
|
* @return {*} The value
|
|
|
|
*/
|
|
|
|
,getByIndex: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a row as an object using the column index.
|
|
|
|
*
|
|
|
|
* @param {number} rowIndex The row index
|
|
|
|
* @return {Object} The row as an object
|
|
|
|
*/
|
|
|
|
,getObject: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Orders the model by the specified column name.
|
|
|
|
*
|
2017-04-21 10:53:15 +00:00
|
|
|
* @param {number} column The column name
|
2017-04-19 06:16:37 +00:00
|
|
|
* @param {SortWay} way The sort way
|
|
|
|
*/
|
|
|
|
,sortByName: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Orders the model by the specified column.
|
|
|
|
*
|
2017-04-21 10:53:15 +00:00
|
|
|
* @param {number} column The column index
|
2017-04-19 06:16:37 +00:00
|
|
|
* @param {SortWay} way The sort way
|
|
|
|
*/
|
|
|
|
,sort: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searchs a value on the model and returns the row index of the first
|
|
|
|
* ocurrence.
|
|
|
|
* If an index have been built on that column, it will be used, for more
|
|
|
|
* information see the indexColumn() method.
|
|
|
|
*
|
2017-04-21 10:53:15 +00:00
|
|
|
* @param {string} column The column name
|
2017-04-19 06:16:37 +00:00
|
|
|
* @param {Object} value The value to search
|
2017-04-21 10:53:15 +00:00
|
|
|
* @return {number} The column index
|
2017-04-19 06:16:37 +00:00
|
|
|
*/
|
|
|
|
,search: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searchs a value on the model and returns the row index of the first
|
|
|
|
* ocurrence.
|
|
|
|
*
|
2017-04-21 10:53:15 +00:00
|
|
|
* @param {number} col The column index
|
2017-04-19 06:16:37 +00:00
|
|
|
* @param {Object} value The value to search
|
2017-04-21 10:53:15 +00:00
|
|
|
* @return {number} The column index
|
2017-04-19 06:16:37 +00:00
|
|
|
*/
|
|
|
|
,searchByIndex: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds an internal hash index for the specified column, this speeds
|
|
|
|
* significantly searches on that column, specially when model has a lot of
|
|
|
|
* rows.
|
|
|
|
*
|
|
|
|
* FIXME: Not fully implemented.
|
|
|
|
*
|
2017-04-21 10:53:15 +00:00
|
|
|
* @param {string} column The column name
|
2017-04-19 06:16:37 +00:00
|
|
|
*/
|
|
|
|
,indexColumn: function () {}
|
|
|
|
});
|
|
|
|
|