Menu

Trợ giúp

0

Open a particular window using javascript: how can I do it?

Avatar
Daniele Lanfranchi

I have a button opening a window from javascript:

var self=this;
            this.$(".oe_write_full").click(function (event) {
                event.stopPropagation();
                var action = {
                    type: 'ir.actions.act_window',
                    res_model: 'mail.compose.message',
                    view_mode: 'form',
                    view_type: 'form',
                    action_from: 'mail.ThreadComposeMessage',
                    views: [[false, 'form']],
                    target: 'new',
                    context: {

                    },
                };
                session.client.action_manager.do_action(action);
            });

I have two ir.actions.act_window for the same res_model (mail.compose.message).

How can I choose which window open? Can I do it using do_action()?

 

Ảnh đại diện
Huỷ bỏ
2 Trả lời
1
Avatar
Ivan
Best Answer

Daniele, I do not have experience in coding the javascript part yet.  But AFAIK, you don't need to know which action to trigger, what you need is actually the view that you intend to show, which you can specify in the views attribute.

2 Bình luận
Ảnh đại diện
Huỷ bỏ
Avatar
Daniele Lanfranchi
-

Thanks Jon Doe, I really appreciate your help, it works! var self=this; this.$(".oe_write_full").click(function (event) { event.stopPropagation(); var action = { type: 'ir.actions.act_window', res_model: 'mail.compose.message', view_mode: 'form', view_type: 'form', action_from: 'mail.ThreadComposeMessage', views: [['590', 'form']], target: 'new', context: { }, }; session.client.action_manager.do_action(action); });

Avatar
Ivan
-

Daniele, you might want to tweak your code a bit. The ID 590 of your view will not be the same in other databases, so you need to either translate it from XML ID or search it by other means.

0
Avatar
Mihai Pop
Best Answer

Hi Daniele. I am interested in your approach to run an action. 

I tried your line:  session.client.action_manager.do_action(action); but it says:  Cannot read property 'action_manager' of undefined.


I am using odoo13. Is it different in this version?

Ảnh đại diện
Huỷ bỏ