【问题标题】:How to hide a custom Button in tree view如何在树视图中隐藏自定义按钮
【发布时间】:2020-07-03 13:53:48
【问题描述】:

我的列表视图中有一个自定义按钮“查看全部”,我希望它只对具有特定组访问权限的用户可见,我该如何实现?

我尝试为按钮添加组属性,但没有成功,

<template xml:space="preserve">
    <t t-extend="ListView.buttons">
        <t  t-jquery="button.o_list_button_add" t-operation="before">
            <button t-if="widget.modelName == 'leave.request.allocation'" type="button" class="btn btn-primary btn-sm oe_filter_button" accesskey="f" groups="hr_holidays.group_hr_holidays_manager">
                View All
            </button> 
        </t>
    </t>

【问题讨论】:

    标签: xml button odoo odoo-10


    【解决方案1】:

    在 ListView 上,它们具有 render_buttons 功能,该功能具有 js 级别。 因此,您可以添加条件以检查是否有您的组的用户,并根据该代码显示按钮和隐藏。 给你:

    var ListView = require('web.ListView');
    ListView.include({
        render_buttons: function($node) {
            this._super.apply(this, arguments);
            this.session.user_has_group('Your Group').then(function(has_group) {
                if (has_group) {
                    // Do Something
                } else {
                    // Do Something
                }
            });
        },
    });
    

    谢谢

    【讨论】:

    • 您好,感谢var user_group = self.getSession().user_has_group('Your Group')的回答,我在这里得到一个数组而不是布尔值
    • web.assets_backend.js:2474 {state: ƒ, always: ƒ, then: ƒ, promise: ƒ, pipe: ƒ, …} 这就是我得到的
    • @user9523333 this.session.user_has_group('Your Group').then(function(has_group) { if(has_group) { // 做某事 } else { // 做某事 } });
    • 您能否将最后一条评论编辑到您的答案中?
    猜你喜欢
    • 2011-03-22
    • 2019-01-04
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    相关资源
    最近更新 更多