summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/pivot/pivot_controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/views/pivot/pivot_controller.js')
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_controller.js67
1 files changed, 29 insertions, 38 deletions
diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js
index c54c6affedc..ee37aba3ce5 100644
--- a/addons/web/static/src/js/views/pivot/pivot_controller.js
+++ b/addons/web/static/src/js/views/pivot/pivot_controller.js
@@ -85,25 +85,44 @@ odoo.define('web.PivotController', function (require) {
* add listeners on it.
* Set this.$buttons with the produced jQuery element
*
+ * @override
* @param {jQuery} [$node] a jQuery node where the rendered buttons should
* be inserted. $node may be undefined, in which case the PivotView
* 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),
+ };
+ this.$buttons = $(QWeb.render('PivotView.buttons', context));
+ this.$buttons.click(this._onButtonClick.bind(this));
+ this.$buttons.find('button').tooltip();
if ($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),
- };
- this.$buttons = $(QWeb.render('PivotView.buttons', context));
- this.$buttons.click(this._onButtonClick.bind(this));
- this.$buttons.find('button').tooltip();
-
this.$buttons.appendTo($node);
- this._updateButtons();
}
},
+ /**
+ * @override
+ */
+ updateButtons: function () {
+ if (!this.$buttons) {
+ return;
+ }
+ const state = this.model.get({ raw: true });
+ Object.entries(this.measures).forEach(elt => {
+ const name = elt[0];
+ const isSelected = state.measures.includes(name);
+ this.$buttons.find('.dropdown-item[data-field="' + name + '"]')
+ .toggleClass('selected', isSelected);
+
+ });
+ const noDataDisplayed = !state.hasData || !state.measures.length;
+ this.$buttons.find('.o_pivot_flip_button').prop('disabled', noDataDisplayed);
+ this.$buttons.find('.o_pivot_expand_button').prop('disabled', noDataDisplayed);
+ this.$buttons.find('.o_pivot_download').prop('disabled', noDataDisplayed);
+ },
//--------------------------------------------------------------------------
// Private
@@ -131,34 +150,6 @@ odoo.define('web.PivotController', function (require) {
error: (error) => this.call('crash_manager', 'rpc_error', error),
});
},
- /**
- * @override
- * @private
- */
- _update: function () {
- this._updateButtons();
- return this._super.apply(this, arguments);
- },
- /**
- * @private
- */
- _updateButtons: function () {
- if (!this.$buttons) {
- return;
- }
- const state = this.model.get({ raw: true });
- Object.entries(this.measures).forEach(elt => {
- const name = elt[0];
- const isSelected = state.measures.includes(name);
- this.$buttons.find('.dropdown-item[data-field="' + name + '"]')
- .toggleClass('selected', isSelected);
-
- });
- const noDataDisplayed = !state.hasData || !state.measures.length;
- this.$buttons.find('.o_pivot_flip_button').prop('disabled', noDataDisplayed);
- this.$buttons.find('.o_pivot_expand_button').prop('disabled', noDataDisplayed);
- this.$buttons.find('.o_pivot_download').prop('disabled', noDataDisplayed);
- },
//--------------------------------------------------------------------------
// Handlers