2018-07-14 16:12:34 +00:00
|
|
|
const numberFormat = require('./numberFormat');
|
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') {
|
2018-06-25 07:49:11 +00:00
|
|
|
field = { fieldtype: field };
|
2018-02-21 09:38:56 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 07:49:11 +00:00
|
|
|
if (field.fieldtype === 'Currency') {
|
2018-07-14 16:12:34 +00:00
|
|
|
value = numberFormat.formatNumber(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') {
|
2018-04-14 19:14:02 +00:00
|
|
|
let dateFormat;
|
|
|
|
if (!frappe.SystemSettings) {
|
|
|
|
dateFormat = 'yyyy-mm-dd';
|
|
|
|
} else {
|
|
|
|
dateFormat = frappe.SystemSettings.dateFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = moment(value).format(dateFormat.toUpperCase());
|
2018-02-21 09:38:56 +00:00
|
|
|
|
2018-02-14 12:50:56 +00:00
|
|
|
} else {
|
2018-06-25 07:49:11 +00:00
|
|
|
if (value === null || value === undefined) {
|
2018-02-14 12:50:56 +00:00
|
|
|
value = '';
|
|
|
|
} else {
|
|
|
|
value = value + '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|