From fe07dc2e6d67c32ebf6aab8e3e32e57f24886c28 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 9 Oct 2012 16:51:13 +0200 Subject: [PATCH] [FIX] Fixed on_switch_mode tirggering. bzr revid: vta@openerp.com-20121009145113-8sazhfrp3xaan5cq --- addons/web/static/src/js/view_form.js | 9 ++++-- addons/web/static/src/js/views.js | 32 ++++++++----------- addons/web_kanban/static/src/js/kanban.js | 4 +-- .../static/src/js/view_editor.js | 4 +-- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index db68b8d7a23..98fd83dadaf 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3370,10 +3370,13 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ } def.resolve(); }); - this.viewmanager.on('on_mode_switch',self,function(n_mode, b, c, d, e) { + this.viewmanager.on("on_mode_switch", self, function(n_mode, b, c, d, e) { $.when(self.save_any_view()).then(function() { - if(n_mode === "list") - $.async_when().then(function() {self.reload_current_view();}); + if (n_mode === "list") { + $.async_when().then(function() { + self.reload_current_view(); + }); + } }); }); this.is_setted.then(function() { diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 18d7e9d5666..e18a3e361be 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -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.on_mode_switch($(this).data('view-type')); + self.trigger('on_mode_switch', $(this).data('view-type')); }).tipsy(); var views_ids = {}; _.each(this.views_src, function(view) { @@ -439,16 +439,12 @@ 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; - return this.on_mode_switch(default_view); + this.on('on_mode_switch', self, function(view_type, no_store, view_options) { + self.switch_mode(view_type, no_store, view_options); + }); + return this.trigger('on_mode_switch', default_view); }, - /** - * Asks the view manager to switch visualization mode. - * - * @param {String} view_type type of view to display - * @param {Boolean} [no_store=false] don't store the view being switched to on the switch stack - * @returns {jQuery.Deferred} new view loading promise - */ - on_mode_switch: function(view_type, no_store, view_options) { + switch_mode: function(view_type, no_store, view_options) { var self = this; var view = this.views[view_type]; var view_promise; @@ -552,7 +548,7 @@ instance.web.ViewManager = instance.web.Widget.extend({ add_breadcrumb: function(on_reverse_breadcrumb) { var self = this; var views = [this.active_view || this.views_src[0].view_type]; - this.on('on_mode_switch',self,function(mode) { + this.on('on_mode_switch',self,function(mode) { var last = views.slice(-1)[0]; if (mode !== last) { if (mode !== 'form') { @@ -568,7 +564,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.on_mode_switch(view_to_select); + self.trigger('on_mode_switch', view_to_select); } }, get_title: function() { @@ -604,7 +600,7 @@ instance.web.ViewManager = instance.web.Widget.extend({ * consist to switch to the asked view. */ switch_view: function(view_type, no_store, options) { - return this.on_mode_switch(view_type, no_store, options); + return this.trigger('on_mode_switch', view_type, no_store, options); }, /** * Returns to the view preceding the caller view in this manager's @@ -623,12 +619,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.on_mode_switch('form'); + return this.trigger('on_mode_switch', '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.on_mode_switch('form'); + return this.trigger('on_mode_switch', 'form'); } - return this.on_mode_switch(previous_view, true); + return this.trigger('on_mode_switch', previous_view, true); }, /** * Sets up the current viewmanager's search view. @@ -897,7 +893,7 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({ }, action || {}); this.do_action(action); }, - on_mode_switch: function (view_type, no_store, options) { + switch_mode: function (view_type, no_store, options) { var self = this; return $.when(this._super.apply(this, arguments)).then(function () { @@ -932,7 +928,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.on_mode_switch(state.view_type, true); + return self.trigger('on_mode_switch', state.view_type, true) }) ); } diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index 41cc366226f..dae3d7b214d 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -194,7 +194,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({ }); var am = instance.webclient.action_manager; var form = am.dialog_widget.views.form.controller; - form.on_button_cancel.add_last(am.dialog.on_close); + form.on("on_button_cancel",self,am.dialog.on_close); form.on_created.add_last(function(r) { (new instance.web.DataSet(self, self.group_by_field.relation)).name_get([r.result]).then(function(new_record) { am.dialog.on_close(); @@ -672,7 +672,7 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({ }); var am = instance.webclient.action_manager; var form = am.dialog_widget.views.form.controller; - form.on_button_cancel.add_last(am.dialog.on_close); + form.on("on_button_cancel",self,am.dialog.on_close); form.on_saved.add_last(function() { am.dialog.on_close(); self.view.do_reload(); diff --git a/addons/web_view_editor/static/src/js/view_editor.js b/addons/web_view_editor/static/src/js/view_editor.js index e65f0ab5d38..f26e12a55d7 100644 --- a/addons/web_view_editor/static/src/js/view_editor.js +++ b/addons/web_view_editor/static/src/js/view_editor.js @@ -1014,9 +1014,7 @@ instance.web_view_editor.ViewEditor = instance.web.Widget.extend({ var action_manager = new instance.web.ActionManager(self); $.when(action_manager.do_action(action)).then(function() { var controller = action_manager.dialog_widget.views['form'].controller; - controller.on_button_cancel.add_last(function(){ - action_manager.destroy() - }); + controller.on("on_button_cancel",self,action_manager.destroy); controller.do_save.add_last(function(){ action_manager.destroy(); var value =controller.fields.name.get('value');