简体   繁体   中英

How To Extend mail.Chatter Widget in Javascript Odoo 10

I want to add a new event to "mail.Chatter" widget(mail/static/src/js/chatter.js) in Odoo 10.so I want to extend the "mail.Chatter" widget.

odoo.define('override_chatter.override_chatter', function (require) {
"use strict";

var Chatter = require('mail.Chatter');

console.log('Chatter', Chatter)



});

But from the console, I got some error. Please check below.

Chatter function Class(){if(this.constructor!==OdooClass){throw new Error("You can only instanciate objects with the 'new' operator");}

Please correct me if am wrong.Is there any other method to extend this "mail.Chatter" widget?

This works for me

odoo.define('override_chatter.override_chatter', function (require) {
"use strict";

var core = require('web.core');
var Chatter = require('mail.Chatter');
var MailThread = core.form_widget_registry.get('mail_thread');

var MailThreadOverride = MailThread.include({

    init: function () {
    this._super.apply(this, arguments);

    },

});

In the file JS chatter.js you have 2 init function.

For ChatterComposer

init: function (parent, dataset, options) {
    this._super(parent, options);
    this.thread_dataset = dataset;
    this.suggested_partners = [];
    this.options = _.defaults(this.options, {
        display_mode: 'textarea',
        record_name: false,
        is_log: false,
    });
    if (this.options.is_log) {
        this.options.send_text = _t('Log');
    }
    this.events = _.extend(this.events, {
        'click .o_composer_button_full_composer': 'on_open_full_composer',
    });
},

And for Chatter

init: function () {
    this._super.apply(this, arguments);
    this.model = this.view.dataset.model;
    this.res_id = undefined;
    this.context = this.options.context || {};
    this.dp = new web_utils.DropPrevious();
},

And if I seeing your code. You try to overwrite the init of Chatter whit the init params of ChatterComposer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM