From 4fb15efb59afe8ce98bb962b54163d3d7cb35a39 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 14 Nov 2012 17:44:13 +0100 Subject: [PATCH] [FIX] IE does not accept custom button@type attribute Added one more step in views serialization historic hell bzr revid: fme@openerp.com-20121114164413-wrnxlbuh9zj924yk --- addons/web/static/src/js/view_form.js | 31 +++++++++++++++++++++++---- addons/web/static/src/js/views.js | 10 +++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 014a67157bb..8f5bb86e6b9 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1191,14 +1191,36 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt }); } }, + view_arch_to_dom_node: function(arch) { + // Historic mess for views arch + // + // server: + // -> got xml as string + // -> parse to xml and manipulate domains and contexts + // -> convert to json + // client: + // -> got view as json + // -> convert back to xml as string + // -> parse it as xml doc (manipulate button@type for IE) + // -> convert back to string + // -> parse it as dom element with jquery + // -> for each widget, convert node to json + // + // Wow !!! + var xml = instance.web.json_node_to_xml(arch); + + var doc = $.parseXML('
' + xml + '
'); + $('button', doc).each(function() { + $(this).attr('data-button-type', $(this).attr('type')); + }); + xml = instance.web.xml_to_str(doc); + return $(xml); + }, render_to: function($target) { var self = this; this.$target = $target; - // TODO: I know this will save the world and all the kitten for a moment, - // but one day, we will have to get rid of xml2json - var xml = instance.web.json_node_to_xml(this.fvg.arch); - this.$form = $('
' + xml + '
'); + this.$form = this.view_arch_to_dom_node(this.fvg.arch); this.process_version(); @@ -1867,6 +1889,7 @@ instance.web.form.FormWidget = instance.web.Widget.extend(instance.web.form.Invi instance.web.form.WidgetButton = instance.web.form.FormWidget.extend({ template: 'WidgetButton', init: function(field_manager, node) { + node.attrs.type = node.attrs['data-button-type']; this._super(field_manager, node); this.force_disabled = false; this.string = (this.node.attrs.string || '').replace(/_/g, ''); diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index f39cb221a86..19336ec3655 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -1409,14 +1409,16 @@ instance.web.json_node_to_xml = function(node, human_readable, indent) { } else { return r + '/>'; } -} +}; instance.web.xml_to_str = function(node) { - if (window.ActiveXObject) { + if (window.XMLSerializer) { + return (new XMLSerializer()).serializeToString(node); + } else if (window.ActiveXObject) { return node.xml; } else { - return (new XMLSerializer()).serializeToString(node); + throw new Error("Could not serialize XML"); } -} +}; instance.web.str_to_xml = function(s) { if (window.DOMParser) { var dp = new DOMParser();