修改start:Odoo中var EditMenuDialog的函数

时间:2017-07-02 09:38:57

标签: javascript odoo-10 odoo-website

我需要修改odoo website.contentMenu.js 文件的EditMenuDialog var的start函数中的值。修改需要在我的自定义模块js文件中完成。

https://github.com/odoo/odoo/blob/10.0/addons/website/static/src/js/website.contentMenu.js#L210

此处maxLevels的值为2:

start: function () {
    var r = this._super.apply(this, arguments);
    this.$('.oe_menu_editor').nestedSortable({
        listType: 'ul',
        handle: 'div',
        items: 'li',
        maxLevels: 2,
        toleranceElement: '> div',
        forcePlaceholderSize: true,
        opacity: 0.6,
        placeholder: 'oe_menu_placeholder',
        tolerance: 'pointer',
        attribute: 'data-menu-id',
        expression: '()(.+)', // nestedSortable takes the second match of an expression (*sigh*)
    });
    return r;
},

对于我的模块,我需要将maxLevels更改为3.我尝试在自定义文件中重写变量,但它不起作用。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

我找到了在自定义模块中继承和修改odoo js函数的解决方案。以下是代码:

odoo.define('your_module_name.js_name', function (require) {
'use strict';

// assign the variable EditMenuDialog of website module's contentModule
// js in a variable
var EditMenuDialog = require('website.contentMenu').EditMenuDialog;

// for modifying use the .include function
EditMenuDialog.include({
    start: function () {
        this.$('.oe_menu_editor').nestedSortable({
            listType: 'ul',
            handle: 'div',
            items: 'li',
            maxLevels: 3, // changed maxLevels from 2 to 3
            toleranceElement: '> div',
            forcePlaceholderSize: true,
            opacity: 0.6,
            placeholder: 'oe_menu_placeholder',
            tolerance: 'pointer',
            attribute: 'data-menu-id',
            expression: '()(.+)'
        });
    }
});
});