[FIX] form shortcuts being somewhat active in listview leading to strange behaviors
added a predicate and a decorator to View, so that views can easily check if they are the active view and only execute relevant actions when they are. lp bug: https://launchpad.net/bugs/1067133 fixed bzr revid: xmo@openerp.com-20121113153610-7yogikfyg4rxwsjp
This commit is contained in:
parent
f736edb150
commit
7d18be69a5
|
@ -173,10 +173,14 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
|||
} else {
|
||||
this.$el.find('.oe_form_buttons').replaceWith(this.$buttons);
|
||||
}
|
||||
this.$buttons.on('click', '.oe_form_button_create', this.on_button_create);
|
||||
this.$buttons.on('click', '.oe_form_button_edit', this.on_button_edit);
|
||||
this.$buttons.on('click', '.oe_form_button_save', this.on_button_save);
|
||||
this.$buttons.on('click', '.oe_form_button_cancel', this.on_button_cancel);
|
||||
this.$buttons.on('click', '.oe_form_button_create',
|
||||
this.guard_active(this.on_button_create));
|
||||
this.$buttons.on('click', '.oe_form_button_edit',
|
||||
this.guard_active(this.on_button_edit));
|
||||
this.$buttons.on('click', '.oe_form_button_save',
|
||||
this.guard_active(this.on_button_save));
|
||||
this.$buttons.on('click', '.oe_form_button_cancel',
|
||||
this.guard_active(this.on_button_cancel));
|
||||
if (this.options.footer_to_buttons) {
|
||||
this.$el.find('footer').appendTo(this.$buttons);
|
||||
}
|
||||
|
|
|
@ -508,7 +508,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
|||
.find('.oe_view_manager_switch a').filter('[data-view-type="' + view_type + '"]')
|
||||
.parent().addClass('active');
|
||||
|
||||
r = $.when(view_promise).done(function () {
|
||||
return $.when(view_promise).done(function () {
|
||||
_.each(_.keys(self.views), function(view_name) {
|
||||
var controller = self.views[view_name].controller;
|
||||
if (controller) {
|
||||
|
@ -524,7 +524,6 @@ 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
|
||||
|
@ -1281,6 +1280,27 @@ instance.web.View = instance.web.Widget.extend({
|
|||
do_hide: function () {
|
||||
this.$el.hide();
|
||||
},
|
||||
is_active: function () {
|
||||
var manager = this.getParent();
|
||||
return !manager || !manager.active_view
|
||||
|| manager.views[manager.active_view].controller === this;
|
||||
}, /**
|
||||
* Wraps fn to only call it if the current view is the active one. If the
|
||||
* current view is not active, doesn't call fn.
|
||||
*
|
||||
* fn can not return anything, as a non-call to fn can't return anything
|
||||
* either
|
||||
*
|
||||
* @param {Function} fn function to wrap in the active guard
|
||||
*/
|
||||
guard_active: function (fn) {
|
||||
var self = this;
|
||||
return function () {
|
||||
if (self.is_active()) {
|
||||
fn.apply(self, arguments);
|
||||
}
|
||||
}
|
||||
},
|
||||
do_push_state: function(state) {
|
||||
if (this.getParent() && this.getParent().do_push_state) {
|
||||
this.getParent().do_push_state(state);
|
||||
|
|
Loading…
Reference in New Issue