[merge] recursive version of the rendering engine
bzr revid: nicolas.vanhoren@openerp.com-20120320140309-87136e5sdf6jws36
This commit is contained in:
commit
e061670408
|
@ -728,27 +728,18 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
|||
|
||||
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 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
|
|||
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, no_process_label) {
|
||||
var name = $field.attr('name'),
|
||||
field_orm = this.fvg.fields[name],
|
||||
field_string = $field.attr('string') || field_orm.string || '',
|
||||
|
@ -791,15 +809,18 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
|
|||
}
|
||||
|
||||
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);
|
||||
if (!no_process_label)
|
||||
this.process_label(label);
|
||||
if (field_colspan > 1) {
|
||||
$field.attr('colspan', field_colspan - 1);
|
||||
}
|
||||
|
@ -811,9 +832,17 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
|
|||
'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;
|
||||
var fields = [];
|
||||
_.each($group.children(), function(el) {
|
||||
var tagname = el.nodeName.toLowerCase();
|
||||
if (tagname === "field") {
|
||||
self.process_field($(el), true);
|
||||
fields.push(el);
|
||||
}
|
||||
});
|
||||
var $new_group = $(QWeb.render('FormRenderingGroup', $group.getAttributes())),
|
||||
$table;
|
||||
if ($new_group.is('table')) {
|
||||
$table = $new_group;
|
||||
|
@ -825,6 +854,7 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
|
|||
cols = parseInt($group.attr('col') || 4, 10),
|
||||
row_cols = cols;
|
||||
|
||||
var children = [];
|
||||
$group.children().each(function() {
|
||||
var $child = $(this),
|
||||
colspan = parseInt($child.attr('colspan') || 1, 10),
|
||||
|
@ -840,6 +870,7 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
|
|||
row_cols -= colspan;
|
||||
var $td = $('<td/>').addClass('oe_form_group_cell').attr('colspan', colspan);
|
||||
$tr.append($td.append($child));
|
||||
children.push($child[0]);
|
||||
});
|
||||
$group.before($new_group).remove();
|
||||
|
||||
|
@ -877,8 +908,16 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
|
|||
total -= width;
|
||||
});
|
||||
});
|
||||
_.each(children, function(el) {
|
||||
if (!_.include(fields, el))
|
||||
self.process_any($(el));
|
||||
});
|
||||
},
|
||||
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),
|
||||
|
@ -894,11 +933,11 @@ openerp.web.FormRenderingEngine = openerp.web.Widget.extend({
|
|||
$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) {
|
||||
|
|
Loading…
Reference in New Issue