]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * @deprecated Please use {@link Ext.data.field.Field field types} instead.\r | |
3 | */\r | |
4 | Ext.define('Ext.data.Types', {\r | |
5 | singleton: true,\r | |
6 | requires: ['Ext.data.SortTypes']\r | |
7 | }, function(Types) {\r | |
8 | var SortTypes = Ext.data.SortTypes;\r | |
9 | \r | |
10 | Ext.apply(Types, {\r | |
11 | /**\r | |
12 | * @property {RegExp} stripRe\r | |
13 | * A regular expression for stripping non-numeric characters from a numeric value.\r | |
14 | * This should be overridden for localization.\r | |
15 | */\r | |
16 | stripRe: /[\$,%]/g,\r | |
17 | \r | |
18 | /**\r | |
19 | * @property {Object} AUTO\r | |
20 | * This data type means that no conversion is applied to the raw data before it is placed into a Record.\r | |
21 | */\r | |
22 | AUTO: {\r | |
23 | sortType: SortTypes.none,\r | |
24 | type: 'auto'\r | |
25 | },\r | |
26 | \r | |
27 | /**\r | |
28 | * @property {Object} STRING\r | |
29 | * This data type means that the raw data is converted into a String before it is placed into a Record.\r | |
30 | */\r | |
31 | STRING: {\r | |
32 | convert: function(v) {\r | |
33 | var defaultValue = this.getAllowNull() ? null : '';\r | |
34 | return (v === undefined || v === null) ? defaultValue : String(v);\r | |
35 | },\r | |
36 | sortType: SortTypes.asUCString,\r | |
37 | type: 'string'\r | |
38 | },\r | |
39 | \r | |
40 | /**\r | |
41 | * @property {Object} INT\r | |
42 | * This data type means that the raw data is converted into an integer before it is placed into a Record.\r | |
43 | *\r | |
44 | * The synonym `INTEGER` is equivalent.\r | |
45 | */\r | |
46 | INT: {\r | |
47 | convert: function(v) {\r | |
48 | // Handle values which are already numbers.\r | |
49 | // Value truncation behaviour of parseInt is historic and must be maintained.\r | |
50 | // parseInt(35.9) and parseInt("35.9") returns 35\r | |
51 | if (typeof v === 'number') {\r | |
52 | return parseInt(v, 10);\r | |
53 | }\r | |
54 | return v !== undefined && v !== null && v !== '' ?\r | |
55 | parseInt(String(v).replace(Types.stripRe, ''), 10) : (this.getAllowNull() ? null : 0);\r | |
56 | },\r | |
57 | sortType: SortTypes.none,\r | |
58 | type: 'int'\r | |
59 | },\r | |
60 | \r | |
61 | /**\r | |
62 | * @property {Object} FLOAT\r | |
63 | * This data type means that the raw data is converted into a number before it is placed into a Record.\r | |
64 | *\r | |
65 | * The synonym `NUMBER` is equivalent.\r | |
66 | */\r | |
67 | FLOAT: {\r | |
68 | convert: function(v) {\r | |
69 | if (typeof v === 'number') {\r | |
70 | return v;\r | |
71 | }\r | |
72 | return v !== undefined && v !== null && v !== '' ?\r | |
73 | parseFloat(String(v).replace(Types.stripRe, ''), 10) : (this.getAllowNull() ? null : 0);\r | |
74 | },\r | |
75 | sortType: SortTypes.none,\r | |
76 | type: 'float'\r | |
77 | },\r | |
78 | \r | |
79 | /**\r | |
80 | * @property {Object} BOOL\r | |
81 | * This data type means that the raw data is converted into a boolean before it is placed into\r | |
82 | * a Record. The string "true" and the number 1 are converted to boolean true.\r | |
83 | *\r | |
84 | * The synonym `BOOLEAN` is equivalent.\r | |
85 | */\r | |
86 | BOOL: {\r | |
87 | convert: function(v) {\r | |
88 | if (typeof v === 'boolean') {\r | |
89 | return v;\r | |
90 | }\r | |
91 | if (this.getAllowNull() && (v === undefined || v === null || v === '')) {\r | |
92 | return null;\r | |
93 | }\r | |
94 | return v === 'true' || v == 1;\r | |
95 | },\r | |
96 | sortType: SortTypes.none,\r | |
97 | type: 'bool'\r | |
98 | },\r | |
99 | \r | |
100 | /**\r | |
101 | * @property {Object} DATE\r | |
102 | * This data type means that the raw data is converted into a Date before it is placed into a Record.\r | |
103 | * The date format is specified in the constructor of the {@link Ext.data.Field} to which this type is\r | |
104 | * being applied.\r | |
105 | */\r | |
106 | DATE: {\r | |
107 | convert: function(v) {\r | |
108 | var df = this.getDateReadFormat() || this.getDateFormat(),\r | |
109 | parsed;\r | |
110 | \r | |
111 | if (!v) {\r | |
112 | return null;\r | |
113 | }\r | |
114 | // instanceof check ~10 times faster than Ext.isDate. Values here will not be cross-document objects\r | |
115 | if (v instanceof Date) {\r | |
116 | return v;\r | |
117 | }\r | |
118 | if (df) {\r | |
119 | return Ext.Date.parse(v, df);\r | |
120 | }\r | |
121 | \r | |
122 | parsed = Date.parse(v);\r | |
123 | return parsed ? new Date(parsed) : null;\r | |
124 | },\r | |
125 | sortType: SortTypes.asDate,\r | |
126 | type: 'date'\r | |
127 | }\r | |
128 | });\r | |
129 | \r | |
130 | /**\r | |
131 | * @property {Object} BOOLEAN\r | |
132 | * This data type means that the raw data is converted into a boolean before it is placed into\r | |
133 | * a Record. The string "true" and the number 1 are converted to boolean `true`.\r | |
134 | *\r | |
135 | * The synonym `BOOL` is equivalent.\r | |
136 | */\r | |
137 | Types.BOOLEAN = Types.BOOL;\r | |
138 | \r | |
139 | /**\r | |
140 | * @property {Object} INTEGER\r | |
141 | * This data type means that the raw data is converted into an integer before it is placed into a Record.\r | |
142 | *\r | |
143 | * The synonym `INT` is equivalent.\r | |
144 | */\r | |
145 | Types.INTEGER = Types.INT;\r | |
146 | \r | |
147 | /**\r | |
148 | * @property {Object} NUMBER\r | |
149 | * This data type means that the raw data is converted into a number before it is placed into a Record.\r | |
150 | *\r | |
151 | * The synonym `FLOAT` is equivalent.\r | |
152 | */\r | |
153 | Types.NUMBER = Types.FLOAT;\r | |
154 | });\r |