From ed830f739491d01da92f2517bd4cee453d994923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sun, 26 Feb 2017 09:53:33 +0100 Subject: [PATCH] [FIX] web: don't select cell in one2many (non editable) The code for selectCell was active, when the user clicked on a td. No test caught that, because we simulated a click on a tr, not on a td. I guess that the lesson of the story is that our tests should be as close as possible to the real conditions, so we should simulate the click on the innermost element. --- .../src/js/views/list/list_editable_renderer.js | 12 +++++------- .../static/test/fields/relational_fields_tests.js | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js index 9d270ba3976..7be3f3d4e29 100644 --- a/addons/web/static/src/js/views/list/list_editable_renderer.js +++ b/addons/web/static/src/js/views/list/list_editable_renderer.js @@ -56,6 +56,8 @@ ListRenderer.include({ // of each line, so the user can delete a record. this.addTrashIcon = params.addTrashIcon; + this.editable = this.arch.attrs.editable; + this.currentRow = null; this.currentCol = null; }, @@ -485,6 +487,9 @@ ListRenderer.include({ * @param {MouseEvent} event */ _onCellClick: function (event) { + if (this.mode === 'readonly' || !this.editable) { + return; + } var $td = $(event.currentTarget); var rowIndex = $td.parent().data('index'); var colIndex = $td.data('index'); @@ -492,13 +497,6 @@ ListRenderer.include({ this._selectCell(rowIndex, colIndex); event.stopPropagation(); } - // FIXME: this seems like dead code - // if (this.state.groupedBy.length) { - // var id = $td.parent().data('id'); - // if (id) { - // this.trigger_up('record_selected', {id:id}); - // } - // } }, /** * We need to manually unselect row, because noone else would do it diff --git a/addons/web/static/test/fields/relational_fields_tests.js b/addons/web/static/test/fields/relational_fields_tests.js index 3ea8ca06ad7..c76c5bdebe0 100644 --- a/addons/web/static/test/fields/relational_fields_tests.js +++ b/addons/web/static/test/fields/relational_fields_tests.js @@ -1025,7 +1025,7 @@ QUnit.module('relational_fields', { '"Add an item" should not visible in edit'); // edit existing subrecord - form.$('.o_list_view tbody tr:first()').click(); + form.$('.o_list_view tbody tr:first() td:eq(1)').click(); $('.modal .o_form_view .o_form_input').val('new name').trigger('input'); $('.modal .modal-footer .btn-primary').click(); // save