diff options
| author | Fabien Meghazi <fme@openerp.com> | 2012-03-20 15:35:16 +0100 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2012-03-20 15:35:16 +0100 |
| commit | 985d448f7c4ebd2d3b7fecae2e9c1853993c4351 (patch) | |
| tree | 694de6f4439523595b41e2e16da110dc404f653e /addons/web/static/src/js | |
| parent | e2c7d8094a4880860901155c1c45a2dabdf17f24 (diff) | |
[IMP] RenderingEngine registry compliant. Also allows use of <any/> tag
bzr revid: fme@openerp.com-20120320143516-dxaj53nu6k8v6kxo
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index aba6eaea261..b578ad0bc32 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -739,7 +739,7 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({ var xml = openerp.web.json_node_to_xml(fvg.arch); this.$form = $(xml); - this.process_any(this.$form); + this.process(this.$form); }, start: function() { var self = this; @@ -770,32 +770,23 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({ this.$element.toggleClass('oe_layout_debugging'); }, - process_any: function($tag) { + process: function($tag) { var self = this; - // TODO: extract embeded views before preprocessing var tagname = $tag[0].nodeName.toLowerCase(); var fn = self['process_' + tagname]; if (this.registry && this.registry.contains(tagname)) { fn = this.registry.get_object(tagname); } - if (fn) - fn.call(self, $tag); - else { // generic tag handling, just process children - _.each($tag.children(), function(el) { - self.process_any($(el)); + if (fn) { + var args = [].slice.call(arguments); + args[0] = $tag; + fn.apply(self, args); + } else { + // generic tag handling, just process children + $tag.children().each(function() { + self.process($(this)); }); } - /* - _.each(['field', 'group', 'notebook', 'separator', 'label'], function(tag) { - var fn = self['process_' + tag]; - if (this.registry && this.registry.contains(tag)) { - fn = this.registry.get_object(tag); - } - $form.find(tag).each(function() { - fn.call(self, $(this), $form); - }); - }); - */ }, process_field: function($field, no_process_label) { var name = $field.attr('name'), @@ -813,14 +804,15 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({ if (!$label.length) { field_string = $label.attr('string') || $label.text() || field_string; field_help = $label.attr('help') || field_help; - var label = $('<label/>').attr({ + var $label = $('<label/>').attr({ 'for' : name, 'string' : field_string, 'help' : field_help }); - label.insertBefore($field); - if (!no_process_label) - this.process_label(label); + $label.insertBefore($field); + if (!no_process_label) { + this.process($label); + } if (field_colspan > 1) { $field.attr('colspan', field_colspan - 1); } @@ -835,12 +827,8 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({ process_group: function($group) { var self = this; var fields = []; - _.each($group.children(), function(el) { - var tagname = el.nodeName.toLowerCase(); - if (tagname === "field") { - self.process_field($(el), true); - fields.push(el); - } + $group.children('field').each(function() { + self.process($(this), true); }); var $new_group = $(QWeb.render('FormRenderingGroup', $group.getAttributes())), $table; @@ -909,14 +897,15 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({ }); }); _.each(children, function(el) { - if (!_.include(fields, el)) - self.process_any($(el)); + if (!_.include(fields, el)) { + self.process($(el)); + } }); }, process_notebook: function($notebook) { var self = this; - _.each($notebook.children(), function(el) { - self.process_any($(el)); + $notebook.children().each(function() { + self.process($(this)); }); var pages = []; $notebook.find('> page').each(function() { |
