openerp web client 6.1: how to override base javascript functions

后端 未结 1 1248
眼角桃花
眼角桃花 2020-12-20 23:09

I\'m looking for a way to override some openerp web js core functions such as \"on_logout\".

The docs lack of instructions (as you can see in my post) and the hellow

相关标签:
1条回答
  • 2020-12-20 23:35

    That's a bit of a special issue since you want to alter the prototype (the class, if you will) of an object which is already instantiated (a WebClient instance is the root of the system, so it's probably already there by the time your code is loaded, therefore creating a new WebClient "class" won't alter the existing instance).

    In that case, you can't replace the class with a subclass, you have to re-open the class (in a manner similar to Ruby), for that there is an include method on class objects, which should work:

    openerp.mytest = function(openerp) {
        openerp.web.WebClient.include({
            on_logout: function() {
                alert('mine');
                this._super.apply(this, arguments);
            }
        });
    }
    

    (as in Ruby, this._super is bound to the method you're replacing, if any, for in-place class alterations)

    If you check the view_list_editable.js implementation file, it provides examples of that since it needs to reopen and alter the listview's code in order to add editability.

    0 讨论(0)
提交回复
热议问题