Nicolas Vanhoren (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-form-v2-alt-algo-niv into 
lp:~openerp-dev/openerp-web/trunk-form-v2-fme.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-form-v2-alt-algo-niv/+merge/98394

Improvement of the rendering engine. Replaced search-and-replace with a 
post-order tree traversal to ease lot a things.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-form-v2-alt-algo-niv/+merge/98394
Your team OpenERP R&D Team is requested to review the proposed merge of 
lp:~openerp-dev/openerp-web/trunk-form-v2-alt-algo-niv into 
lp:~openerp-dev/openerp-web/trunk-form-v2-fme.
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js	2012-03-20 11:01:15 +0000
+++ addons/web/static/src/js/view_form.js	2012-03-20 11:09:21 +0000
@@ -728,27 +728,18 @@
 
 openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
     init: function(parent, fvg, registry) {
-        var self = this;
         this._super.apply(this, arguments);
+        this.registry = registry;
         this.fvg = fvg;
         this.view = parent;
         this.fields_prefix = this.view.dataset ? this.view.dataset.model : '';
 
         // 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 = openerp.web.json_node_to_xml(fvg.arch),
-            $form = this.$form = $(xml);
+        var xml = openerp.web.json_node_to_xml(fvg.arch);
+        this.$form = $(xml);
 
-        // TODO: extract embeded views before preprocessing
-        _.each(['field', 'group', 'notebook', 'separator', 'label'], function(tag) {
-            var fn = self['process_' + tag];
-            if (registry && registry.contains(tag)) {
-                fn = registry.get_object(tag);
-            }
-            $form.find(tag).each(function() {
-                fn.call(self, $(this), $form);
-            });
-        });
+        this.process_any(this.$form);
     },
     start: function() {
         var self = this;
@@ -779,7 +770,34 @@
         this.$element.toggleClass('oe_layout_debugging');
 
     },
-    process_field: function($field, $form) {
+    process_any: 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));
+            });
+        }
+        /*
+        _.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) {
         var name = $field.attr('name'),
             field_orm = this.fvg.fields[name],
             field_string = $field.attr('string') || field_orm.string || '',
@@ -791,15 +809,17 @@
         }
 
         if ($field.attr('nolabel') !== '1') {
-            var $label = $form.find('label[for="' + name + '"]');
+            var $label = this.$form.find('label[for="' + name + '"]');
             if (!$label.length) {
                 field_string = $label.attr('string') || $label.text() || field_string;
                 field_help = $label.attr('help') || field_help;
-                $('<label/>').attr({
+                var label = $('<label/>').attr({
                     'for' : name,
                     'string' : field_string,
                     'help' :  field_help
-                }).insertBefore($field).text();
+                });
+                label.insertBefore($field);
+                this.process_any(label);
                 if (field_colspan > 1) {
                     $field.attr('colspan', field_colspan - 1);
                 }
@@ -811,9 +831,12 @@
             'help' : field_help
         });
     },
-    process_group: function($group, $form) {
-        var self = this,
-            $new_group = $(QWeb.render('FormRenderingGroup', $group.getAttributes())),
+    process_group: function($group) {
+        var self = this;
+        _.each($group.children(), function(el) {
+            self.process_any($(el));
+        });
+        var $new_group = $(QWeb.render('FormRenderingGroup', $group.getAttributes())),
             $table;
         if ($new_group.is('table')) {
             $table = $new_group;
@@ -877,7 +900,11 @@
             });
         });
     },
-    process_notebook: function($notebook, $form) {
+    process_notebook: function($notebook) {
+        var self = this;
+        _.each($notebook.children(), function(el) {
+            self.process_any($(el));
+        });
         var pages = [];
         $notebook.find('> page').each(function() {
             var $page = $(this),
@@ -893,11 +920,11 @@
         $notebook.before($new_notebook).remove();
         $new_notebook.tabs();
     },
-    process_separator: function($separator, $form) {
+    process_separator: function($separator) {
         var $new_separator = $(QWeb.render('FormRenderingSeparator', $separator.getAttributes()));
         $separator.before($new_separator).remove();
     },
-    process_label: function($label, $form) {
+    process_label: function($label) {
         var dict = $label.getAttributes();
         var align = parseFloat(dict.align);
         if (isNaN(align) || align === 1) {

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to