[IMP] web: list: add expand attrs
When this attribute is set to true on the <tree> root node, in a grouped list view, first level groups are automatically opened. Part of task 1915702
This commit is contained in:
@@ -4323,8 +4323,11 @@ var BasicModel = AbstractModel.extend({
|
||||
self.localData[newGroup.id] = newGroup;
|
||||
} else if (!newGroup.openGroupByDefault || openGroupCount >= self.OPEN_GROUP_LIMIT) {
|
||||
newGroup.isOpen = false;
|
||||
} else if ('__fold' in group) {
|
||||
newGroup.isOpen = !group.__fold;
|
||||
} else {
|
||||
newGroup.isOpen = '__fold' in group ? !group.__fold : true;
|
||||
// open the group iff it is a first level group
|
||||
newGroup.isOpen = !self.localData[newGroup.parentID].parentID;
|
||||
}
|
||||
list.data.push(newGroup.id);
|
||||
list.count += newGroup.count;
|
||||
|
||||
@@ -54,6 +54,7 @@ var ListView = BasicView.extend({
|
||||
this.rendererParams.addCreateLineInGroups = this.rendererParams.editable && this.controllerParams.activeActions.create;
|
||||
|
||||
this.loadParams.limit = this.loadParams.limit || 80;
|
||||
this.loadParams.openGroupByDefault = !!JSON.parse(this.arch.attrs.expand || "0");
|
||||
this.loadParams.type = 'list';
|
||||
},
|
||||
|
||||
|
||||
@@ -4065,6 +4065,60 @@ QUnit.module('Views', {
|
||||
delete widgetRegistry.map.asyncWidget;
|
||||
});
|
||||
|
||||
QUnit.test('grouped list with expand attribute', async function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
var list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: '<tree expand="1"><field name="foo"/></tree>',
|
||||
groupBy: ['bar'],
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method || route);
|
||||
return this._super.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
assert.containsN(list, '.o_group_header', 2);
|
||||
assert.containsN(list, '.o_data_row', 4);
|
||||
|
||||
assert.verifySteps([
|
||||
'read_group',
|
||||
'/web/dataset/search_read',
|
||||
'/web/dataset/search_read',
|
||||
]);
|
||||
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('grouped list (two levels) with expand attribute', async function (assert) {
|
||||
// the expand attribute only opens the first level groups
|
||||
assert.expect(5);
|
||||
|
||||
var list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: '<tree expand="1"><field name="foo"/></tree>',
|
||||
groupBy: ['bar', 'int_field'],
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method || route);
|
||||
return this._super.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
assert.containsN(list, '.o_group_header', 6);
|
||||
|
||||
assert.verifySteps([
|
||||
'read_group', // global
|
||||
'read_group', // first group
|
||||
'read_group', // second group
|
||||
]);
|
||||
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('editable grouped lists', async function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
|
||||
@@ -221,6 +221,9 @@ root can have the following attributes:
|
||||
corresponding attribute to ``false``
|
||||
``limit``
|
||||
the default size of a page. It should be a positive integer
|
||||
``expand``
|
||||
when the list view is grouped, automatically open the first level of groups
|
||||
if set to true (default: false)
|
||||
|
||||
Possible children elements of the list view are:
|
||||
|
||||
|
||||
@@ -42,6 +42,14 @@
|
||||
</rng:choice>
|
||||
</rng:attribute>
|
||||
</rng:optional>
|
||||
<rng:optional>
|
||||
<rng:attribute name="expand">
|
||||
<rng:choice>
|
||||
<rng:value>1</rng:value>
|
||||
<rng:value>0</rng:value>
|
||||
</rng:choice>
|
||||
</rng:attribute>
|
||||
</rng:optional>
|
||||
<rng:zeroOrMore>
|
||||
<rng:choice>
|
||||
<rng:ref name="control"/>
|
||||
|
||||
Reference in New Issue
Block a user