[IMP] web: list: improve style of icon buttons
Buttons with icon and string attributes now have both their icon and string displayed, whereas before only the icon was displayed (the string was available as title). We also force class btn-link to style buttons with icon, except if another btn-xxx class is explicitely provided. Part of task 2195254
This commit is contained in:
@@ -469,9 +469,18 @@ var ListRenderer = BasicRenderer.extend({
|
||||
var self = this;
|
||||
var nodeWithoutWidth = Object.assign({}, node);
|
||||
delete nodeWithoutWidth.attrs.width;
|
||||
|
||||
let extraClass = '';
|
||||
if (node.attrs.icon) {
|
||||
// if there is an icon, we force the btn-link style, unless a btn-xxx
|
||||
// style class is explicitely provided
|
||||
const btnStyleRegex = /\bbtn-(primary|secondary|link|success|info|warning|danger)\b/;
|
||||
if (!btnStyleRegex.test(nodeWithoutWidth.attrs.class)) {
|
||||
extraClass = 'btn-link o_icon_button';
|
||||
}
|
||||
}
|
||||
var $button = viewUtils.renderButtonFromNode(nodeWithoutWidth, {
|
||||
extraClass: node.attrs.icon ? 'o_icon_button' : undefined,
|
||||
textAsTitle: !!node.attrs.icon,
|
||||
extraClass: extraClass,
|
||||
});
|
||||
this._handleAttributes($button, node);
|
||||
this._registerModifiers(node, record, $button);
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
}
|
||||
&.o_list_button .o_button_icon {
|
||||
margin-right: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
tfoot {
|
||||
|
||||
@@ -277,6 +277,33 @@ QUnit.module('Views', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('list view with icon buttons', async function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
this.data.foo.records.splice(1);
|
||||
|
||||
const list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: `
|
||||
<tree>
|
||||
<button name="x" type="object" icon="fa-asterisk"/>
|
||||
<button name="x" type="object" icon="fa-star" class="o_yeah"/>
|
||||
<button name="x" type="object" icon="fa-refresh" string="Refresh" class="o_yeah"/>
|
||||
<button name="x" type="object" icon="fa-exclamation" string="Danger" class="o_yeah btn-danger"/>
|
||||
</tree>`,
|
||||
});
|
||||
|
||||
assert.containsOnce(list, 'button.btn.btn-link i.fa.fa-asterisk');
|
||||
assert.containsOnce(list, 'button.btn.btn-link.o_yeah i.fa.fa-star');
|
||||
assert.containsOnce(list, 'button.btn.btn-link.o_yeah:contains("Refresh") i.fa.fa-refresh');
|
||||
assert.containsOnce(list, 'button.btn.btn-danger.o_yeah:contains("Danger") i.fa.fa-exclamation');
|
||||
assert.containsNone(list, 'button.btn.btn-link.btn-danger');
|
||||
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('simple editable rendering', async function (assert) {
|
||||
assert.expect(15);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user