sim*_*awk 5 client webclient openerp web
我正在寻找一种方法来覆盖一些openerp web js核心功能,如"on_logout".
文档缺乏说明(正如你在我的帖子中看到的)和helloworld模块告诉你,你可以这样做
openerp.web_hello = function(openerp) {
openerp.web.SearchView = openerp.web.SearchView.extend({
init:function() {
this._super.apply(this,arguments);
this.on_search.add(function(){console.log('hello');});
}
});
// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them
openerp.web.Login = openerp.web.Login.extend({
start: function() {
console.log('Hello there');
this._super.apply(this,arguments);
}
});
};
Run Code Online (Sandbox Code Playgroud)
在我的模块中,我这样做:
openerp.mytest = function(openerp){
openerp.web.WebClient = openerp.web.WebClient.extend({
on_logout: function() {
alert('mine');
[...]
},
});
}
Run Code Online (Sandbox Code Playgroud)
我知道js已加载,因为在此定义之外放置警报是有效的.
这有什么不对?
这是一个有点特殊的问题,因为您想要更改已经实例化的对象的原型(类,如果您愿意的话)(WebClient 实例是系统的根,因此在您的代码编写时它可能已经存在)已加载,因此创建新的 WebClient“类”不会改变现有实例)。
在这种情况下,你不能用子类替换该类,你必须重新打开该类(以类似于 Ruby 的方式),因为include类对象上有一个方法,它应该可以工作:
openerp.mytest = function(openerp) {
openerp.web.WebClient.include({
on_logout: function() {
alert('mine');
this._super.apply(this, arguments);
}
});
}
Run Code Online (Sandbox Code Playgroud)
(如在 Ruby 中一样,this._super绑定到您要替换的方法(如果有的话)以进行就地类更改)
如果您检查 view_list_editable.js 实现文件,它会提供相关示例,因为它需要重新打开并更改列表视图的代码才能添加可编辑性。