Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
15701 มุมมอง

Can anyone give me minimal code so that any method I can override for JS method, I tried this code but it doesn't work for me?

I want to override the method for this line https://github.com/odoo/odoo/blob/12.0/addons/im_livechat/static/src/js/website_livechat_window.js#L65

Here is my code file

odoo.define('poc.test', function(require){

"use strict";
console.log('111XXX');
var WebsiteLivechatWindowXXX = require('im_livechat.WebsiteLivechatWindow');
var LivechatWindowTest = WebsiteLivechatWindowXXX.extend({
events: _.extend(WebsiteLivechatWindowXXX.prototype.events, {
'input .o_composer_text_field': '_onInputX',
}),
/**
* @override
* @param {im_livechat.im_livechat.LivechatButton} parent
* @param {im_livechat.model.WebsiteLivechat} thread
*/
init: function (parent, thread) {
this._super.apply(this, arguments);
this._thread = thread;
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
* @private
* @param {Object} messageData
*/
_postMessage: function (messageData) {
console.log('222XXX');
this._super.apply(this, arguments);
},
_onInputX: function () {
console.log('this.$input.val().length');
console.log(this.$input.val().length);
console.log(this.hasThread());
console.log(this._thread);
console.log(this._thread.hasTypingNotification());
},
});
return LivechatWindowTest;
});


In the console, I can see the log '111XXX' which confirm the JS custom code is loaded but when I tried to send message It doesn't print '222XXX' in the console. Also, If I type anything I got an error message in the console which say 'Error: Couldn't find method '_onInputX' in widget'.
I have included in JS file by creating template view and the template inherit 'inherit_id="website.assets_frontend"' and also I have added depends 'im_livechat' in __manifest__.py file.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

this widget should be overridde with `include` rather than `extend` because you are not creating any instant of extended widget

WebsiteLivechatWindowXXX.extend({ ==> WebsiteLivechatWindowXXX.include({
อวตาร
ละทิ้ง
ผู้เขียน

Thanks, it works.

Do you know any tutorial/Book other than Odoo docs where I can learn JS framework used in Odoo? I am struggling to understand JS.

Please @ sah Vinay, have you gotten any resource in regards to this?

i am also struggling to understand odoo javascript framework...plz any tutorial/book

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
เม.ย. 21
4338
1
เม.ย. 20
2984
0
มี.ค. 20
2177
Creation of DOM from XML แก้ไขแล้ว
1
ก.พ. 20
3872
1
ส.ค. 19
6400