如何在看板视图中向按钮添加确认对话框?

时间:2019-04-08 02:06:42

标签: xml odoo odoo-11

我向看板视图中的按钮添加了一个Confirm属性,但它不会触发确认对话框。这是我的代码中出现按钮的一部分:

<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>

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

2 个答案:

答案 0 :(得分:0)

尝试此地雷使用此代码

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

答案 1 :(得分:0)

至少在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,
            });
        }**
    },

我希望这个解决方案能对其他人有所帮助。 谢谢您的时间