[FIX] web: list: hide export button when list empty

Before this commit, at first rendering, the export button was
displayed in the list view even if the list was empty.

The issue occurred because at first rendering, the buttons aren't
moved inside the control panel yet (this is done in the 'mounted'
hook of the control panel). As we render in a fragment, the hook
is called later on, when everything is ready and inserted into the
DOM.

We'll get rid of these painful manipulations as soon as everything
will be converted to OWL.

Task 2294306

closes odoo/odoo#54307

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Hardik Prajapati
2020-07-27 12:54:57 +00:00
committed by Aaron Bohy
parent 97425653af
commit 7aafa20509
2 changed files with 21 additions and 2 deletions
@@ -174,9 +174,9 @@ var ListController = BasicController.extend({
this.$buttons.toggleClass('o-editing', mode === 'edit');
const state = this.model.get(this.handle, {raw: true});
if (state.count) {
this.$('.o_list_export_xlsx').show();
this.$buttons.find('.o_list_export_xlsx').show();
} else {
this.$('.o_list_export_xlsx').hide();
this.$buttons.find('.o_list_export_xlsx').hide();
}
}
this._updateSelectionBox();
@@ -278,6 +278,25 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('export button in empty list view', async function (assert) {
assert.expect(2);
const list = await createView({
View: ListView,
model: "foo",
data: this.data,
arch: '<tree><field name="foo"/></tree>',
domain: [["id", "<", 0]], // such that no record matches the domain
});
assert.isNotVisible(list.el.querySelector('.o_list_export_xlsx'));
await list.reload({ domain: [['id', '>', 0]] });
assert.isVisible(list.el.querySelector('.o_list_export_xlsx'));
list.destroy();
});
QUnit.test('list view with adjacent buttons', async function (assert) {
assert.expect(2);