如何将确认对话框添加到看板视图中的按钮?

问题描述 投票:1回答:2

我在看板视图中为按钮添加了确认属性,但它不会触发确认对话框。这是我的代码的一大块,其中出现按钮:

<templates>
    <t t-name="kanban-box">
        <div t-attf-class="oe_kanban_global_click">
            <!-- some code -->
            <div class="oe_kanban_bottom_left">
                <button name="action_restart"
                    type="object"
                    t-attf-class="btn btn-sm btn-primary"
                    style="margin-top:35px;"
                    confirm="Restart mtto?">Restart</button>
            </div>
        <div>
    <t>
<templates>

看板可以这样做吗?预先感谢

xml odoo odoo-11
2个回答
0
投票

试试这个我正在使用这个代码

<button class="btn btn-primary" name="action_restart" type="object" confirm="Restart mtto?">

0
投票

肯定Kanban不处理确认属性,至少在版本11.0之前。

要添加此功能,我修改了_onKanbanActionClicked函数:.. \ addons \ web \ static \ src \ js \ views \ kanban \ kanban_record.js

var Dialog = require("web.Dialog"); // at the top of the class


_onKanbanActionClicked: function (event) {
        event.preventDefault();

        **var _this = this;**
        var $action = $(event.currentTarget);
        var type = $action.data('type') || 'button';

        switch (type) {
            case 'edit':
                this.trigger_up('open_record', {id: this.db_id, mode: 'edit'});
                break;
            case 'open':
                this.trigger_up('open_record', {id: this.db_id});
                break;
            case 'delete':
                this.trigger_up('kanban_record_delete', {id: this.db_id, record: this});
                break;
            case 'action':
            case 'object':
                **var confirm = $(event.currentTarget).attr("confirm");
                if (confirm) {
                    Dialog.confirm(this, confirm, {
                        confirm_callback: object_trigger_up
                    });
                }
                else {
                    object_trigger_up();
                }**
                break;
            default:
                this.do_warn("Kanban: no action for type : " + type);
        }
        **function object_trigger_up () {
            _this.trigger_up('button_clicked', {
                attrs: $action.data(),
                record: _this.state,
            });
        }**
    },

我希望这个解决方案可以帮助其他人。谢谢你的时间

© www.soinside.com 2019 - 2024. All rights reserved.