X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/530ef4b6c5b943cfa68b779d11cf7de29aa878bf..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/src/data/Types.js diff --git a/src/data/Types.js b/src/data/Types.js index e609991a..c9a6889f 100644 --- a/src/data/Types.js +++ b/src/data/Types.js @@ -1,12 +1,20 @@ -/*! - * Ext JS Library 3.2.1 - * Copyright(c) 2006-2010 Ext JS, Inc. - * licensing@extjs.com - * http://www.extjs.com/license - */ +/* + +This file is part of Ext JS 4 + +Copyright (c) 2011 Sencha Inc + +Contact: http://www.sencha.com/contact + +GNU General Public License Usage +This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + +If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. + +*/ /** * @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}.

+ *

This is a 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.

@@ -19,8 +27,8 @@ *
  • 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}).
  • + * Depending on the Reader type, this could be an Array ({@link Ext.data.reader.Array ArrayReader}), an object + * ({@link Ext.data.reader.Json JsonReader}), or an XML element. * *
  • sortType : Function
    A function to convert the stored data into comparable form, as defined by {@link Ext.data.SortTypes}.
  • *
  • type : String
    A textual data type name.
  • @@ -39,149 +47,162 @@ Ext.data.Types.VELATLONG = { type: 'VELatLong' }; - *

    Then, when declaring a Record, use

    
    + * 

    Then, when declaring a Model, use:

    
     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 }
    -]);
    +Ext.define('Unit',
    +    extend: 'Ext.data.Model',
    +    fields: [
    +        { name: 'unitName', mapping: 'UnitName' },
    +        { name: 'curSpeed', mapping: 'CurSpeed', type: types.INT },
    +        { name: 'latitude', mapping: 'lat', type: types.FLOAT },
    +        { name: 'longitude', mapping: 'long', type: types.FLOAT },
    +        { name: 'position', type: types.VELATLONG }
    +    ]
    +});
     
    * @singleton */ -Ext.data.Types = new function(){ +Ext.define('Ext.data.Types', { + singleton: true, + requires: ['Ext.data.SortTypes'] +}, function() { var st = Ext.data.SortTypes; - Ext.apply(this, { + + Ext.apply(Ext.data.Types, { /** - * @type Regexp - * @property stripRe + * @property {RegExp} 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 + * @property {Object} 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; }, + convert: function(v) { + return v; + }, sortType: st.none, type: 'auto' }, /** - * @type Object. - * @property STRING + * @property {Object} 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); }, + convert: function(v) { + var defaultValue = this.useNull ? null : ''; + return (v === undefined || v === null) ? defaultValue : String(v); + }, sortType: st.asUCString, type: 'string' }, /** - * @type Object. - * @property INT + * @property {Object} INT * This data type means that the raw data is converted into an integer before it is placed into a Record. *

    The synonym INTEGER is equivalent.

    */ INT: { - convert: function(v){ + convert: function(v) { return v !== undefined && v !== null && v !== '' ? - parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10) : 0; + parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0); }, sortType: st.none, type: 'int' }, - + /** - * @type Object. - * @property FLOAT + * @property {Object} FLOAT * This data type means that the raw data is converted into a number before it is placed into a Record. *

    The synonym NUMBER is equivalent.

    */ FLOAT: { - convert: function(v){ + convert: function(v) { return v !== undefined && v !== null && v !== '' ? - parseFloat(String(v).replace(Ext.data.Types.stripRe, ''), 10) : 0; + parseFloat(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0); }, sortType: st.none, type: 'float' }, - + /** - * @type Object. - * @property BOOL + * @property {Object} BOOL *

    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 is equivalent.

    */ BOOL: { - convert: function(v){ return v === true || v === 'true' || v == 1; }, + convert: function(v) { + if (this.useNull && (v === undefined || v === null || v === '')) { + return null; + } + return v === true || v === 'true' || v == 1; + }, sortType: st.none, type: 'bool' }, - + /** - * @type Object. - * @property DATE + * @property {Object} 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){ + convert: function(v) { + var df = this.dateFormat, + parsed; + + if (!v) { return null; } - if(Ext.isDate(v)){ + if (Ext.isDate(v)) { return v; } - if(df){ - if(df == 'timestamp'){ + if (df) { + if (df == 'timestamp') { return new Date(v*1000); } - if(df == 'time'){ + if (df == 'time') { return new Date(parseInt(v, 10)); } - return Date.parseDate(v, df); + return Ext.Date.parse(v, df); } - var parsed = Date.parse(v); + + parsed = Date.parse(v); return parsed ? new Date(parsed) : null; }, sortType: st.asDate, type: 'date' } }); - - Ext.apply(this, { + + Ext.apply(Ext.data.Types, { /** - * @type Object. - * @property BOOLEAN + * @property {Object} BOOLEAN *

    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 is equivalent.

    */ BOOLEAN: this.BOOL, + /** - * @type Object. - * @property INTEGER + * @property {Object} INTEGER * This data type means that the raw data is converted into an integer before it is placed into a Record. *

    The synonym INT is equivalent.

    */ INTEGER: this.INT, + /** - * @type Object. - * @property NUMBER + * @property {Object} NUMBER * This data type means that the raw data is converted into a number before it is placed into a Record. *

    The synonym FLOAT is equivalent.

    */ - NUMBER: this.FLOAT + NUMBER: this.FLOAT }); -}; \ No newline at end of file +}); +