DataField_wev8.js
3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
// private
// Field objects are not intended to be created directly, but are created
// behind the scenes when defined for Record objects. See Record_wev8.js for details.
Ext.data.Field = function(config){
if(typeof config == "string"){
config = {name: config};
}
Ext.apply(this, config);
if(!this.type){
this.type = "auto";
}
var st = Ext.data.SortTypes;
// named sortTypes are supported, here we look them up
if(typeof this.sortType == "string"){
this.sortType = st[this.sortType];
}
// set default sortType for strings and dates
if(!this.sortType){
switch(this.type){
case "string":
this.sortType = st.asUCString;
break;
case "date":
this.sortType = st.asDate;
break;
default:
this.sortType = st.none;
}
}
// define once
var stripRe = /[\$,%]/g;
// prebuilt conversion function for this field, instead of
// switching every time we're reading a value
if(!this.convert){
var cv, dateFormat = this.dateFormat;
switch(this.type){
case "":
case "auto":
case undefined:
cv = function(v){ return v; };
break;
case "string":
cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
break;
case "int":
cv = function(v){
return v !== undefined && v !== null && v !== '' ?
parseInt(String(v).replace(stripRe, ""), 10) : '';
};
break;
case "float":
cv = function(v){
return v !== undefined && v !== null && v !== '' ?
parseFloat(String(v).replace(stripRe, ""), 10) : '';
};
break;
case "bool":
case "boolean":
cv = function(v){ return v === true || v === "true" || v == 1; };
break;
case "date":
cv = function(v){
if(!v){
return '';
}
if(Ext.isDate(v)){
return v;
}
if(dateFormat){
if(dateFormat == "timestamp"){
return new Date(v*1000);
}
if(dateFormat == "time"){
return new Date(parseInt(v, 10));
}
return Date.parseDate(v, dateFormat);
}
var parsed = Date.parse(v);
return parsed ? new Date(parsed) : null;
};
break;
}
this.convert = cv;
}
};
Ext.data.Field.prototype = {
dateFormat: null,
defaultValue: "",
mapping: null,
sortType : null,
sortDir : "ASC"
};