diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 5293ee6f4b6..7beb15a9d70 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -87,6 +87,41 @@ return AbstractController.extend(FieldManagerMixin, { // Private //-------------------------------------------------------------------------- + /** + * When the user clicks on a 'action button', this function determines what + * should happen. + * + * @private + * @param {Object} attrs the attrs of the button clicked + * @param {Object} [record] the current state of the view + * @returns {Deferred} + */ + _callButtonAction: function (attrs, record) { + var self = this; + var def = $.Deferred(); + var reload = function () { + if (!self.isDestroyed()) { + self.reload(); + } + }; + record = record || this.model.get(this.handle); + var recordID = record.data.id; + this.trigger_up('execute_action', { + action_data: _.extend({}, attrs, { + context: record.getContext({additionalContext: attrs.context}), + }), + model: record.model, + record_id: recordID, + on_closed: function (reason) { + if (!_.isObject(reason)) { + reload(); + } + }, + on_fail: reload, + on_success: def.resolve.bind(def), + }); + return this.alive(def); + }, /** * Called by the field manager mixin to confirm that a change just occured * (after that potential onchanges have been applied). diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js index e833c80e3b2..981d614f52c 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -260,41 +260,6 @@ var FormController = BasicController.extend({ // Private //-------------------------------------------------------------------------- - /** - * When the user clicks on a form button, this function determines what - * should happen. - * - * @private - * @param {Object} attrs the attrs of the button clicked - * @param {Object} [record] the current state of the view - * @returns {Deferred} - */ - _callButtonAction: function (attrs, record) { - var self = this; - var def = $.Deferred(); - var reload = function () { - if (!self.isDestroyed()) { - self.reload(); - } - }; - record = record || this.model.get(this.handle); - var recordID = record.data.id; - this.trigger_up('execute_action', { - action_data: _.extend({}, attrs, { - context: record.getContext({additionalContext: attrs.context}), - }), - model: record.model, - record_id: recordID, - on_closed: function (reason) { - if (!_.isObject(reason)) { - reload(); - } - }, - on_fail: reload, - on_success: def.resolve.bind(def), - }); - return this.alive(def); - }, /** * When a save operation has been confirmed from the model, this method is * called. diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js index 1f5bb64cac8..d4d1fe9debe 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -210,11 +210,8 @@ var ListController = BasicController.extend({ * @param {OdooEvent} event */ _onButtonClicked: function (event) { - this.trigger_up('execute_action', { - action_data: event.data.attrs, - model: this.modelName, - record_id: event.data.record.res_id, - }); + event.stopPropagation(); + this._callButtonAction(event.data.attrs, event.data.record); }, /** * This event is triggered when a list renderer goes from mode = readonly to diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 59a7aa774b8..a3abe59892b 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -969,7 +969,7 @@ QUnit.module('Views', { }); QUnit.test('click on a button in a list view', function (assert) { - assert.expect(6); + assert.expect(9); var list = createView({ View: ListView, @@ -979,6 +979,10 @@ QUnit.module('Views', { '' + '