fix: handle msgprint html on client side

This commit is contained in:
Saqib Ansari 2020-10-14 21:35:58 +05:30
parent 350bc0258f
commit d04e6cc95f
2 changed files with 16 additions and 19 deletions

View file

@ -347,26 +347,10 @@ def msgprint(msg, title=None, raise_exception=0, as_table=False, as_list=False,
return
if as_table and type(msg) in (list, tuple):
table_rows = ''
for row in msg:
table_row_data = ''
for data in row:
table_row_data += '<td>{}</td>'.format(data)
table_rows += '<tr>{}</tr>'.format(table_row_data)
out.message = '''<table class="table table-bordered"
style="margin: 0;">{}</table>'''.format(table_rows)
out.as_table = 1
if as_list and type(msg) in (list, tuple):
if len(msg) > 1:
list_rows = ''
for row in msg:
list_rows += '<li>{}</li>'.format(row)
out.message = '''<ul style="padding-left: 20px">{}</ul>'''.format(list_rows)
elif len(msg) == 1:
out.message = msg[0]
if as_list and type(msg) in (list, tuple) and len(msg) > 1:
out.as_list = 1
if flags.print_messages and out.message:
print(f"Message: {repr(out.message).encode('utf-8')}")

View file

@ -128,6 +128,19 @@ frappe.msgprint = function(msg, title, is_minimizable) {
data.indicator = 'blue';
}
if (data.as_list) {
const list_rows = data.message.map(m => `<li>${m}</li>`).join('');
data.message = `<ul style="padding-left: 20px">${list_rows}</ul>`;
}
if (data.as_table) {
const rows = data.message.map(row => {
const cols = row.map(col => `<td>${col}</td>`).join('');
return `<tr>${cols}</tr>`
}).join('');
data.message = `<table class="table table-bordered" style="margin: 0;">${rows}</table>`;
}
if(data.message instanceof Array) {
data.message.forEach(function(m) {
frappe.msgprint(m);