94 lines
No EOL
3.8 KiB
HTML
94 lines
No EOL
3.8 KiB
HTML
<html><head><title>DataField.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>DataField.js</h1><pre class="highlighted"><code>Ext.data.Field = <b>function</b>(config){
|
|
<b>if</b>(typeof config == "string"){
|
|
config = {name: config};
|
|
}
|
|
Ext.apply(<b>this</b>, config);
|
|
|
|
<b>if</b>(!<b>this</b>.type){
|
|
<b>this</b>.type = "auto";
|
|
}
|
|
|
|
<b>var</b> st = Ext.data.SortTypes;
|
|
<i>// named sortTypes are supported, here we look them up</i>
|
|
<b>if</b>(typeof <b>this</b>.sortType == "string"){
|
|
<b>this</b>.sortType = st[<b>this</b>.sortType];
|
|
}
|
|
|
|
<i>// set <b>default</b> sortType <b>for</b> strings and dates</i>
|
|
<b>if</b>(!<b>this</b>.sortType){
|
|
<b>switch</b>(this.type){
|
|
<b>case</b> "string":
|
|
<b>this</b>.sortType = st.asUCString;
|
|
<b>break</b>;
|
|
<b>case</b> "date":
|
|
<b>this</b>.sortType = st.asDate;
|
|
<b>break</b>;
|
|
<b>default</b>:
|
|
<b>this</b>.sortType = st.none;
|
|
}
|
|
}
|
|
|
|
<i>// define once</i>
|
|
<b>var</b> stripRe = /[\$,%]/g;
|
|
|
|
<i>// prebuilt conversion <b>function</b> for <b>this</b> field, instead of</i>
|
|
<i>// switching every time we're reading a value</i>
|
|
<b>if</b>(!<b>this</b>.convert){
|
|
<b>var</b> cv, dateFormat = <b>this</b>.dateFormat;
|
|
<b>switch</b>(this.type){
|
|
<b>case</b> "":
|
|
<b>case</b> "auto":
|
|
<b>case</b> undefined:
|
|
cv = <b>function</b>(v){ <b>return</b> v; };
|
|
<b>break</b>;
|
|
<b>case</b> "string":
|
|
cv = <b>function</b>(v){ <b>return</b> String(v); };
|
|
<b>break</b>;
|
|
<b>case</b> "int":
|
|
cv = <b>function</b>(v){
|
|
<b>return</b> v !== undefined && v !== null && v !== '' ?
|
|
parseInt(String(v).replace(stripRe, ""), 10) : '';
|
|
};
|
|
<b>break</b>;
|
|
<b>case</b> "float":
|
|
cv = <b>function</b>(v){
|
|
<b>return</b> v !== undefined && v !== null && v !== '' ?
|
|
parseFloat(String(v).replace(stripRe, ""), 10) : '';
|
|
};
|
|
<b>break</b>;
|
|
<b>case</b> "bool":
|
|
<b>case</b> "boolean":
|
|
cv = <b>function</b>(v){ <b>return</b> v === true || v === "true" || v == 1; };
|
|
<b>break</b>;
|
|
<b>case</b> "date":
|
|
cv = <b>function</b>(v){
|
|
<b>if</b>(!v){
|
|
<b>return</b> '';
|
|
}
|
|
<b>if</b>(v instanceof Date){
|
|
<b>return</b> v;
|
|
}
|
|
<b>if</b>(dateFormat){
|
|
<b>if</b>(dateFormat == "timestamp"){
|
|
<b>return</b> new Date(v*1000);
|
|
}
|
|
<b>return</b> Date.parseDate(v, dateFormat);
|
|
}
|
|
<b>var</b> parsed = Date.parse(v);
|
|
<b>return</b> parsed ? <b>new</b> Date(parsed) : null;
|
|
};
|
|
<b>break</b>;
|
|
|
|
}
|
|
<b>this</b>.convert = cv;
|
|
}
|
|
};
|
|
|
|
Ext.data.Field.prototype = {
|
|
dateFormat: null,
|
|
defaultValue: "",
|
|
mapping: null,
|
|
sortType : null,
|
|
sortDir : "ASC"
|
|
};</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
|
|
</body></html> |