【问题标题】:How to run javascript only after the view has loaded in Odoo 10如何仅在 Odoo 10 中加载视图后运行 javascript
【发布时间】:2018-02-06 17:21:57
【问题描述】:

我在https://www.odoo.com/apps/modules/8.0/web_menu_hide_8.0/上安装了网络隐藏菜单

我修改为在 Odoo 10 上使用它,但是如果我们按下隐藏按钮,表单将被调整为全宽,如果我们在按下隐藏按钮后更改为另一个视图,表单页面将保持原样(不是全宽)。

所以我需要在页面呈现后在表单视图上调整类“o_form_sheet”。我可以知道如何使用 javascript 做到这一点吗?我需要扩展哪个类和方法?

【问题讨论】:

    标签: odoo-10 webpage-rendering javascript-inheritance


    【解决方案1】:

    我将回答我自己的问题。 经过一番研究,我发现最好的选择是使用 load_views 函数继承 ViewManager 小部件。

    var ViewManager = require('web.ViewManager');
    
    ViewManager.include({
        load_views: function (load_fields) {
            var self = this;
    
            // Check if left menu visible
            var root=self.$el.parents();
            var visible=(root.find('.o_sub_menu').css('display') != 'none')
            if (visible) {
                // Show menu and resize form components to original values
                root.find('.o_form_sheet_bg').css('padding', self.sheetbg_padding);
                root.find('.o_form_sheet').css('max-width', self.sheetbg_maxwidth);
                root.find('.o_form_view div.oe_chatter').css('max-width', self.chatter_maxwidth);
            } else {
                // Hide menu and save original values
                self.sheetbg_padding=root.find('.o_form_sheet_bg').css('padding');
                root.find('.o_form_sheet_bg').css('padding', '16px');
                self.sheetbg_maxwidth=root.find('.o_form_sheet').css('max-width');
                root.find('.o_form_sheet').css('max-width', '100%');
                self.chatter_maxwidth=root.find('.o_form_view div.oe_chatter').css('max-width');
                root.find('.o_form_view div.oe_chatter').css('max-width','100%');
            }
    
            return this._super.apply(this, arguments, load_fields);
        },
    });
    

    【讨论】:

    • 我正在寻找同样的东西。您在哪里添加此代码以使其在您的自定义模块中工作??
    • 我在我的自定义模块上添加了,只需创建新的 js 将其放在您的静态文件夹中,然后不要忘记将其包含在 web.assets_backend 中,仅此而已。
    猜你喜欢
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    相关资源
    最近更新 更多