From 55676110c8787dfafd34a6508b207952f5c5eb88 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 13 Mar 2019 11:26:43 +0000 Subject: [PATCH] [IMP] web: list: import attrs The 'import' attrs is valid according to the rng definition of the list view. It is used in a few views in Odoo. However, it didn't actually work (in most cases, it worked by chance because it is set to "0" in addition to create="0", and create="0" already disables the import feature). With this ref, the 'import' attrs is taken into account and we can now disable the import feature even if the create one is enabled. Moreover, it is now documented. --- .../static/src/js/import_buttons.js | 8 +++-- .../static/tests/import_buttons_tests.js | 31 +++++++++++++++++++ doc/reference/views.rst | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/addons/base_import/static/src/js/import_buttons.js b/addons/base_import/static/src/js/import_buttons.js index f6d246a8586..89baedc8113 100644 --- a/addons/base_import/static/src/js/import_buttons.js +++ b/addons/base_import/static/src/js/import_buttons.js @@ -13,11 +13,13 @@ var ImportViewMixin = { /** * @override * @param {Object} params - * @param {boolean} [params.import_enabled=true] determine if the import - * button is visible (in the control panel) + * @param {boolean} [params.import_enabled=true] set to false to disable + * the Import feature (no 'Import' button in the control panel). Can also + * be disabled with 'import' attrs set to '0' in the arch. */ init: function (viewInfo, params) { - var importEnabled = 'import_enabled' in params ? params.import_enabled : true; + var importEnabled = !!JSON.parse(this.arch.attrs.import || '1') && + ('import_enabled' in params ? params.import_enabled : true); this.controllerParams.importEnabled = importEnabled && !config.device.isMobile; }, }; diff --git a/addons/base_import/static/tests/import_buttons_tests.js b/addons/base_import/static/tests/import_buttons_tests.js index 40bd162dd2f..fdb0e2a816e 100644 --- a/addons/base_import/static/tests/import_buttons_tests.js +++ b/addons/base_import/static/tests/import_buttons_tests.js @@ -106,4 +106,35 @@ QUnit.test('kanban without import button', async function(assert) { kanban.destroy(); }); +QUnit.test('import attrs in list views', async function (assert) { + assert.expect(1); + + var list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '', + }); + + assert.containsNone(list.$buttons, '.o_button_import'); + list.destroy(); +}); + +QUnit.test('import attrs in kanban views', async function (assert) { + assert.expect(1); + + var kanban = await createView({ + View: KanbanView, + model: 'foo', + data: this.data, + arch: '' + + '' + + '
' + + '
' + + '
', + }); + + assert.containsNone(kanban.$buttons, '.o_button_import'); + kanban.destroy(); +}); }); diff --git a/doc/reference/views.rst b/doc/reference/views.rst index 746c5e48b32..68d024e47db 100644 --- a/doc/reference/views.rst +++ b/doc/reference/views.rst @@ -216,7 +216,7 @@ root can have the following attributes: (``font-style: italic``), or any `bootstrap contextual color `_ (``danger``, ``info``, ``muted``, ``primary``, ``success`` or ``warning``). -``create``, ``edit``, ``delete``, ``duplicate`` +``create``, ``edit``, ``delete``, ``duplicate``, ``import`` allows *dis*\ abling the corresponding action in the view by setting the corresponding attribute to ``false`` ``limit``