Odoo js error on function change, property 'include' is undefined

I changed the js function of this site. The code looks like this:

odoo.define('website_custom_menu.menu_custom', function (require) {
    'use strict';
    require('website.contentMenu');
    var EditMenuDialog = require('website.contentMenu').EditMenuDialog;
    EditMenuDialog.include({
        start: function () {
            this._super();
            var r = this._super.apply(this, arguments);
            this.$('.oe_menu_editor').nestedSortable({
                listType: 'ul',
                handle: 'div',
                items: 'li',
                maxLevels: 4,
                toleranceElement: '> div',
                forcePlaceholderSize: true,
                opacity: 0.6,
                placeholder: 'oe_menu_placeholder',
                tolerance: 'pointer',
                attribute: 'data-menu-id',
                expression: '()(.+)'
            });
            return r;
        }
    });
});

      

This changes the website menu editor. Where it can be edited to add four levels of submenus. But this misleads the Congloe.

When loaded, it says "Failed Module". And after some debugging on the console, I encountered the following error:

TypeError: Cannot read property 'include' of undefined
    at website.assets_editor.js:191
    at process_job (web.assets_common.js:2994)
    at Object.process_jobs (web.assets_common.js:3000)
    at $.when.then.job.rejected (web.assets_common.js:2995)
    at web.assets_common.js:547
    at fire (web.assets_common.js:541)
    at Object.add as done
    at Array. (web.assets_common.js:547)
    at Function.each (web.assets_common.js:370)
    at Object. (web.assets_common.js:547)

      

How do I fix this and what does it mean? I have seen other modules and they did it the same way.

TBN: The module has the website module as a dependency and the js file is added to the assets.

+3


source to share


3 answers


EditMenuDialog is undefined because /website/static/src/js/website.contentMenu.js which defines website.contentMenu only returns TopBar

return {
    'TopBar': TopBarContent,
};

      



You can add EditMenuDialog to it:

return {
    'TopBar': TopBarContent,
    'EditMenuDialog': EditMenuDialog,
};

      

+2


source


your code has an error, make this call:

var EditMenuDialog = require('website.contentMenu').EditMenuDialog;

      

the following module manager in odoo, require will give an instance, then you can continue / include try:

var EditMenuDialog = require('website.contentMenu.EditMenuDialog');

      



If EditMenuDialog is a module.

You can check our example here

Also on odoo source code you can check several examples with the same hacks

examples

0


source


You have to use extension instead of include for EditMenuDialog.

Hint:

odoo.define('website_custom_menu.menu_custom', function (require) {
'use strict';
    var widget = require('web_editor.widget');
    var MyMenuDialog = require('website.contentMenu');
    MyMenuDialog.EditMenuDialog.extend({
        start: function () {
            this._super();
            var r = this._super.apply(this, arguments);
            this.$('.oe_menu_editor').nestedSortable({
                listType: 'ul',
                handle: 'div',
                items: 'li',
                maxLevels: 4,
                toleranceElement: '> div',
                forcePlaceholderSize: true,
                opacity: 0.6,
                placeholder: 'oe_menu_placeholder',
                tolerance: 'pointer',
                attribute: 'data-menu-id',
                expression: '()(.+)'
            });
            return r;
        }
    });
    return MyMenuDialog;
});

      

0


source







All Articles