diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 78abe6a8fdb..41be7a18286 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -953,19 +953,19 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ } }); -session.web.json_node_to_xml = function(node, single_quote, indent) { +session.web.json_node_to_xml = function(node, human_readable, indent) { // For debugging purpose, this function will convert a json node back to xml // Maybe usefull for xml view editor + indent = indent || 0; + var sindent = (human_readable ? (new Array(indent + 1).join('\t')) : ''), + r = sindent + '<' + node.tag, + cr = human_readable ? '\n' : ''; if (typeof(node) === 'string') { - return node; - } - else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) { + return sindent + node; + } else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) { throw("Node a json node"); } - indent = indent || 0; - var sindent = new Array(indent + 1).join('\t'), - r = sindent + '<' + node.tag; for (var attr in node.attrs) { var vattr = node.attrs[attr]; if (typeof(vattr) !== 'string') { @@ -973,19 +973,19 @@ session.web.json_node_to_xml = function(node, single_quote, indent) { vattr = JSON.stringify(vattr); } vattr = vattr.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); - if (single_quote) { + if (human_readable) { vattr = vattr.replace(/"/g, "'"); } r += ' ' + attr + '="' + vattr + '"'; } if (node.children && node.children.length) { - r += '>\n'; + r += '>' + cr; var childs = []; for (var i = 0, ii = node.children.length; i < ii; i++) { - childs.push(session.web.json_node_to_xml(node.children[i], single_quote, indent + 1)); + childs.push(session.web.json_node_to_xml(node.children[i], human_readable, indent + 1)); } - r += childs.join('\n'); - r += '\n' + sindent + ''; + r += childs.join(cr); + r += cr + sindent + ''; return r; } else { return r + '/>';