第七章 树形列表视图自定义按钮的实现

本文针对于13.0及之前版本中,不能在list视图中添加按钮的特性,需要自行实现的方法作出的总结.

定义按钮视图

首先,我们需要在树形列表视图的按钮的视图中添加我们自定义的按钮:

<templates>
    <t t-extend="ListView.buttons">
        <t t-jquery="div.o_list_buttons" t-operation="prepend">
            <button type="button" class="oe_tiv_multi_create btn btn-primary">批量分发</button>
        </t>
    </t>
</templates>

做好视图之后,我们将它添加到qweb声明中:

'qweb':[
    "static/src/xml/button.xml"
],

自定义按钮事件

我们既然添加按钮,那么自然也要实现按钮对应的方法, 这里按钮有两种调用方法, 一种是调用模型的后台方法, 另外一种是调用动作(action).

我们这里以调用动作为例:

var ListController = require("web.ListController");
var rpc = require("web.rpc");

ListController.include({
    renderButtons: function($node){
        this._super.apply(this, arguments);
        var self = this;
        if (this.$buttons){
            this.$buttons.find(".oe_tiv_multi_create").on("click",function(){
                self.do_action("juhui_account.action_juhui_tax_invoice_wizard");
            });
        }
    }
});

这里绑定了按钮的点击触发的方法, 调用一个后台定义好的动作, 弹出弹窗.

最后,我们将自定义的前端部件添加到到assets中:

<odoo>
    <data>
      <template id="assets_backend_assets" inherit_id="web.assets_backend" name="juhui_account">
        <xpath expr="script[last()]" position="after">
          <script type="text/javascript" src="/juhui_account/static/src/js/button.js"></script>
        </xpath>
      </template>
    </data>
</odoo>

实现效果

results matching ""

    No results matching ""