[FIX] switch_view

bzr revid: al@openerp.com-20121010113025-qpz12d28uob7hab9
This commit is contained in:
Antony Lesuisse 2012-10-10 13:30:25 +02:00
parent b1fdaa4356
commit 4c7f416dd4
2 changed files with 15 additions and 22 deletions

View File

@ -3565,7 +3565,7 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({
});
this.__ignore_blur = false;
},
switch_view: function(mode, unused) {
do_switch_view: function(mode, unused) {
if (mode !== 'form') {
return this._super(mode, unused);
}

View File

@ -417,7 +417,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
this._super();
var self = this;
this.$el.find('.oe_view_manager_switch a').click(function() {
self.trigger('switch_mode', $(this).data('view-type'));
self.switch_mode($(this).data('view-type'));
}).tipsy();
var views_ids = {};
_.each(this.views_src, function(view) {
@ -439,8 +439,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
}
// If no default view defined, switch to the first one in sequence
var default_view = this.flags.default_view || this.views_src[0].view_type;
this.on('switch_mode', self, self.switch_mode);
return this.trigger('switch_mode', default_view);
return this.switch_mode(default_view);
},
switch_mode: function(view_type, no_store, view_options) {
var self = this;
@ -448,9 +447,9 @@ instance.web.ViewManager = instance.web.Widget.extend({
var view_promise;
var form = this.views['form'];
if (!view || (form && form.controller && !form.controller.can_be_discarded())) {
self.trigger('switch_mode', view_type, no_store, view_options);
return $.Deferred().reject();
}
if (!no_store) {
this.views_history.push(view_type);
}
@ -468,13 +467,12 @@ instance.web.ViewManager = instance.web.Widget.extend({
this.searchview[(view.controller.searchable === false || this.searchview.hidden) ? 'hide' : 'show']();
}
this.$el
.find('.oe_view_manager_switch a').parent().removeClass('active');
this.$el.find('.oe_view_manager_switch a').parent().removeClass('active');
this.$el
.find('.oe_view_manager_switch a').filter('[data-view-type="' + view_type + '"]')
.parent().addClass('active');
return $.when(view_promise).then(function () {
r = $.when(view_promise).then(function () {
_.each(_.keys(self.views), function(view_name) {
var controller = self.views[view_name].controller;
if (controller) {
@ -495,7 +493,9 @@ instance.web.ViewManager = instance.web.Widget.extend({
}
}
});
self.trigger('switch_mode', view_type, no_store, view_options);
});
return r;
},
do_create_view: function(view_type) {
// Lazy loading of views
@ -524,7 +524,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
if (view.embedded_view) {
controller.set_embedded_view(view.embedded_view);
}
controller.do_switch_view.add_last(_.bind(this.switch_view, this));
controller.on('switch_mode', self, this.switch_mode);
controller.do_prev_view.add_last(this.on_prev_view);
var container = this.$el.find(".oe_view_manager_view_" + view_type);
@ -562,7 +562,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
var view_to_select = views[index];
self.$el.show();
if (self.active_view !== view_to_select) {
self.trigger('switch_mode', view_to_select);
self.switch_mode(view_to_select);
}
},
get_title: function() {
@ -592,14 +592,6 @@ instance.web.ViewManager = instance.web.Widget.extend({
on_reverse_breadcrumb: on_reverse_breadcrumb,
});
},
/**
* Method used internally when a view asks to switch view. This method is meant
* to be extended by child classes to change the default behavior, which simply
* consist to switch to the asked view.
*/
switch_view: function(view_type, no_store, options) {
return this.trigger('switch_mode', view_type, no_store, options);
},
/**
* Returns to the view preceding the caller view in this manager's
* navigation history (the navigation history is appended to via
@ -617,12 +609,12 @@ instance.web.ViewManager = instance.web.Widget.extend({
if (options.created && current_view === 'form' && previous_view === 'list') {
// APR special case: "If creation mode from list (and only from a list),
// after saving, go to page view (don't come back in list)"
return this.trigger('switch_mode', 'form');
return this.switch_mode('form');
} else if (options.created && !previous_view && this.action && this.action.flags.default_view === 'form') {
// APR special case: "If creation from dashboard, we have no previous view
return this.trigger('switch_mode', 'form');
return this.switch_mode('form');
}
return this.trigger('switch_mode', previous_view, true);
return this.switch_mode(previous_view, true);
},
/**
* Sets up the current viewmanager's search view.
@ -926,7 +918,7 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({
if (state.view_type && state.view_type !== this.active_view) {
defs.push(
this.views[this.active_view].deferred.pipe(function() {
return self.trigger('switch_mode', state.view_type, true)
return self.switch_mode(state.view_type, true);
})
);
}
@ -1265,6 +1257,7 @@ instance.web.View = instance.web.Widget.extend({
* @param {String} view view type to switch to
*/
do_switch_view: function(view) {
this.trigger('switch_mode',view);
},
/**
* Cancels the switch to the current view, switches to the previous one