diff options
| author | Alexandre Kühn <alexkuhn@users.noreply.github.com> | 2018-01-03 11:42:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-03 11:42:39 +0100 |
| commit | 8bc7cebd9c19ae8f77378d115a8401d7b7de56b0 (patch) | |
| tree | 4cc13e4a51b11e1da1f30996cab01d3d6876a451 /addons/web/static/src/js/views | |
| parent | c8fa2d581caa13e881188552e6e2e22f8e858f7f (diff) | |
[IMP] web: many2many editable list with X remove icon (#20978)
In many2many lists, the remove record from the widget is a trash bin.
It is confusing, as people feel they are deleting it when they are
only unlinking it.
So in many2many, we propose to change the trash icon by a 'X'.
This icon appears in many2many relations and in many2many widgets:
even though hr.expense.sheet defines the expense lines as a one2many,
it uses a many2many widget, so we use a 'X' instead of the trash bin.
To avoid ambiguity, we decided to rename 'delete' to 'remove'.
Diffstat (limited to 'addons/web/static/src/js/views')
| -rw-r--r-- | addons/web/static/src/js/views/list/list_editable_renderer.js | 37 |
1 files changed, 22 insertions, 15 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 c1ef23b6b5e..964b7ba7bbe 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 @@ -23,11 +23,11 @@ ListRenderer.include({ navigation_move: '_onNavigationMove', }), events: _.extend({}, ListRenderer.prototype.events, { + 'click .o_field_x2many_list_row_add a': '_onAddRecord', 'click tbody td.o_data_cell': '_onCellClick', 'click tbody tr:not(.o_data_row)': '_onEmptyRowClick', 'click tfoot': '_onFooterClick', - 'click tr .o_list_record_delete': '_onTrashIconClick', - 'click .o_field_x2many_list_row_add a': '_onAddRecord', + 'click tr .o_list_record_remove': '_onRemoveIconClick', }), /** * @override @@ -46,6 +46,10 @@ ListRenderer.include({ // of each line, so the user can delete a record. this.addTrashIcon = params.addTrashIcon; + // replace the trash icon by X in case of many2many relations + // so that it means 'unlink' instead of 'remove' + this.isMany2Many = params.isMany2Many; + this.currentRow = null; this.currentFieldIndex = null; }, @@ -489,6 +493,7 @@ ListRenderer.include({ /** * Editable rows are possibly extended with a trash icon on their right, to * allow deleting the corresponding record. + * For many2many editable lists, the trash bin is replaced by X. * * @override * @param {any} record @@ -498,8 +503,10 @@ ListRenderer.include({ _renderRow: function (record, index) { var $row = this._super.apply(this, arguments); if (this.addTrashIcon) { - var $icon = $('<span>', {class: 'fa fa-trash-o', name: 'delete'}); - var $td = $('<td>', {class: 'o_list_record_delete'}).append($icon); + var $icon = this.isMany2Many ? + $('<i>', {class: 'fa fa-times', name: 'unlink'}) : + $('<i>', {class: 'fa fa-trash-o', name: 'delete'}); + var $td = $('<td>', {class: 'o_list_record_remove'}).append($icon); $row.append($td); } return $row; @@ -777,6 +784,17 @@ ListRenderer.include({ } }, /** + * Triggers a remove event. I don't know why we stop the propagation of the + * event. + * + * @param {MouseEvent} event + */ + _onRemoveIconClick: function (event) { + event.stopPropagation(); + var id = $(event.target).closest('tr').data('id'); + this.trigger_up('list_record_remove', {id: id}); + }, + /** * If the list view editable, just let the event bubble. We don't want to * open the record in this case anyway. * @@ -800,17 +818,6 @@ ListRenderer.include({ } }, /** - * Triggers a delete event. I don't know why we stop the propagation of the - * event. - * - * @param {MouseEvent} event - */ - _onTrashIconClick: function (event) { - event.stopPropagation(); - var id = $(event.target).closest('tr').data('id'); - this.trigger_up('list_record_delete', {id: id}); - }, - /** * When a click happens outside the list view, or outside a currently * selected row, we want to unselect it. * |
