[IMP] kpi_dashboard: edit color

This commit is contained in:
Enric Tobella
2020-07-29 18:43:01 +02:00
parent 612784b827
commit f6a4955151
6 changed files with 62 additions and 7 deletions

View File

@@ -11,11 +11,14 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
init: function () {
this._super.apply(this, arguments);
this.dashboard_context = {};
this.dashboard_color_data = []
},
custom_events: _.extend({}, BasicController.prototype.custom_events, {
addDashboard: '_addDashboard',
refresh_on_fly: '_refreshOnFly',
modify_context: '_modifyContext',
add_modify_color: '_addModifyColor',
refresh_colors: '_refreshColors',
}),
_refreshOnFly: function (event) {
var self = this;
@@ -112,7 +115,34 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
)}),
);
this._refreshOnFly(event);
}
this._refreshColors();
},
_addModifyColor: function (event) {
this.dashboard_color_data.push([
event.data.element_id,
event.data.expression,
]);
},
_refreshColors: function () {
var self = this;
var ctx = this._getContext();
_.each(this.dashboard_color_data, function (data) {
var color = py.eval(data[1], {
context: _.extend(ctx, {
__getattr__: function() {return false},
}),
check_if: function(args) {
if (args[0].toJSON()) {
return args[1];
}
return args[2];
}
});
var $element = self.renderer.$el.find('#' + data[0]);
$element.css('background-color', color);
});
},
});
return DashboardController;

View File

@@ -36,7 +36,14 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
'kpi_dashboard.kpi', {widget: kpi}));
element.css('background-color', kpi.color);
element.css('color', kpi.font_color);
element.attr('id', _.uniqueId('kpi_'));
self.$grid.append(element);
if (kpi.modify_color) {
self.trigger_up("add_modify_color", {
element_id: element.attr("id"),
expression: kpi.modify_color_expression,
})
}
if (kpi.modify_context) {
element.on("click", self._onClickModifyContext.bind(
self, kpi.modify_context_expression));
@@ -71,6 +78,10 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
self.trigger_up('refresh_on_fly');
}, this.state.specialData.compute_on_fly_refresh *1000);
};
this.trigger_up('refresh_colors');
this.trigger_up('refresh_on_fly');
// We need to refreshs data in order compute with the current
// context
return $.when();
},
on_detach_callback: function () {