* Parse a value into a formatted date using the specified format pattern.
* @param {String/Date} value The value to format (Strings must conform to the format expected by the javascript Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method)
* @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
* @return {String} The formatted date string
*/
date : function(v,format){
if(!v){
return"";
}
if(!Ext.isDate(v)){
v=newDate(Date.parse(v));
}
returnv.dateFormat(format||"m/d/Y");
},
/**
* Returns a date rendering function that can be reused to apply a date format multiple times efficiently
* @param {String} format Any valid date format string
* @return {Function} The date formatting function
*/
dateRenderer : function(format){
returnfunction(v){
returnExt.util.Format.date(v,format);
};
},
/**
* Strips all HTML tags
* @param {Mixed} value The text from which to strip tags
* @return {String} The stripped text
*/
stripTags : function(v){
return!v ? v : String(v).replace(stripTagsRE,"");
},
/**
* Strips all script tags
* @param {Mixed} value The text from which to strip script tags
* @return {String} The stripped text
*/
stripScripts : function(v){
return!v ? v : String(v).replace(stripScriptsRe,"");
},
/**
* Simple format for a file size (xxx bytes, xxx KB, xxx MB)
* @param {Number/String} size The numeric value to format
* @return {String} The formatted file size
*/
fileSize : function(size){
if(size<1024){
returnsize+" bytes";
}elseif(size<1048576){
return(Math.round(((size*10)/1024))/10)+" KB";
}else{
return(Math.round(((size*10)/1048576))/10)+" MB";
}
},
/**
* It does simple math for use in a template, for example:<pre><code>
* var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
* </code></pre>
* @return {Function} A function that operates on the passed value.
*/
math : function(){
varfns={};
returnfunction(v,a){
if(!fns[a]){
fns[a]=newFunction('v','return v '+a+';');
}
returnfns[a](v);
};
}(),
/**
* Rounds the passed number to the required decimal precision.
* @param {Number/String} value The numeric value to round.
* @param {Number} precision The number of decimal places to which to round the first parameter's value.
* @return {Number} The rounded value.
*/
round : function(value,precision){
varresult=Number(value);
if(typeofprecision=='number'){
precision=Math.pow(10,precision);
result=Math.round(value*precision)/precision;
}
returnresult;
},
/**
* Formats the number according to the format string.