如何使用js隐藏/不可见odoo帮助台中的按钮

发布于 2025-01-11 17:33:12 字数 2621 浏览 1 评论 0原文

在 Odoo 版本 15 中,我创建了一个基于按钮 Accept 和 Deny 的 Js cod,并在 res users model 中创建了一个布尔字段。工作流程是:如果用户单击 Accept 按钮,布尔字段将变为 True,单击 Denay 按钮,布尔字段将更改为 False 状态。该功能运行良好。目前,我面临的问题是两个按钮都在页面刷新时显示。 基于用户可用性(基于布尔字段)显示一个按钮:

如何解决这个问题...实际上我只想在 XML 端

<templates>
     <t t-extend="ListView.buttons" t-name="AttendenceMarkListView.buttons">
        <t t-jquery="button.o_list_button_add" t-operation="after">
<!--            <t t-if="widget.isAvailable()">-->


            <button t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_accept_ticket">
                Accept
            </button>
            <button t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_deny_ticket">
                Deny
            </button>
<!--                  </t>-->
        </t>
    </t>
</templates>

和 JS 端

odoo.define('attendance.button.tree', function (require) {
"use strict";
    var core = require('web.core');
    var ListController = require('web.ListController');
    var ListView = require('web.ListView');
    var viewRegistry = require('web.view_registry');
    var rpc = require('web.rpc')

    var includeDict = {
        buttons_template: 'AttendenceMarkListView.buttons',
        renderButtons: function ($node) {
            this._super.apply(this, arguments);
            var self = this;
            this.$buttons.on('click', '.o_button_accept_ticket', this._onAcceptAttendance.bind(this));
            this.$buttons.on('click', '.o_button_deny_ticket', this._onDeclineAttendance.bind(this));
        },
        _onAcceptAttendance: function(){
            var self = this;
            this.$('.o_button_accept_ticket').hide();
            this.$('.o_button_deny_ticket').show();
            rpc.query({
            model: 'helpdesk.ticket',
            method: 'user_accept_ticket',
            args: [],
        }, {
            shadow: true,
        }).then(function () {

        });
        },
         _onDeclineAttendance: function(){
            var self = this;
            this.$('.o_button_deny_ticket').hide();
            this.$('.o_button_accept_ticket').show();
            rpc.query({
            model: 'helpdesk.ticket',
            method: 'user_decline_ticket',
            args: [],
        }, {
            shadow: true,
        }).then(function () {

        });
        },
    };

    ListController.include(includeDict);

});

In Odoo version 15 I created a Js cod Based on the button Accept and Deny and I created a boolean field in res users model. The workflow is: if the user clicks the Accept button the boolean field makes True and clicks the Denay button it change to False state. The Functionality is working well. Currently, the issue am facing is both buttons are showing on page refresh time. How to solve this ... Actually I want to show only One button based on the user availability( based on the Boolean field)

IN XML SIDE:

<templates>
     <t t-extend="ListView.buttons" t-name="AttendenceMarkListView.buttons">
        <t t-jquery="button.o_list_button_add" t-operation="after">
<!--            <t t-if="widget.isAvailable()">-->


            <button t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_accept_ticket">
                Accept
            </button>
            <button t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_deny_ticket">
                Deny
            </button>
<!--                  </t>-->
        </t>
    </t>
</templates>

and in JS side:

odoo.define('attendance.button.tree', function (require) {
"use strict";
    var core = require('web.core');
    var ListController = require('web.ListController');
    var ListView = require('web.ListView');
    var viewRegistry = require('web.view_registry');
    var rpc = require('web.rpc')

    var includeDict = {
        buttons_template: 'AttendenceMarkListView.buttons',
        renderButtons: function ($node) {
            this._super.apply(this, arguments);
            var self = this;
            this.$buttons.on('click', '.o_button_accept_ticket', this._onAcceptAttendance.bind(this));
            this.$buttons.on('click', '.o_button_deny_ticket', this._onDeclineAttendance.bind(this));
        },
        _onAcceptAttendance: function(){
            var self = this;
            this.$('.o_button_accept_ticket').hide();
            this.$('.o_button_deny_ticket').show();
            rpc.query({
            model: 'helpdesk.ticket',
            method: 'user_accept_ticket',
            args: [],
        }, {
            shadow: true,
        }).then(function () {

        });
        },
         _onDeclineAttendance: function(){
            var self = this;
            this.$('.o_button_deny_ticket').hide();
            this.$('.o_button_accept_ticket').show();
            rpc.query({
            model: 'helpdesk.ticket',
            method: 'user_decline_ticket',
            args: [],
        }, {
            shadow: true,
        }).then(function () {

        });
        },
    };

    ListController.include(includeDict);

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2025-01-18 17:33:12

模板:

<templates>
    <t t-extend="ListView.buttons" t-name="AttendenceMarkListView.buttons">
        <t t-jquery="button.o_list_button_add" t-operation="after">
                 <button id="button_accept" t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_accept_ticket">
                    Accept
                </button>
                <button id="button_reject" t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_deny_ticket">
                    Deny
                </button>

        </t>
    </t>
</templates>

**Js Side:**
odoo.define('attendance.button.tree', function (require) {
"use strict";
    var core = require('web.core');
    var ListController = require('web.ListController');
    var ListView = require('web.ListView');
    var viewRegistry = require('web.view_registry');
    var rpc = require('web.rpc')

    var includeDict = {
        buttons_template: 'AttendenceMarkListView.buttons',
        renderButtons: function ($node) {
            this._super.apply(this, arguments);
            var self = this;
            this.$buttons.on('click', '.o_button_accept_ticket', this._onAcceptAttendance.bind(this));
            this.$buttons.on('click', '.o_button_deny_ticket', this._onDeclineAttendance.bind(this));

        },
        _onAcceptAttendance: function(){
            var self = this;
            this.$('.o_button_accept_ticket').hide();
            this.$('.o_button_deny_ticket').show();
            return self._rpc({
            model: 'helpdesk.ticket',
            method: 'user_accept_ticket',
            args: [],
            }).then(function (data) {

            });
        },

         _onDeclineAttendance: function(){
            var self = this;
            this.$('.o_button_deny_ticket').hide();
            this.$('.o_button_accept_ticket').show();
            return self._rpc({
                model: 'helpdesk.ticket',
                method: 'user_decline_ticket',
                args: [],
            }).then(function (data) {
                      

                });
        },



    };

    ListController.include(includeDict);

});

Template :

<templates>
    <t t-extend="ListView.buttons" t-name="AttendenceMarkListView.buttons">
        <t t-jquery="button.o_list_button_add" t-operation="after">
                 <button id="button_accept" t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_accept_ticket">
                    Accept
                </button>
                <button id="button_reject" t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_deny_ticket">
                    Deny
                </button>

        </t>
    </t>
</templates>

**Js Side:**
odoo.define('attendance.button.tree', function (require) {
"use strict";
    var core = require('web.core');
    var ListController = require('web.ListController');
    var ListView = require('web.ListView');
    var viewRegistry = require('web.view_registry');
    var rpc = require('web.rpc')

    var includeDict = {
        buttons_template: 'AttendenceMarkListView.buttons',
        renderButtons: function ($node) {
            this._super.apply(this, arguments);
            var self = this;
            this.$buttons.on('click', '.o_button_accept_ticket', this._onAcceptAttendance.bind(this));
            this.$buttons.on('click', '.o_button_deny_ticket', this._onDeclineAttendance.bind(this));

        },
        _onAcceptAttendance: function(){
            var self = this;
            this.$('.o_button_accept_ticket').hide();
            this.$('.o_button_deny_ticket').show();
            return self._rpc({
            model: 'helpdesk.ticket',
            method: 'user_accept_ticket',
            args: [],
            }).then(function (data) {

            });
        },

         _onDeclineAttendance: function(){
            var self = this;
            this.$('.o_button_deny_ticket').hide();
            this.$('.o_button_accept_ticket').show();
            return self._rpc({
                model: 'helpdesk.ticket',
                method: 'user_decline_ticket',
                args: [],
            }).then(function (data) {
                      

                });
        },



    };

    ListController.include(includeDict);

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文