[FIX] web: field color: adapted for views

The FieldColor widget had been designed exclusively for the document
layout configurator. Because of this, the widget would not display/behave
correctly in other views.

Before this commit:
- in list views, the widget had a "white-space" attribute adapted for char fields,
which gave it much more space than it needed
- there was no handling of the widget in readonly state: it was always editable
- its size in list views was a bit too large

Now:
- all styling problems have been adjusted for list views (unchanged for forms)
- the widget is disabled when in readonly mode

Task 2072466

closes odoo/odoo#36949

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
This commit is contained in:
Julien Mougenot
2019-09-20 07:28:17 +00:00
parent 8901146b91
commit fd3c382186
5 changed files with 96 additions and 14 deletions
@@ -6442,7 +6442,7 @@ QUnit.module('basic_fields', {
});
QUnit.test('Field Color: default widget state', async function (assert) {
assert.expect(3);
assert.expect(4);
var form = await createView({
View: FormView,
@@ -6467,6 +6467,46 @@ QUnit.module('basic_fields', {
await testUtils.dom.click($('.modal .btn:contains("Discard")'));
assert.strictEqual(document.activeElement, form.$('.o_field_color')[0],
"Focus should go back to the color field");
form.destroy();
});
QUnit.test('Field Color: behaviour in different views', async function (assert) {
assert.expect(2);
this.data.partner.records[0].p = [4, 2];
this.data.partner.records[1].hex_color = '#ff0080';
const form = await createView({
arch: '<form>' +
'<field name="hex_color" widget="color"/>' +
'<field name="p">' +
'<tree editable="top">' +
'<field name="display_name"/>' +
'<field name="hex_color" widget="color"/>' +
'</tree>' +
'</field>' +
'</form>',
data: this.data,
model: 'partner',
res_id: 1,
View: FormView,
});
await testUtils.dom.click(form.$('.o_field_color:first()'));
assert.containsNone($(document.body), '.modal',
"Color field in readonly shouldn't be editable");
const rowInitialHeight = form.$('.o_data_row:first()').height();
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_data_row:first() .o_data_cell:first()'));
assert.strictEqual(rowInitialHeight, form.$('.o_data_row:first()').height(),
"Color field shouldn't change the color height when edited");
form.destroy();
});