From c465605049bdce16621e4e5f57c52ebab23de813 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 27 Jan 2015 12:15:36 +0100 Subject: [PATCH] [FIX] Web: views.js and view_pivot.js: sidebar The sidebar in view pivot was not hidden when switching from view pivot to another view. Thus, the sidebar content of view pivot was still in a dropdown of the sidebar of the new view (when this new view has a sidebar as well). Also changed the way of switching between views: we now first hide the current view before creating and displaying the new one. This prevents weird rendering in the header as well. Moreover, the task of hidding/showing the view's buttons is left to the view instead of the ViewManager. --- addons/web/static/src/js/view_form.js | 3 -- addons/web/static/src/js/view_graph.js | 1 - addons/web/static/src/js/view_list.js | 6 ---- addons/web/static/src/js/view_pivot.js | 10 +++++- addons/web/static/src/js/views.js | 34 ++++++++++++------- .../static/src/js/web_calendar.js | 9 ----- addons/web_kanban/static/src/js/kanban.js | 9 ----- 7 files changed, 30 insertions(+), 42 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 50b579f35d9..4f8fc48094c 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -309,9 +309,6 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM if (this.sidebar) { this.sidebar.$el.hide(); } - if (this.$buttons) { - this.$buttons.hide(); - } if (this.$pager) { this.$pager.hide(); } diff --git a/addons/web/static/src/js/view_graph.js b/addons/web/static/src/js/view_graph.js index dea16c3396c..385f347e307 100644 --- a/addons/web/static/src/js/view_graph.js +++ b/addons/web/static/src/js/view_graph.js @@ -26,7 +26,6 @@ instance.web.GraphView = instance.web.View.extend({ this.measures = []; this.active_measure = '__count__'; this.initial_groupbys = []; - this.$buttons = options.$buttons; this.widget = undefined; }, start: function () { diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index b4410a9f811..4333731b93e 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -472,9 +472,6 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi }, do_show: function () { this._super(); - if (this.$buttons) { - this.$buttons.show(); - } if (this.$pager) { this.$pager.show(); } @@ -483,9 +480,6 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi if (this.sidebar) { this.sidebar.$el.hide(); } - if (this.$buttons) { - this.$buttons.hide(); - } if (this.$pager) { this.$pager.hide(); } diff --git a/addons/web/static/src/js/view_pivot.js b/addons/web/static/src/js/view_pivot.js index 34846236aea..ed0b65c9702 100644 --- a/addons/web/static/src/js/view_pivot.js +++ b/addons/web/static/src/js/view_pivot.js @@ -30,7 +30,6 @@ instance.web.PivotView = instance.web.View.extend({ this._super(parent, dataset, view_id, options); this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); - this.$buttons = options.$buttons; this.$sidebar = options.$sidebar; this.fields = {}; this.measures = {}; @@ -165,6 +164,9 @@ instance.web.PivotView = instance.web.View.extend({ }, do_show: function () { var self = this; + if (this.sidebar) { + this.sidebar.$el.show(); + } this.do_push_state({}); this.data_loaded.done(function () { self.display_table(); @@ -172,6 +174,12 @@ instance.web.PivotView = instance.web.View.extend({ }); return this._super(); }, + do_hide: function () { + if (this.sidebar) { + this.sidebar.$el.hide(); + } + this._super(); + }, get_context: function () { return !this.ready ? {} : { pivot_measures: this.active_measures, diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index d602675d69c..c01a648745d 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -630,6 +630,9 @@ instance.web.ViewManager = instance.web.Widget.extend({ action : self.action, action_views_ids : views_ids, }, self.flags, self.flags[view.type], view.options); + // show options.$buttons as views will put their $buttons inside it + // and call show/hide on them + view.options.$buttons.show(); self.$('.oe-vm-switch-' + view.type).tooltip(); }); this.$('.oe_debug_view').click(this.on_debug_changed); @@ -652,7 +655,15 @@ instance.web.ViewManager = instance.web.Widget.extend({ } this.view_stack.push(view); + + // Hide active view (at first rendering, there is no view to hide) + if (this.active_view && + this.active_view != view && + this.active_view.controller) { + this.active_view.controller.do_hide(); + } this.active_view = view; + if (!view.created) { view.created = this.create_view.bind(this)(view); } @@ -669,7 +680,7 @@ instance.web.ViewManager = instance.web.Widget.extend({ self.update_header(); return $.when(view.created, this.active_search).done(function () { self.active_view = view; - self._display_view(view.type, view_options); + self._display_view(view_options); self.trigger('switch_mode', view_type, no_store, view_options); if (self.session.debug) { self.$('.oe_debug_view').html(QWeb.render('ViewManagerDebug', { @@ -683,20 +694,10 @@ instance.web.ViewManager = instance.web.Widget.extend({ this.$switch_buttons.removeClass('active'); this.$('.oe-vm-switch-' + this.active_view.type).addClass('active'); }, - _display_view: function (view_type, view_options) { + _display_view: function (view_options) { var self = this; this.active_view.$container.show(); - $.when(this.active_view.controller.do_show(view_options)).done(function () { - _.each(self.views, function (view) { - if (view.type !== view_type) { - if (view.controller) view.controller.do_hide(); - if (view.$container) view.$container.hide(); - if (view.options.$buttons) view.options.$buttons.hide(); - } - }); - if (self.active_view.options.$buttons) { - self.active_view.options.$buttons.show(); - } + $.when(this.active_view.controller.do_show(view_options)).done(function () { if (self.searchview) { var is_hidden = self.active_view.controller.searchable === false; self.searchview.toggle_visibility(!is_hidden); @@ -1220,6 +1221,7 @@ instance.web.View = instance.web.Widget.extend({ this.ViewManager = parent; this.dataset = dataset; this.view_id = view_id; + this.$buttons = options && options.$buttons; this.set_default_options(options); }, start: function () { @@ -1362,6 +1364,9 @@ instance.web.View = instance.web.Widget.extend({ }, do_show: function () { var self = this; + if (this.$buttons) { + this.$buttons.show(); + } this.$el.show(); setTimeout(function () { self.$el.parent().addClass('in'); @@ -1370,6 +1375,9 @@ instance.web.View = instance.web.Widget.extend({ instance.web.bus.trigger('view_shown', this); }, do_hide: function () { + if (this.$buttons) { + this.$buttons.hide(); + } this.$el.parent().removeClass('in'); this.$el.hide(); }, diff --git a/addons/web_calendar/static/src/js/web_calendar.js b/addons/web_calendar/static/src/js/web_calendar.js index 07480a3965f..43d0249ce88 100644 --- a/addons/web_calendar/static/src/js/web_calendar.js +++ b/addons/web_calendar/static/src/js/web_calendar.js @@ -880,19 +880,10 @@ openerp.web_calendar = function(instance) { }, do_show: function() { - if (this.$buttons) { - this.$buttons.show(); - } this.do_push_state({}); this.shown.resolve(); return this._super(); }, - do_hide: function () { - if (this.$buttons) { - this.$buttons.hide(); - } - return this._super(); - }, is_action_enabled: function(action) { if (action === 'create' && !this.options.creatable) { return false; diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index 08b61c7b187..d2bbb9045de 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -518,18 +518,9 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ }, do_show: function() { - if (this.options.$buttons) { - this.$buttons.show(); - } this.do_push_state({}); return this._super(); }, - do_hide: function () { - if (this.$buttons) { - this.$buttons.hide(); - } - return this._super(); - }, open_record: function(id, editable) { if (this.dataset.select_id(id)) { this.do_switch_view('form', null, { mode: editable ? "edit" : undefined });