From 604bd9fa4da689e3162a295ecd2959a764bd4eef Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 5 Sep 2012 14:35:32 +0200 Subject: [PATCH] [WIP] Notification on do_action and on_mode_switch bzr revid: fme@openerp.com-20120905123532-oskxl7srmoabkqr5 --- addons/web/static/src/js/chrome.js | 3 +-- addons/web/static/src/js/view_form.js | 5 ++++ addons/web/static/src/js/views.js | 38 ++++++++++++++++++++------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 736e10875f6..3dd7672287f 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1101,8 +1101,7 @@ instance.web.WebClient = instance.web.Client.extend({ if (options.needaction) { action.context.search_default_needaction_pending = true; } - self.action_manager.clear_breadcrumbs(); - self.action_manager.do_action(action); + self.action_manager.do_action(action, null, true); }); }, do_action: function(action) { diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index f65da67d8fb..e6bbb664eaf 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -92,6 +92,11 @@ 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) { + if (!this.can_be_discarded()) { + e.preventDefault(); + } + }); }, destroy: function() { _.each(this.get_widgets(), function(w) { diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 95693ca9c50..20f7b12c0ac 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -113,6 +113,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ while (this.breadcrumbs.length) { this.remove_breadcrumb(0); } + this.inner_widget = null; }, remove_breadcrumb: function(index) { var item = this.breadcrumbs.splice(index, 1)[0]; @@ -208,14 +209,14 @@ instance.web.ActionManager = instance.web.Widget.extend({ } }); }, - do_action: function(action, on_close) { + do_action: function(action, on_close, clear_breadcrumbs) { if (_.isString(action) && instance.web.client_actions.contains(action)) { var action_client = { type: "ir.actions.client", tag: action }; - return this.do_action(action_client); + return this.do_action(action_client, on_close, clear_breadcrumbs); } else if (_.isNumber(action) || _.isString(action)) { var self = this; return self.rpc("/web/action/load", { action_id: action }, function(result) { - self.do_action(result.result, on_close); + self.do_action(result.result, on_close, clear_breadcrumbs); }); } if (!action.type) { @@ -237,14 +238,23 @@ instance.web.ActionManager = instance.web.Widget.extend({ console.error("Action manager can't handle action of type " + action.type, action); return null; } - return this[type](action, on_close); + return this[type](action, on_close, clear_breadcrumbs); }, null_action: function() { this.dialog_stop(); this.clear_breadcrumbs(); }, - ir_actions_common: function(action, on_close) { + 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()) { + return; + } else if (clear_breadcrumbs) { + this.clear_breadcrumbs(); + } + } if (action.type === 'ir.actions.client') { var ClientWidget = instance.web.client_actions.get_object(action.tag); widget = new ClientWidget(this, action.params); @@ -287,17 +297,17 @@ instance.web.ActionManager = instance.web.Widget.extend({ this.inner_widget.appendTo(this.$el); } }, - ir_actions_act_window: function (action, on_close) { + ir_actions_act_window: function (action, on_close, clear_breadcrumbs) { var self = this; if (action.target !== 'new') { if(action.menu_id) { this.dialog_stop(); return this.getParent().do_action(action, function () { instance.webclient.menu.open_menu(action.menu_id); - }); + }, clear_breadcrumbs); } } - return this.ir_actions_common(action, on_close); + return this.ir_actions_common(action, on_close, clear_breadcrumbs); }, ir_actions_client: function (action, on_close) { return this.ir_actions_common(action, on_close); @@ -314,7 +324,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ action_id: action.id, context: action.context || {} }).then(function (action) { - self.do_action(action, on_closed) + self.do_action(action, on_closed, clear_breadcrumbs) }); }, ir_actions_report_xml: function(action, on_closed) { @@ -412,8 +422,10 @@ instance.web.ViewManager = instance.web.Widget.extend({ var self = this; var view = this.views[view_type]; var view_promise; - if(!view) + var form = this.views['form']; + if (!view || (form && form.controller && !form.controller.can_be_discarded())) { return $.Deferred().reject(); + } if (!no_store) { this.views_history.push(view_type); @@ -472,6 +484,12 @@ 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) {