diff --git a/addons/report/static/src/js/client_action.js b/addons/report/static/src/js/client_action.js index 22d53d57eea..4538b9df11b 100644 --- a/addons/report/static/src/js/client_action.js +++ b/addons/report/static/src/js/client_action.js @@ -13,6 +13,7 @@ var QWeb = core.qweb; var AUTHORIZED_MESSAGES = [ 'report.editor:save_ok', 'report.editor:discard_ok', + 'report:do_action', ]; var ReportAction = Widget.extend(ControlPanelMixin, { @@ -124,6 +125,9 @@ var ReportAction = Widget.extend(ControlPanelMixin, { // Check the syntax of the received message. var message = ev.originalEvent.data; + if (_.isObject(message)) { + message = message.message; + } if (! _.isString(message) || (_.isString(message) && ! _.contains(AUTHORIZED_MESSAGES, message))) { return; } @@ -141,6 +145,8 @@ var ReportAction = Widget.extend(ControlPanelMixin, { this.in_edit_mode = false; this._update_control_panel_buttons(); break; + case 'report:do_action': + return this.do_action(ev.originalEvent.data.action); default: } } diff --git a/addons/report/static/src/js/report.editor.js b/addons/report/static/src/js/report.editor.js index 21c8500b6ed..5b58793bbf5 100644 --- a/addons/report/static/src/js/report.editor.js +++ b/addons/report/static/src/js/report.editor.js @@ -63,6 +63,29 @@ if (window.self !== window.top) { } } }, false); + + // Allow to send commands to the webclient when the editor is disabled. + if (window.location.search.indexOf('enable_editor') === -1) { + // `do_action` command + $('[res-id][res-model][view-type]') + .wrap('') + .attr('href', '#') + .on('click', function (ev) { + ev.preventDefault(); + var action = { + 'type': 'ir.actions.act_window', + 'view_type': $(this).attr('view-type'), + 'view_mode': $(this).attr('view-mode') || $(this).attr('view-type'), + 'res_id': Number($(this).attr('res-id')), + 'res_model': $(this).attr('res-model'), + 'views': [[$(this).attr('view-id') || false, $(this).attr('view-type')]], + }; + window.parent.postMessage({ + 'message': 'report:do_action', + 'action': action, + }, trusted_origin); + }); + } } options.registry.many2one.include({