From bafa09f7e46201effdd36fe621f533b2ecda578d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 4 Sep 2014 15:39:14 +0200 Subject: [PATCH] [IMP] graph view integration into view manager header --- addons/web/static/src/css/base.css | 2 +- addons/web/static/src/css/base.sass | 2 +- addons/web/static/src/js/search.js | 2 +- addons/web_graph/static/src/js/graph_view.js | 9 ++- .../web_graph/static/src/js/graph_widget.js | 30 ++++++-- addons/web_graph/static/src/xml/web_graph.xml | 74 +++++-------------- 6 files changed, 56 insertions(+), 63 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index b93274afa4a..23f5782300c 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1084,7 +1084,7 @@ } .openerp .oe-view-manager-header { height: 90px; - overflow: hidden; + overflow: visible; border-bottom: 1px solid black; display: none; } diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 92b5211e256..e39f04f7559 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -936,7 +936,7 @@ $sheet-padding: 16px // ViewManager common {{{ .oe-view-manager-header height: 90px - overflow: hidden + overflow: visible border-bottom: 1px solid black display: none .oe-right-toolbar diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index e28b1185357..c07a82620a9 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -440,7 +440,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea if (view_manager) { this.view_manager = view_manager; view_manager.on('switch_mode', this, function (e) { - self.drawer.toggle(e === 'graph'); + self.drawer.toggle(false); }); } return $.when(p, this.ready); diff --git a/addons/web_graph/static/src/js/graph_view.js b/addons/web_graph/static/src/js/graph_view.js index a892f348511..dd4ba800245 100644 --- a/addons/web_graph/static/src/js/graph_view.js +++ b/addons/web_graph/static/src/js/graph_view.js @@ -31,10 +31,16 @@ instance.web_graph.GraphView = instance.web.View.extend({ get_domain: function () {}, get_groupby: function () {}, }; - + this.$buttons = options.$buttons; this.view_loaded = $.Deferred(); }, + start: function() { + var $buttons = instance.web.qweb.render("graph-view-buttons"); + this.$buttons.html($buttons); + return this._super(); + }, + view_loading: function (fields_view_get) { var self = this, arch = fields_view_get.arch; @@ -47,6 +53,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ row_groupby: [], col_groupby: [], graph_view: this, + $buttons: this.$buttons }; _.each(arch.children, function (field) { diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 97a5ad66d4e..fc1ed4a9296 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -26,6 +26,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.graph_view = options.graph_view || null; this.pivot_options = options; this.title = options.title || 'Data'; + this.$buttons = options.$buttons; }, start: function() { @@ -33,6 +34,25 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.table = $(''); this.$('.graph_main_content').append(this.table); + var $pivot_button = this.$buttons.find('.oe-pivot-mode'); + $pivot_button.click(function () { + self.set_mode.bind(self)('pivot'); + }); + this.$measure_list = this.$buttons.find('.oe-measure-list'); + + var $barchart_button = this.$buttons.find('.oe-bar-mode'); + $barchart_button.click(function () { + self.set_mode.bind(self)('bar'); + }); + var $line_chart_button = this.$buttons.find('.oe-line-mode'); + $line_chart_button.click(function () { + self.set_mode.bind(self)('line'); + }); + var $pie_chart_button = this.$buttons.find('.oe-pie-mode'); + $pie_chart_button.click(function () { + self.set_mode.bind(self)('pie'); + }); + var indexes = {'pivot': 0, 'bar': 1, 'line': 2, 'chart': 3}; this.$('.graph_mode_selection label').eq(indexes[this.mode]).addClass('active'); @@ -42,7 +62,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ } else { this.$('.graph_main_content').addClass('graph_pivot_mode'); } - // get search view var parent = this.getParent(); while (!(parent instanceof openerp.web.ViewManager)) { @@ -142,12 +161,13 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ }, add_measures_to_options: function() { - this.$('.graph_measure_selection').append( + this.$measure_list.append( _.map(this.measure_list, function (measure) { return $('
  • ').append($('').attr('data-choice', measure.field) .attr('href', '#') .text(measure.string)); })); + this.$measure_list.find('li').click(this.measure_selection.bind(this)); }, // ---------------------------------------------------------------------- @@ -281,11 +301,11 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ put_measure_checkmarks: function () { var self = this, - measures_li = this.$('.graph_measure_selection a'); - measures_li.removeClass('oe_selected'); + measures_li = this.$measure_list.find('li'); + measures_li.removeClass('active'); _.each(this.measure_list, function (measure, index) { if (_.findWhere(self.pivot.measures, measure)) { - measures_li.eq(index).addClass('oe_selected'); + measures_li.eq(index).addClass('active'); } }); diff --git a/addons/web_graph/static/src/xml/web_graph.xml b/addons/web_graph/static/src/xml/web_graph.xml index 828d184dc24..aac5f2433fd 100644 --- a/addons/web_graph/static/src/xml/web_graph.xml +++ b/addons/web_graph/static/src/xml/web_graph.xml @@ -1,59 +1,25 @@ + + +
    + + + + +
    +
    + + + +
    +
    + +
    +
    -
    - - -