2018-02-14 12:50:56 +00:00
|
|
|
const number_format = require('./number_format');
|
2018-02-21 09:38:56 +00:00
|
|
|
const markdown = new (require('showdown').Converter)();
|
|
|
|
const moment = require('moment');
|
|
|
|
const frappe = require('frappejs');
|
2018-02-14 12:50:56 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
format(value, field) {
|
2018-02-21 09:38:56 +00:00
|
|
|
if (typeof field === 'string') {
|
|
|
|
field = {fieldtype: field};
|
|
|
|
}
|
|
|
|
|
2018-02-14 12:50:56 +00:00
|
|
|
if (field.fieldtype==='Currency') {
|
|
|
|
value = number_format.format_number(value);
|
2018-02-21 09:38:56 +00:00
|
|
|
|
|
|
|
} else if (field.fieldtype === 'Text') {
|
2018-03-05 16:45:21 +00:00
|
|
|
value = markdown.makeHtml(value || '');
|
2018-02-21 09:38:56 +00:00
|
|
|
|
|
|
|
} else if (field.fieldtype === 'Date') {
|
|
|
|
value = moment(value).format(frappe.SystemSettings.dateFormat.toUpperCase());
|
|
|
|
|
2018-02-14 12:50:56 +00:00
|
|
|
} else {
|
|
|
|
if (value===null || value===undefined) {
|
|
|
|
value = '';
|
|
|
|
} else {
|
|
|
|
value = value + '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|