diff --git a/addons/account/static/src/js/account_journal_dashboard_widget.js b/addons/account/static/src/js/account_journal_dashboard_widget.js deleted file mode 100644 index f89c8409c16..00000000000 --- a/addons/account/static/src/js/account_journal_dashboard_widget.js +++ /dev/null @@ -1,100 +0,0 @@ -odoo.define('journal_dashboard', function (require) { -'use strict'; - -var kanban_widgets = require('web_kanban.widgets'); - -var JournalDashboardGraph = kanban_widgets.AbstractField.extend({ - start: function() { - this.graph_type = this.$node.attr('graph_type'); - this.data = JSON.parse(this.field.raw_value); - this.display_graph(); - return this._super(); - }, - - display_graph : function() { - var self = this; - nv.addGraph(function () { - self.$svg = self.$el.append(''); - - switch(self.graph_type) { - - case "line": - self.$svg.addClass('o_graph_linechart'); - - self.chart = nv.models.lineChart(); - self.chart.forceY([0]); - self.chart.options({ - x: function(d, u) { return u }, - margin: {'left': 0, 'right': 0, 'top': 0, 'bottom': 0}, - showYAxis: false, - showLegend: false, - }); - self.chart.xAxis - .tickFormat(function(d) { - var label = ''; - _.each(self.data, function(v, k){ - if (v.values[d] && v.values[d].x){ - label = v.values[d].x; - } - }); - return label; - }); - self.chart.yAxis - .tickFormat(d3.format(',.2f')); - - break; - - case "bar": - self.$svg.addClass('o_graph_barchart'); - - self.chart = nv.models.discreteBarChart() - .x(function(d) { return d.label }) - .y(function(d) { return d.value }) - .showValues(false) - .showYAxis(false) - .margin({'left': 0, 'right': 0, 'top': 0, 'bottom': 40}); - - self.chart.xAxis.axisLabel(self.data[0].title); - self.chart.yAxis.tickFormat(d3.format(',.2f')); - - break; - } - d3.select(self.$el.find('svg')[0]) - .datum(self.data) - .transition().duration(1200) - .call(self.chart); - - self.customize_chart(); - - nv.utils.windowResize(self.on_resize); - }); - }, - - on_resize: function(){ - this.chart.update(); - this.customize_chart(); - }, - - customize_chart: function(){ - if (this.graph_type === 'bar') { - // Add classes related to time on each bar of the bar chart - var bar_classes = _.map(this.data[0].values, function (v, k) {return v.type}); - - _.each(this.$('.nv-bar'), function(v, k){ - // classList doesn't work with phantomJS & addClass doesn't work with a SVG element - $(v).attr('class', $(v).attr('class') + ' ' + bar_classes[k]); - }); - } - }, - - destroy: function(){ - nv.utils.offWindowResize(this.on_resize); - this._super(); - }, - -}); - - -kanban_widgets.registry.add('dashboard_graph', JournalDashboardGraph); - -}); \ No newline at end of file diff --git a/addons/account/views/account.xml b/addons/account/views/account.xml index ccf43b8c9bd..47fe1f10667 100644 --- a/addons/account/views/account.xml +++ b/addons/account/views/account.xml @@ -12,7 +12,6 @@ - diff --git a/addons/web_kanban/static/src/js/kanban_widgets.js b/addons/web_kanban/static/src/js/kanban_widgets.js index a29105ed9b5..25e289cea4f 100644 --- a/addons/web_kanban/static/src/js/kanban_widgets.js +++ b/addons/web_kanban/static/src/js/kanban_widgets.js @@ -274,6 +274,97 @@ var KanbanMonetary = AbstractField.extend({ } }); +var DashboardGraph = AbstractField.extend({ + start: function() { + this.graph_type = this.$node.attr('graph_type'); + this.data = JSON.parse(this.field.raw_value); + this.display_graph(); + return this._super(); + }, + + display_graph : function() { + var self = this; + nv.addGraph(function () { + self.$svg = self.$el.append(''); + + switch(self.graph_type) { + + case "line": + self.$svg.addClass('o_graph_linechart'); + + self.chart = nv.models.lineChart(); + self.chart.forceY([0]); + self.chart.options({ + x: function(d, u) { return u }, + margin: {'left': 0, 'right': 0, 'top': 0, 'bottom': 0}, + showYAxis: false, + showLegend: false, + }); + self.chart.xAxis + .tickFormat(function(d) { + var label = ''; + _.each(self.data, function(v, k){ + if (v.values[d] && v.values[d].x){ + label = v.values[d].x; + } + }); + return label; + }); + self.chart.yAxis + .tickFormat(d3.format(',.2f')); + + break; + + case "bar": + self.$svg.addClass('o_graph_barchart'); + + self.chart = nv.models.discreteBarChart() + .x(function(d) { return d.label }) + .y(function(d) { return d.value }) + .showValues(false) + .showYAxis(false) + .margin({'left': 0, 'right': 0, 'top': 0, 'bottom': 40}); + + self.chart.xAxis.axisLabel(self.data[0].title); + self.chart.yAxis.tickFormat(d3.format(',.2f')); + + break; + } + d3.select(self.$el.find('svg')[0]) + .datum(self.data) + .transition().duration(1200) + .call(self.chart); + + self.customize_chart(); + + nv.utils.windowResize(self.on_resize); + }); + }, + + on_resize: function(){ + this.chart.update(); + this.customize_chart(); + }, + + customize_chart: function(){ + if (this.graph_type === 'bar') { + // Add classes related to time on each bar of the bar chart + var bar_classes = _.map(this.data[0].values, function (v, k) {return v.type}); + + _.each(this.$('.nv-bar'), function(v, k){ + // classList doesn't work with phantomJS & addClass doesn't work with a SVG element + $(v).attr('class', $(v).attr('class') + ' ' + bar_classes[k]); + }); + } + }, + + destroy: function(){ + nv.utils.offWindowResize(this.on_resize); + this._super(); + }, + +}); + var fields_registry = new Registry(); fields_registry @@ -284,6 +375,7 @@ fields_registry .add('float_time', FormatChar) .add('monetary', KanbanMonetary) .add('kanban_label_selection', KanbanLabelSelection) + .add('dashboard_graph', DashboardGraph) ; return {