/*! * Ext JS Library 3.2.1 * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ /** * @class Ext.data.Types *This is s static class containing the system-supplied data types which may be given to a {@link Ext.data.Field Field}.
*The properties in this class are used as type indicators in the {@link Ext.data.Field Field} class, so to * test whether a Field is of a certain type, compare the {@link Ext.data.Field#type type} property against properties * of this class.
*Developers may add their own application-specific data types to this class. Definition names must be UPPERCASE. * each type definition must contain three properties:
***
- *
convert
: FunctionA function to convert raw data values from a data block into the data * to be stored in the Field. The function is passed the collowing parameters: **
- v : Mixed
*The data value as read by the Reader, if undefined will use * the configured {@link Ext.data.Field#defaultValue defaultValue}.- rec : Mixed
*The data object containing the row as read by the Reader. * Depending on the Reader type, this could be an Array ({@link Ext.data.ArrayReader ArrayReader}), an object * ({@link Ext.data.JsonReader JsonReader}), or an XML element ({@link Ext.data.XMLReader XMLReader}).- *
sortType
: FunctionA function to convert the stored data into comparable form, as defined by {@link Ext.data.SortTypes}.- *
type
: StringA textual data type name.For example, to create a VELatLong field (See the Microsoft Bing Mapping API) containing the latitude/longitude value of a datapoint on a map from a JsonReader data block * which contained the properties
*lat
andlong
, you would define a new data type like this:*// Add a new Field data type which stores a VELatLong object in the Record. Ext.data.Types.VELATLONG = { convert: function(v, data) { return new VELatLong(data.lat, data.long); }, sortType: function(v) { return v.Latitude; // When sorting, order by latitude }, type: 'VELatLong' };
Then, when declaring a Record, use
* @singleton */ Ext.data.Types = new function(){ var st = Ext.data.SortTypes; Ext.apply(this, { /** * @type Regexp * @property stripRe * A regular expression for stripping non-numeric characters from a numeric value. Defaults to /[\$,%]/g. * This should be overridden for localization. */ stripRe: /[\$,%]/g, /** * @type Object. * @property AUTO * This data type means that no conversion is applied to the raw data before it is placed into a Record. */ AUTO: { convert: function(v){ return v; }, sortType: st.none, type: 'auto' }, /** * @type Object. * @property STRING * This data type means that the raw data is converted into a String before it is placed into a Record. */ STRING: { convert: function(v){ return (v === undefined || v === null) ? '' : String(v); }, sortType: st.asUCString, type: 'string' }, /** * @type Object. * @property INT * This data type means that the raw data is converted into an integer before it is placed into a Record. *var types = Ext.data.Types; // allow shorthand type access UnitRecord = Ext.data.Record.create([ { name: 'unitName', mapping: 'UnitName' }, { name: 'curSpeed', mapping: 'CurSpeed', type: types.INT }, { name: 'latitude', mapping: 'lat', type: types.FLOAT }, { name: 'latitude', mapping: 'lat', type: types.FLOAT }, { name: 'position', type: types.VELATLONG } ]);
The synonym
*/ INT: { convert: function(v){ return v !== undefined && v !== null && v !== '' ? parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10) : 0; }, sortType: st.none, type: 'int' }, /** * @type Object. * @property FLOAT * This data type means that the raw data is converted into a number before it is placed into a Record. *INTEGER
is equivalent.The synonym
*/ FLOAT: { convert: function(v){ return v !== undefined && v !== null && v !== '' ? parseFloat(String(v).replace(Ext.data.Types.stripRe, ''), 10) : 0; }, sortType: st.none, type: 'float' }, /** * @type Object. * @property BOOL *NUMBER
is equivalent.This data type means that the raw data is converted into a boolean before it is placed into * a Record. The string "true" and the number 1 are converted to boolean
*true
.The synonym
*/ BOOL: { convert: function(v){ return v === true || v === 'true' || v == 1; }, sortType: st.none, type: 'bool' }, /** * @type Object. * @property DATE * This data type means that the raw data is converted into a Date before it is placed into a Record. * The date format is specified in the constructor of the {@link Ext.data.Field} to which this type is * being applied. */ DATE: { convert: function(v){ var df = this.dateFormat; if(!v){ return null; } if(Ext.isDate(v)){ return v; } if(df){ if(df == 'timestamp'){ return new Date(v*1000); } if(df == 'time'){ return new Date(parseInt(v, 10)); } return Date.parseDate(v, df); } var parsed = Date.parse(v); return parsed ? new Date(parsed) : null; }, sortType: st.asDate, type: 'date' } }); Ext.apply(this, { /** * @type Object. * @property BOOLEAN *BOOLEAN
is equivalent.This data type means that the raw data is converted into a boolean before it is placed into * a Record. The string "true" and the number 1 are converted to boolean
*true
.The synonym
*/ BOOLEAN: this.BOOL, /** * @type Object. * @property INTEGER * This data type means that the raw data is converted into an integer before it is placed into a Record. *BOOL
is equivalent.The synonym
*/ INTEGER: this.INT, /** * @type Object. * @property NUMBER * This data type means that the raw data is converted into a number before it is placed into a Record. *INT
is equivalent.The synonym
*/ NUMBER: this.FLOAT }); };FLOAT
is equivalent.