mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[IMP] kpi_dashboard: edit color
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user