mahes
mahes

Reputation: 1152

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

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

This template is associated with a Javascript widget. I did render it in homepage using JavaScript as follows.

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?

Upvotes: 2

Views: 4536

Answers (1)

This is on V12.
I've used this function to check if the user is a public one (in my case, the public uid is 4):

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

Hope this helps.
Regards

Upvotes: 0

Related Questions