Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
15730 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

WebsiteLivechatWindowXXX.extend({ ==> WebsiteLivechatWindowXXX.include({
Awatar
Odrzuć
Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
1
kwi 21
4379
1
kwi 20
3031
0
mar 20
2204
1
lut 20
3909
1
sie 19
6444