[IMP] Refactored has_uncommitted_changes in order to use trigger_children

bzr revid: fme@openerp.com-20120906102526-vthdib9qfeijywo8
This commit is contained in:
Fabien Meghazi 2012-09-06 12:25:26 +02:00
parent c58b567d94
commit c43e9bce27
3 changed files with 24 additions and 23 deletions

View File

@ -871,10 +871,12 @@ instance.web.UserMenu = instance.web.Widget.extend({
},
on_menu_settings: function() {
var self = this;
self.rpc("/web/action/load", { action_id: "base.action_res_users_my" }, function(result) {
result.result.res_id = instance.session.uid;
self.getParent().action_manager.do_action(result.result);
});
if (!this.getParent().has_uncommitted_changes()) {
self.rpc("/web/action/load", { action_id: "base.action_res_users_my" }, function(result) {
result.result.res_id = instance.session.uid;
self.getParent().action_manager.do_action(result.result);
});
}
},
on_menu_about: function() {
var self = this;
@ -952,7 +954,10 @@ instance.web.Client = instance.web.Widget.extend({
},
toggle_bars: function(value) {
this.$('tr:has(td.oe_topbar),.oe_leftbar').toggle(value);
}
},
has_uncommitted_changes: function() {
return false;
},
});
instance.web.WebClient = instance.web.Client.extend({
@ -1051,10 +1056,7 @@ instance.web.WebClient = instance.web.Client.extend({
n.warn.apply(n, arguments);
},
on_logout: function() {
var self = this;
var $e = $.Event("about_to_destroy");
this.action_manager.inner_widget.trigger("about_to_destroy", $e);
if (!$e.isDefaultPrevented()) {
if (!this.has_uncommitted_changes()) {
this.session.session_logout().then(function () {
$(window).unbind('hashchange', self.on_hashchange);
self.do_push_state({});
@ -1131,7 +1133,16 @@ instance.web.WebClient = instance.web.Client.extend({
$(".oe_webclient", this.$el).removeClass("oe_content_full_screen");
$("body").css({'overflow-y':'scroll'});
}
}
},
has_uncommitted_changes: function() {
var $e = $.Event('clear_uncommitted_changes');
this.trigger_children('clear_uncommitted_changes', $e);
if ($e.isDefaultPrevented()) {
return true;
} else {
return this._super.apply(this, arguments);
}
},
});
instance.web.EmbeddedClient = instance.web.Client.extend({

View File

@ -92,7 +92,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
self.on("change:actual_mode", self, self.init_pager);
self.init_pager();
});
this.on('about_to_destroy', this, function(e) {
this.on('clear_uncommitted_changes', this, function(e) {
if (!this.can_be_discarded()) {
e.preventDefault();
}

View File

@ -125,9 +125,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
return item.widget === it.widget;
});
if (!dups.length) {
var $e = $.Event("about_to_destroy");
item.widget.trigger("about_to_destroy", $e);
if ($e.isDefaultPrevented()) {
if (this.getParent().has_uncommitted_changes()) {
this.inner_widget = item.widget;
this.breadcrumbs.splice(index, 0, item);
return false;
@ -260,9 +258,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
ir_actions_common: function(action, on_close, clear_breadcrumbs) {
var self = this, klass, widget, post_process;
if (this.inner_widget && (action.type === 'ir.actions.client' || action.target !== 'new')) {
var $e = $.Event("about_to_destroy");
this.inner_widget.trigger("about_to_destroy", $e);
if ($e.isDefaultPrevented()) {
if (this.getParent().has_uncommitted_changes()) {
return $.Deferred().reject();
} else if (clear_breadcrumbs) {
this.clear_breadcrumbs();
@ -497,12 +493,6 @@ instance.web.ViewManager = instance.web.Widget.extend({
}
var controller = new viewclass(this, this.dataset, view.view_id, options);
if (view_type === 'form') {
this.on('about_to_destroy', this, function(e) {
controller.trigger('about_to_destroy', e);
});
}
controller.on('history_back', this, function() {
var am = self.getParent();
if (am && am.trigger) {