简体   繁体   English

在 Odoo 网站中创建模态对话框

[英]Create a Modal Dialog in Odoo Website

I did create my Modal Popup in xml and put it in /my_module/static/src/xml/ folder我确实在 xml 中创建了我的模态弹出窗口并将其放在/my_module/static/src/xml/文件夹中

<t t-name="my_module.homepage_modal">
<!-- modal popup content , Signup prompt-->
</t>

This template is associated with a Javascript widget.此模板与 Javascript 小部件相关联。 I did render it in homepage using JavaScript as follows.我确实使用 JavaScript 在主页中呈现它,如下所示。

ajax.loadXML('/my_module/static/src/xml/modal_view.xml', qweb);

var ModalPopup = Widget.extend({
    template: 'my_module.homepage_modal',

    start: function () {
        this.$el.modal();
    },
});

base.ready().done(function() {

    if (location.pathname == '/'){
        var modal1 = new ModalPopup();
        modal1.appendTo($(document.body));

    };

});`

I have to render this Popup only when the user is not logged in (ie Public user).我必须仅在用户未登录(即公共用户)时呈现此弹出窗口。 How can I do this?我怎样才能做到这一点? How can I check the current user id from JavaScript?如何从 JavaScript 检查当前用户 ID?

This is on V12.这是在 V12 上。
I've used this function to check if the user is a public one (in my case, the public uid is 4):我已经使用这个 function 来检查用户是否是公共用户(在我的例子中,公共 uid 是 4):

function is_public_user() {
    return this.odoo.session_info.user_id == 4;
}

Hope this helps.希望这可以帮助。
Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM