[FIX] web: implement <newline/> form tag behavior

Before this commit, the new form view implementation was rendering
<newline/> tags as real <newline/> DOM element. The wanted behavior
is now restored:
- As outer group direct child, produce a <br/> tag, forcing the next
  group children to be on a new line
- As inner group direct child, produce nothing but forces the creation
  of a new <tr/> (for the next group children)
This commit is contained in:
qsm-odoo
2017-05-11 15:09:25 +02:00
parent 97517a1cc2
commit 40a026d5b2
2 changed files with 68 additions and 1 deletions
@@ -315,9 +315,16 @@ var FormRenderer = BasicRenderer.extend({
$result.append($sep);
}
var currentColspan = 0;
var $currentRow = $('<tr/>');
var currentColspan = 0;
_.each(node.children, function (child) {
if (child.tag === 'newline') {
$currentRow.appendTo($result);
$currentRow = $('<tr/>');
currentColspan = 0;
return;
}
var colspan = parseInt(child.attrs.colspan, 10);
var isLabeledField = (child.tag === 'field' && child.attrs.nolabel !== '1');
if (!colspan) {
@@ -524,6 +531,9 @@ var FormRenderer = BasicRenderer.extend({
var $result = $('<div/>', {class: 'o_group'});
var colSize = Math.max(1, Math.round(12 / (parseInt(node.attrs.col, 10) || 2)));
$result.append(_.map(node.children, function (child) {
if (child.tag === 'newline') {
return $('<br/>');
}
var $child = self._renderNode(child);
$child.addClass('o_group_col_' + (colSize * (parseInt(child.attrs.colspan, 10) || 1)));
return $child;
@@ -4257,5 +4257,62 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('form group with newline tag inside', function (assert) {
assert.expect(6);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:
'<form>' +
'<sheet>' +
'<group col="5" class="main_inner_group">' +
// col=5 otherwise the test is ok even without the
// newline code as this will render a <newline/> DOM
// element in the third column, leaving no place for
// the next field and its label on the same line.
'<field name="foo"/>' +
'<newline/>' +
'<field name="bar"/>' +
'<field name="qux"/>' +
'</group>' +
'<group col="3">' +
// col=3 otherwise the test is ok even without the
// newline code as this will render a <newline/> DOM
// element with the o_group_col_6 class, leaving no
// place for the next group on the same line.
'<group class="top_group">' +
'<div style="height: 200px;"/>' +
'</group>' +
'<newline/>' +
'<group class="bottom_group">' +
'<div/>' +
'</group>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 1,
});
// Inner group
assert.strictEqual(form.$('.main_inner_group > tbody > tr').length, 2,
"there should be 2 rows in the group");
assert.strictEqual(form.$('.main_inner_group > tbody > tr:first > .o_td_label').length, 1,
"there should be only one label in the first row");
assert.strictEqual(form.$('.main_inner_group > tbody > tr:first .o_field_widget').length, 1,
"there should be only one widget in the first row");
assert.strictEqual(form.$('.main_inner_group > tbody > tr:last > .o_td_label').length, 2,
"there should be two labels in the second row");
assert.strictEqual(form.$('.main_inner_group > tbody > tr:last .o_field_widget').length, 2,
"there should be two widgets in the second row");
// Outer group
assert.ok((form.$('.bottom_group').position().top - form.$('.top_group').position().top) >= 200,
"outergroup children should not be on the same line");
form.destroy();
});
});
});