// for license information please see license.txt
wn.provide("wn.form.formatters");
wn.form.formatters = {
Data: function(value) {
return value==null ? "" : value
},
Float: function(value, docfield) {
var decimals = wn.boot.sysdefaults.float_precision ?
parseInt(wn.boot.sysdefaults.float_precision) : null;
return "
" +
format_number(flt(value, decimals), null, decimals) + "
";
},
Int: function(value) {
return cint(value);
},
Currency: function(value, docfield, doc) {
var currency = wn.meta.get_field_currency(docfield, doc);
return "" + format_currency(value, currency) + "
";
},
Check: function(value) {
return value ? "" : "";
},
Link: function(value, docfield) {
if(!value) return "";
if(docfield && docfield.options) {
return repl('\
%(name)s', {
doctype: docfield.options,
name: value
});
} else {
return value;
}
},
Date: function(value) {
return dateutil.str_to_user(value);
},
Text: function(value) {
if(value) {
var tags = ["]>", "
]>", "
]>"];
var match = false;
for(var i=0; i'+v +'';
});
return html;
},
SmallText: function(value) {
return wn.form.formatters.Text(value);
},
WorkflowState: function(value) {
workflow_state = wn.model.get("Workflow State", value)[0];
if(workflow_state) {
return repl("\
%(value)s", {
value: value,
style: workflow_state.style.toLowerCase(),
icon: workflow_state.icon
});
} else {
return "" + value + "";
}
}
}
wn.form.get_formatter = function(fieldtype) {
return wn.form.formatters[fieldtype.replace(/ /g, "")] || wn.form.formatters.Data;
}
wn.format = function(value, df) {
if(!df) df = {"fieldtype":"Data"}
return wn.form.get_formatter(df.fieldtype)(value, df);
}