[IMP] web: allow to add buttons to pivot controller
This is useful for the integration of pivot views with spreadsheet Task-ID: 2168016
This commit is contained in:
@@ -91,11 +91,7 @@ odoo.define('web.PivotController', function (require) {
|
||||
* does nothing
|
||||
*/
|
||||
renderButtons: function ($node) {
|
||||
const context = {
|
||||
measures: Object.entries(this.measures)
|
||||
.filter(x => x[0] !== '__count')
|
||||
.sort((a, b) => a[1].string.toLowerCase() > b[1].string.toLowerCase() ? 1 : -1),
|
||||
};
|
||||
const context = this._getRenderButtonContext();
|
||||
this.$buttons = $(QWeb.render('PivotView.buttons', context));
|
||||
this.$buttons.click(this._onButtonClick.bind(this));
|
||||
this.$buttons.find('button').tooltip();
|
||||
@@ -183,6 +179,30 @@ odoo.define('web.PivotController', function (require) {
|
||||
if ($target.hasClass('o_pivot_download')) {
|
||||
this._downloadTable();
|
||||
}
|
||||
|
||||
await this._addIncludedButtons(ev);
|
||||
},
|
||||
|
||||
/**
|
||||
* Declared to be overwritten in includes of pivot controller
|
||||
*
|
||||
* @param {MouseEvent} ev
|
||||
* @returns {Promise<void>}
|
||||
* @private
|
||||
*/
|
||||
_addIncludedButtons: async function(ev) {},
|
||||
/**
|
||||
* Get the context of rendering of the buttons
|
||||
*
|
||||
* @returns {Object}
|
||||
* @private
|
||||
*/
|
||||
_getRenderButtonContext: function () {
|
||||
return {
|
||||
measures: Object.entries(this.measures)
|
||||
.filter(x => x[0] !== '__count')
|
||||
.sort((a, b) => a[1].string.toLowerCase() > b[1].string.toLowerCase() ? 1 : -1),
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@ odoo.define('web.pivot_tests', function (require) {
|
||||
|
||||
var core = require('web.core');
|
||||
var PivotView = require('web.PivotView');
|
||||
const PivotController = require("web.PivotController");
|
||||
var testUtils = require('web.test_utils');
|
||||
var testUtilsDom = require('web.test_utils_dom');
|
||||
|
||||
@@ -2835,5 +2836,36 @@ QUnit.module('Views', {
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('Allow to add behaviour to buttons on pivot', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
let _testButtons = (ev) => {
|
||||
if ($(ev.target).hasClass("o_pivot_flip_button")) {
|
||||
assert.step("o_pivot_flip_button")
|
||||
}
|
||||
}
|
||||
|
||||
PivotController.include({
|
||||
_addIncludedButtons: async function (ev) {
|
||||
await this._super(...arguments);
|
||||
_testButtons(ev);
|
||||
},
|
||||
});
|
||||
|
||||
const pivot = await createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: this.data,
|
||||
arch: '<pivot>' +
|
||||
'<field name="date" type="row" interval="day"/>' +
|
||||
'<field name="bar" type="col"/>' +
|
||||
'</pivot>',
|
||||
});
|
||||
await testUtils.dom.click(pivot.$buttons.find('.o_pivot_flip_button'));
|
||||
assert.verifySteps(["o_pivot_flip_button"]);
|
||||
_testButtons = () => true;
|
||||
pivot.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user