码迷,mamicode.com
首页 > 其他好文 > 详细

odoo14在列表视图里添加自定义按钮

时间:2021-03-16 13:30:43      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:bsp   btn   web   按钮   列表   ring   选中   ssi   form   

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

 

odoo14在列表视图里添加自定义按钮

标签:bsp   btn   web   按钮   列表   ring   选中   ssi   form   

原文地址:https://www.cnblogs.com/1314520xh/p/14533219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!