/****************************************************************
*****************************************************************/
if (!AW.JSON) {AW.JSON = {}}
AW.JSON.Table = AW.HTTP.Request.subclass();
AW.JSON.Table.create = function(){
/****************************************************************
Table model for loading and parsing data in JSON text format.
*****************************************************************/
var obj = this.prototype;
var _super = this.superclass.prototype;
/****************************************************************
Allows to process the received text.
@param text (String) The downloaded text.
*****************************************************************/
obj.response = function(text){
this._data = eval('(' + text + ')');
if (this.$owner) {
this.$owner.clearSelectionModel();
this.$owner.clearSortModel();
this.$owner.clearRowModel();
this.$owner.setRowCount(this.getCount());
this.$owner.refresh();
}
// _super.response.call(this);
};
obj._data = [];
obj._formats = [];
/****************************************************************
Allows to specify the formatting object for the column.
@param format (Object) The formatting object.
@param index (Index) The column index.
*****************************************************************/
obj.setFormat = function(format, index){
this._formats = this._formats.concat();
this._formats[index] = format;
};
/****************************************************************
Allows to specify the formatting objects for each column.
@param formats (Array) The array of formatting objects.
*****************************************************************/
obj.setFormats = function(formats){
this._formats = formats;
};
/****************************************************************
Returns the number of data rows.
*****************************************************************/
obj.getCount = function(){
return this._data.length;
};
/****************************************************************
Returns the index.
*****************************************************************/
obj.getIndex = function(i){
return i;
};
/****************************************************************
Returns the cell text.
@param r (Index) Row index.
@param c (Index) Column index.
*****************************************************************/
obj.getData = function(c, r){
return this._data[r][c];
};
/****************************************************************
Returns the cell text.
@param i (Index) Row index.
@param j (Index) Column index.
*****************************************************************/
obj.getText = function(i, j){
var data = this.getData(i, j);
var format = this._formats[i];
return format ? format.dataToText(data) : data;
};
/****************************************************************
Returns the cell image.
@param i (Index) Row index.
@param j (Index) Column index.
*****************************************************************/
obj.getImage = function(){
return "";
};
/****************************************************************
Returns the cell hyperlink.
@param i (Index) Row index.
@param j (Index) Column index.
*****************************************************************/
obj.getLink = function(){
return "";
};
/****************************************************************
Returns the cell value.
@param i (Index) Row index.
@param j (Index) Column index.
*****************************************************************/
obj.getValue = function(i, j){
var data = this.getData(i, j) || "";
var format = this._formats[i];
return format ? format.dataToValue(data) : data;
};
};
This topic is archived.