[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
This commit is contained in:
Fabien Meghazi 2012-11-14 17:44:13 +01:00
parent 303b6108a4
commit 4fb15efb59
2 changed files with 33 additions and 8 deletions

View File

@ -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('<div class="oe_form">' + xml + '</div>');
$('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 = $('<div class="oe_form">' + xml + '</div>');
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, '');

View File

@ -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();