odoo tree视图按钮加入confirm弹框

此confirm弹框odoo14版本的,其他版本JS方法可能不同,参考就行

odoo.define('mrp_revolve.add_tree_button_confirm', function (require) {
    "use strict";
    var Dialog = require('web.Dialog'); //引入odoo的dialog弹窗对象
    var ListController = require('web.ListController');
    var core = require('web.core');
    var _t = core._t;

    ListController.include({
        /**
         * _onHeaderButtonClicked方法 是给tree视图header按钮加入confirm属性
         * _onButtonClicked方法 给tree视图行内按钮加入confirm属性
         * 文末对header按钮和行内按钮有介绍
         */
        async _onHeaderButtonClicked(node) {
            this._disableButtons();
            const state = this.model.get(this.handle);
            const actionData = Object.assign({}, node.attrs, {
                context: state.getContext({ additionalContext: node.attrs.context }),
            });
            const resIds = await this.getSelectedIdsWithDomain();
            const recordData = {
                context: state.getContext(),
                model: state.model,
                resIDs: resIds,
            };
            const confirm = node.attrs.confirm;
            const self = this;
            if (confirm) {
               new Dialog(this, {
                   title: '警告',
                   size: 'medium',
                   $content: $('
', {text: confirm}), buttons: [{ text: '确认', classes : "btn-primary", click: function () { self._executeButtonAction(actionData, recordData); self._enableButtons(); }, close:true, }, { text: _t("Cancel"), close: true, }], }).open(); } else { self._executeButtonAction(actionData, recordData); self._enableButtons(); } }, _onButtonClicked: function (ev) { var self = this; ev.stopPropagation(); var confirm = ev.data.attrs.confirm; if (confirm) { new Dialog(this, { title: '警告', size: 'medium', $content: $('
', {text: confirm}), buttons: [{ text: '确认', classes : "btn-primary", click: function () { self._callButtonAction(ev.data.attrs, ev.data.record); }, close:true, }, { text: _t("Cancel"), close: true, }], }).open(); } else { this._callButtonAction(ev.data.attrs, ev.data.record); } }, }); });

然后button里面加入confirm属性
odoo tree视图按钮加入confirm弹框_第1张图片

这里解释一下 运算结果 是header按钮, hahah 是行内按钮
odoo tree视图按钮加入confirm弹框_第2张图片
最后不要忘了引入这个JS, odoo14引入方法,src是你这个JS所在模块的路径,然后再manifest文件加载这个引入JS的xml文件就行
odoo tree视图按钮加入confirm弹框_第3张图片

你可能感兴趣的:(odoo,javascript,python)