[FIX] json_node_to_xml: whitespaces wrongly inserted around text nodes causing bugs in kanban views.
bzr revid: fme@openerp.com-20111025163531-nxr8gb4j2f7wne2a
This commit is contained in:
parent
dd514b567d
commit
20e5cb63a4
|
@ -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, '>').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 + '</' + node.tag + '>';
|
||||
r += childs.join(cr);
|
||||
r += cr + sindent + '</' + node.tag + '>';
|
||||
return r;
|
||||
} else {
|
||||
return r + '/>';
|
||||
|
|
Loading…
Reference in New Issue