[FIX] web: avoid crash when clicking on colored m2m in list

With the BS4 update, a traceback occured when clicking on a m2m tag using colors
in a list view.

When using colors on m2m tags, the badge was wrapped inside a `dropdown-toggle`.
However, there is no `dropdown-menu` by default (it is only rendered in FormFieldMany2ManyTags
when clicking on the `.dropdown-toggle`, hence the traceback.

The `dropdown-toggle` class is now only set if necessary.

Task 1925313

closes odoo/odoo#31445
This commit is contained in:
Martin Geubelle
2019-02-27 11:39:52 +00:00
parent 70c8fd7f75
commit e39bcae818
3 changed files with 36 additions and 2 deletions
@@ -1857,6 +1857,7 @@ var FieldMany2ManyTags = AbstractField.extend({
}
this.colorField = this.nodeOptions.color_field;
this.hasDropdown = false;
},
//--------------------------------------------------------------------------
@@ -1923,6 +1924,7 @@ var FieldMany2ManyTags = AbstractField.extend({
return {
colorField: this.colorField,
elements: elements,
hasDropdown: this.hasDropdown,
readonly: this.mode === "readonly",
};
},
@@ -2034,6 +2036,14 @@ var FormFieldMany2ManyTags = FieldMany2ManyTags.extend({
'mousedown .o_colorpicker a': '_onUpdateColor',
'mousedown .o_colorpicker .o_hide_in_kanban': '_onUpdateColor',
}),
/**
* @override
*/
init: function () {
this._super.apply(this, arguments);
this.hasDropdown = !!this.colorField;
},
//--------------------------------------------------------------------------
// Handlers
+2 -2
View File
@@ -838,11 +838,11 @@
<t t-foreach="elements" t-as="el">
<t t-set="color" t-value="el[colorField] || 0"/>
<t t-set="colornames" t-value="['No color', 'Red', 'Orange', 'Yellow', 'Light blue', 'Dark purple', 'Salmon pink', 'Medium blue', 'Dark blue', 'Fushia', 'Green', 'Purple']"/>
<div t-attf-class="badge badge-pill dropdown o_tag_color_#{color}" t-att-data-color="color" t-att-data-index="el_index" t-att-data-id="el.id" t-attf-title="Tag color: #{colornames[color]}">
<div t-attf-class="badge badge-pill #{hasDropdown ? 'dropdown' : ''} o_tag_color_#{color}" t-att-data-color="color" t-att-data-index="el_index" t-att-data-id="el.id" t-attf-title="Tag color: #{colornames[color]}">
<t t-set="_badge_text">
<span class="o_badge_text" t-att-title="el.display_name"><span role="img" t-attf-aria-label="Tag color: #{colornames[color]}"/><t t-esc="el.display_name"/></span>
</t>
<t t-if="colorField">
<t t-if="hasDropdown">
<a role="button" href="#" class="dropdown-toggle o-no-caret" data-toggle="dropdown" aria-expanded="false">
<t t-raw="_badge_text"/>
</a>
@@ -12683,6 +12683,30 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('fieldmany2many tags in tree view', function (assert) {
assert.expect(3);
this.data.partner.records[0].timmy = [12, 14];
var list = createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree string="Partners">' +
'<field name="timmy" widget="many2many_tags" options="{\'color_field\': \'color\'}"/>' +
'</tree>',
});
assert.containsN(list, '.o_field_many2manytags .badge', 2, "there should be 2 tags");
assert.containsNone(list, '.dropdown-toggle', "the tags should not be dropdowns");
testUtils.intercept(list, 'switch_view', function (event) {
assert.strictEqual(event.data.view_type, "form", "should switch to form view");
});
// click on the tag: should do nothing and open the form view
testUtils.dom.click(list.$('.o_field_many2manytags .badge:first'));
list.destroy();
});
QUnit.test('fieldmany2many tags view a domain', function (assert) {
assert.expect(7);