[FIX] web: add tooltips for buttons

Button tooltips have been missing since the switch to the new views. As
their omission was unintentional, this revision restores the
functionality.
This commit is contained in:
Khoi Nguyen
2017-07-24 13:14:23 +02:00
parent cae497b679
commit 952c17b8a7
3 changed files with 76 additions and 19 deletions
@@ -336,12 +336,27 @@ var FormRenderer = BasicRenderer.extend({
* @returns {jQueryElement}
*/
_renderHeaderButton: function (node) {
var self = this;
var $button = $('<button>')
.text(node.attrs.string)
.addClass('btn btn-sm btn-default');
this._addOnClickAction($button, node);
this._handleAttributes($button, node);
this._registerModifiers(node, this.state, $button);
// Display tooltip
if (config.debug || node.attrs.help) {
$button.tooltip({
delay: { show: 1000, hide: 0 },
title: function () {
return qweb.render('WidgetButton.tooltip', {
debug: config.debug,
state: self.state,
node: node,
});
},
});
}
return $button;
},
/**
+32 -19
View File
@@ -93,36 +93,49 @@
</li>
</ul>
</t>
<t t-name="WidgetButton.tooltip" t-extend="WidgetLabel.tooltip">
<t t-jquery="div.oe_tooltip_string" t-operation="replace">
<div class="oe_tooltip_string" t-if="debug || widget.string">
<t t-if="debug">
Button
<t t-if="widget.string">: </t>
<t t-if="!widget.string"> (no string)</t>
</t>
<t t-esc="widget.string"/>
</div>
</t>
<t t-jquery="ul.oe_tooltip_technical" t-operation="append">
<li t-if="widget.node.attrs.special" data-item="special">
<span class="oe_tooltip_technical_title">Special:</span>
<t t-esc="widget.node.attrs.special"/>
<t t-name="WidgetButton.tooltip">
<div class="oe_tooltip_string" t-if="debug || node.attrs.string">
<t t-if="debug">
Button
<t t-if="node.attrs.string">: </t>
<t t-if="!node.attrs.string"> (no string)</t>
</t>
<t t-esc="node.attrs.string"/>
</div>
<p t-if="node.attrs.help" class="oe_tooltip_help">
<t t-esc="node.attrs.help"/>
</p>
<ul t-if="debug" class="oe_tooltip_technical">
<li data-item="object">
<span class="oe_tooltip_technical_title">Object:</span>
<t t-esc="state.model"/>
</li>
<t t-set="button_type" t-value="widget.node.attrs.type"/>
<li t-if="node.attrs.context" data-item="context">
<span class="oe_tooltip_technical_title">Context:</span>
<t t-esc="node.attrs.context || widget.field.context"/>
</li>
<li t-if="node.attrs.modifiers and node.attrs.modifiers != '{}'" data-item="modifiers">
<span class="oe_tooltip_technical_title">Modifiers:</span>
<t t-esc="node.attrs.modifiers"/>
</li>
<li t-if="node.attrs.special" data-item="special">
<span class="oe_tooltip_technical_title">Special:</span>
<t t-esc="node.attrs.special"/>
</li>
<t t-set="button_type" t-value="node.attrs.type"/>
<li t-if="button_type" data-item="button_type">
<span class="oe_tooltip_technical_title">Button Type:</span>
<t t-esc="button_type"/>
</li>
<li t-if="button_type === 'object'" data-item="button_method">
<span class="oe_tooltip_technical_title">Method:</span>
<t t-esc="widget.node.attrs.name"/>
<t t-esc="node.attrs.name"/>
</li>
<li t-if="button_type === 'action'" data-item="button_action">
<span class="oe_tooltip_technical_title">Action ID:</span>
<t t-esc="widget.node.attrs.name"/>
<t t-esc="node.attrs.name"/>
</li>
</t>
</ul>
</t>
<t t-name="SwitchCompanyMenu">
@@ -2,6 +2,7 @@ odoo.define('web.form_tests', function (require) {
"use strict";
var concurrency = require('web.concurrency');
var config = require('web.config');
var core = require('web.core');
var FormView = require('web.FormView');
var testUtils = require('web.test_utils');
@@ -5388,5 +5389,33 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('display tooltips for buttons', function (assert) {
assert.expect(1);
var initialDebugMode = config.debug;
config.debug = true;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<header>' +
'<button name="some_method" class="oe_highlight" string="Button" type="object"/>' +
'</header>' +
'</form>',
});
var $button = form.$('.o_form_statusbar button');
$button.tooltip('show', false);
$button.trigger($.Event('mouseenter'));
assert.strictEqual($('.tooltip .oe_tooltip_string').length, 1,
"should have rendered a tooltip");
config.debug = initialDebugMode;
form.destroy();
});
});
});