From 276e081490430a62872febef6529fff6bf8edeea Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 6 Sep 2012 15:26:02 +0200 Subject: [PATCH] [FIX] Fixed muliple calls to FormView#can_be_discarded() [REM] Removed trigger_children bzr revid: fme@openerp.com-20120906132602-whcst4g0c16a6s5v --- addons/web/static/src/js/chrome.js | 16 +--------------- addons/web/static/src/js/view_form.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 0c32fdffff9..3114aaf315f 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -958,20 +958,6 @@ instance.web.Client = instance.web.Widget.extend({ has_uncommitted_changes: function() { return false; }, - trigger_children: function(events) { - // TODO: In the future, if we have more valid use cases in other objects, let's - // put this back in the EventDispatcherMixin as an option of trigger() - var children = this.getChildren(); - for (var i = 0; i < children.length; i++) { - var child = children[i]; - if (child.__eventDispatcherMixin) { - child.__edispatcherEvents.trigger.apply(child.__edispatcherEvents, arguments); - instance.webclient // Yuck! - .trigger_children.apply(child, arguments); - } - } - return this; - }, }); instance.web.WebClient = instance.web.Client.extend({ @@ -1151,7 +1137,7 @@ instance.web.WebClient = instance.web.Client.extend({ }, has_uncommitted_changes: function() { var $e = $.Event('clear_uncommitted_changes'); - this.trigger_children('clear_uncommitted_changes', $e); + instance.web.bus.trigger('clear_uncommitted_changes', $e); if ($e.isDefaultPrevented()) { return true; } else { diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index bf2bfc4c9fe..744aa8d000d 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -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('clear_uncommitted_changes', this, function(e) { + instance.web.bus.on('clear_uncommitted_changes', this, function(e) { if (!this.can_be_discarded()) { e.preventDefault(); } @@ -753,7 +753,13 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM return def.promise(); }, can_be_discarded: function() { - return !this.$el.is('.oe_form_dirty') || confirm(_t("Warning, the record has been modified, your changes will be discarded.\n\nAre you sure you want to leave this page ?")); + if (this.$el.is('.oe_form_dirty')) { + if (!confirm(_t("Warning, the record has been modified, your changes will be discarded.\n\nAre you sure you want to leave this page ?"))) { + return false; + } + this.$el.removeClass('oe_form_dirty'); + } + return true; }, /** * Triggers saving the form's record. Chooses between creating a new