diff options
| author | Aaron Bohy <aab@odoo.com> | 2019-03-13 11:26:43 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-04-02 11:55:57 +0000 |
| commit | 55676110c8787dfafd34a6508b207952f5c5eb88 (patch) | |
| tree | 36e4816c38c73beb13e64d042a19fc0906499a3e | |
| parent | 7024f8d58bb279c800818955979ab73f1ee7b612 (diff) | |
[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.
| -rw-r--r-- | addons/base_import/static/src/js/import_buttons.js | 8 | ||||
| -rw-r--r-- | addons/base_import/static/tests/import_buttons_tests.js | 31 | ||||
| -rw-r--r-- | 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: '<tree import="0"><field name="foo"/></tree>', + }); + + 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: '<kanban import="0">' + + '<templates><t t-name="kanban-box">' + + '<div><field name="foo"/></div>' + + '</t></templates>' + + '</kanban>', + }); + + 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 <https://getbootstrap.com/docs/3.3/components/#available-variations>`_ (``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`` |
