[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.
This commit is contained in:
Aaron Bohy
2015-01-27 17:25:38 +01:00
parent d22b94a699
commit c465605049
7 changed files with 30 additions and 42 deletions
-3
View File
@@ -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();
}
-1
View File
@@ -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 () {
-6
View File
@@ -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();
}
+9 -1
View File
@@ -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,
+21 -13
View File
@@ -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();
},
@@ -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;
@@ -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 });