zoukankan      html  css  js  c++  java
  • odoo14在列表视图里添加自定义按钮

    static/js/xxxx.js   这里定义按钮

    odoo.define('add.tree.view.buttons', 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 qweb = core.qweb; var AddListViewController = ListController.extend({ buttons_template: 'AddsListView.buttons', /** * Extends the renderButtons function of ListView by adding an event listener * on the bill upload button. * * @override */ renderButtons: function () { this._super.apply(this, arguments); // Possibly sets this.$buttons if (this.$buttons) { var self = this; this.$buttons.on('click', '.o_button_add_tree_btn', function () { var actived_ids = []; var select_value = $('tbody .o_list_record_selector input'); var state = self.model.get(self.handle, {raw: true});
    //这里是获取列表中选中的record
    for (var i=0;i<select_value.length;i++){
    if (select_value[i].checked===true){

    actived_ids.push(state.res_ids[i]);

    }

    }
    self.do_action({ type: 'ir.actions.act_window', res_model: 'test.wizard',//向导模型 target: 'new', views: [[false, 'form']], context: {active_ids:actived_ids}, }); }); } } }); //注册你的插件 var AddsListView = ListView.extend({ config: _.extend({}, ListView.prototype.config, { Controller: AddListViewController, }), }); viewRegistry.add('add_buttons_tree', AddsListView); });

    这里添加按钮:static/xml/xxxx.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <templates>
        <t t-extend="ListView.buttons" t-name="AddsListView.buttons">
            <t t-jquery="button.o_button_import" t-operation="replace"></t><!--隐藏列表导入按钮-->
     <t t-jquery="button.o_list_button_add" t-operation="after"> <!--将新加按钮放置创建按钮后面--> <button type="button" class="btn btn-danger o_button_add_tree_btn" title="按钮1">按钮1</button> </t> </t> </templates>

    导入你的js

    <odoo>
        <data>
            <template id="assets_backend" name="add list buttons" inherit_id = "web.assets_backend">
                <xpath expr="." position="inside">
                    <script type="text/javascript" src="/mde_name/static/src/js/add_tree_view_button.js"></script>
                </xpath>
            </template>
        </data>
    </odoo>

    最后在列表视图中引用:js_class="AAAAAAAAA"

        <tree string="" js_class="add_buttons_tree" delete="0" >
    心有猛虎,细嗅蔷薇
  • 相关阅读:
    [翻译]使用设计模式简化.NET中菜单和Form元素之间的关系
    [AWDwR4]13章出错 protect_against_forgery
    使用存储过程(22)
    建立数据库连接(19)
    对数据库添加数据(21)
    ADO.NET常用对象(18)
    数据展现Repeater控件(25)
    content控件(24)
    对数据库增加数据(21)
    行为存储过程(23)
  • 原文地址:https://www.cnblogs.com/1314520xh/p/14533219.html
Copyright © 2011-2022 走看看