// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
// 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 = cint(docfield.options, null) || cint(wn.boot.sysdefaults.float_precision, null);
return "
" +
((value==null || value==="") ? "" :
format_number(value, null, decimals)) + "
";
},
Int: function(value) {
return value==null ? "": "" + cint(value) + "
";
},
Percent: function(value) {
return "" + flt(value, 2) + "%" + "
";
},
Currency: function(value, docfield, options, doc) {
var currency = wn.meta.get_field_currency(docfield, doc);
return "" + format_currency(value, currency) + "
";
},
Check: function(value) {
return value ? "" : "";
},
Link: function(value, docfield, options) {
if(options && options.for_print)
return value;
if(!value)
return "";
if(docfield && docfield.options) {
return repl('%(icon)s%(label)s', {
doctype: encodeURIComponent(docfield.options),
name: encodeURIComponent(value),
label: value,
icon: (options && options.no_icon) ? "" :
(' ')
});
} else {
return value;
}
},
Date: function(value) {
return value ? dateutil.str_to_user(value) : "";
},
Text: function(value) {
if(value) {
var tags = ["]>", "
]>", "
]>"];
var match = false;
for(var i=0; i
'+v +'';
});
return html;
},
Comment: function(value) {
var html = "";
$.each(JSON.parse(value || "[]"), function(i, v) {
if(v) html+= ''+v.comment+'';
});
return html;
},
SmallText: function(value) {
return wn.form.formatters.Text(value);
},
TextEditor: function(value) {
return wn.form.formatters.Text(wn.utils.remove_script_and_style(value));
},
Code: function(value) {
return "" + (value==null ? "" : $("").text(value).html()) + ""
},
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) {
if(!fieldtype) fieldtype = "Data";
return wn.form.formatters[fieldtype.replace(/ /g, "")] || wn.form.formatters.Data;
}
wn.format = function(value, df, options, doc) {
if(!df) df = {"fieldtype":"Data"};
return wn.form.get_formatter(df.fieldtype)(value, df, options, doc);
}