From d59b67a91587b4a968cbd9dd053ddfe8beaedd14 Mon Sep 17 00:00:00 2001 From: Quentin Nicolay Date: Tue, 15 Oct 2019 09:15:32 +0000 Subject: [PATCH] [FIX] web: add 'no_edit_color' option to many2many_tags This option, if set to True, prevents the user from modifying the color of the tags. Part of task 2070454 closes odoo/odoo#38848 X-original-commit: a62b65a8f9114493064d4efae92825814a880c04 Signed-off-by: Aaron Bohy (aab) --- .../static/src/js/fields/relational_fields.js | 4 ++++ .../tests/fields/relational_fields_tests.js | 22 +++++++++++++++++++ doc/reference/javascript_reference.rst | 6 +++++ 3 files changed, 32 insertions(+) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index f54f46e4ebf..2b6a0d44854 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -2440,6 +2440,10 @@ var FormFieldMany2ManyTags = FieldMany2ManyTags.extend({ */ _onOpenColorPicker: function (ev) { ev.preventDefault(); + if (this.nodeOptions.no_edit_color) { + ev.stopPropagation(); + return; + } var tagID = $(ev.currentTarget).parent().data('id'); var tagColor = $(ev.currentTarget).parent().data('color'); var tag = _.findWhere(this.value.data, { res_id: tagID }); diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 751eb1cb137..d9e9b69e6c2 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -1545,6 +1545,28 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('fieldmany2many tags with no_edit_color option', async function (assert) { + assert.expect(1); + + this.data.partner.records[0].timmy = [12]; + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
' + + '' + + '', + res_id: 1, + }); + + // Click to try to open colorpicker + await testUtils.dom.click(form.$('.badge:first() .dropdown-toggle')); + assert.containsNone(document.body, '.o_colorpicker'); + + form.destroy(); + }); + QUnit.test('fieldmany2many tags in editable list', async function (assert) { assert.expect(7); diff --git a/doc/reference/javascript_reference.rst b/doc/reference/javascript_reference.rst index 6a1dbdd7599..49ab37cf2e0 100644 --- a/doc/reference/javascript_reference.rst +++ b/doc/reference/javascript_reference.rst @@ -2131,6 +2131,12 @@ Relational fields + - no_edit_color: set to True to remove the possibility to change the color of the tags (default: False). + + .. code-block:: xml + + + - form.many2many_tags (FormFieldMany2ManyTags) Specialization of many2many_tags widget for form views. It has some extra code to allow editing the color of a tag.