mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[IMP] kpi_dashboard: Allow to edit context using items
This commit is contained in:
@@ -8,9 +8,14 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
|
||||
var _t = core._t;
|
||||
|
||||
var DashboardController = BasicController.extend({
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.dashboard_context = {};
|
||||
},
|
||||
custom_events: _.extend({}, BasicController.prototype.custom_events, {
|
||||
addDashboard: '_addDashboard',
|
||||
refresh_on_fly: '_refreshOnFly',
|
||||
modify_context: '_modifyContext',
|
||||
}),
|
||||
_refreshOnFly: function (event) {
|
||||
var self = this;
|
||||
@@ -18,11 +23,7 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
|
||||
model: this.modelName,
|
||||
method: 'read_dashboard_on_fly',
|
||||
args: [[this.renderer.state.res_id]],
|
||||
context: _.extend(
|
||||
{},
|
||||
this.model.get(this.handle, {raw: true}).getContext(),
|
||||
{bin_size: true}
|
||||
),
|
||||
context: this._getContext(),
|
||||
}).then(function (data) {
|
||||
_.each(data, function (item) {
|
||||
// We will follow the same logic used on Bus Notifications
|
||||
@@ -91,6 +92,27 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
|
||||
this._updateButtons();
|
||||
this.$buttons.appendTo($node);
|
||||
},
|
||||
_getContext: function () {
|
||||
return _.extend(
|
||||
{},
|
||||
this.model.get(this.handle, {raw: true}).getContext(),
|
||||
{bin_size: true},
|
||||
this.dashboard_context,
|
||||
)
|
||||
},
|
||||
_modifyContext: function (event) {
|
||||
var ctx = this._getContext();
|
||||
this.dashboard_context = _.extend(
|
||||
this.dashboard_context,
|
||||
py.eval(event.data.context, {context: _.extend(
|
||||
ctx,
|
||||
{__getattr__: function() {return false}}
|
||||
// We need to add this in order to allow to use undefined
|
||||
// context items
|
||||
)}),
|
||||
);
|
||||
this._refreshOnFly(event);
|
||||
}
|
||||
});
|
||||
|
||||
return DashboardController;
|
||||
|
||||
@@ -16,6 +16,12 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
|
||||
var widget = new Widget(this, kpi);
|
||||
return widget;
|
||||
},
|
||||
_onClickModifyContext: function (modify_context_expression, event) {
|
||||
this.trigger_up('modify_context', {
|
||||
context: modify_context_expression,
|
||||
event: event,
|
||||
})
|
||||
},
|
||||
_renderView: function () {
|
||||
this.$el.html($(qweb.render('dashboard_kpi.dashboard')));
|
||||
this.$el.css(
|
||||
@@ -31,6 +37,12 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
|
||||
element.css('background-color', kpi.color);
|
||||
element.css('color', kpi.font_color);
|
||||
self.$grid.append(element);
|
||||
if (kpi.modify_context) {
|
||||
element.on("click", self._onClickModifyContext.bind(
|
||||
self, kpi.modify_context_expression));
|
||||
element.css('cursor', 'pointer');
|
||||
// We want to set it show as clickable
|
||||
}
|
||||
self.kpi_widget[kpi.id] = self._getDashboardWidget(kpi);
|
||||
self.kpi_widget[kpi.id].appendTo(element);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user