diff options
| author | xO-Tx <mou@odoo.com> | 2020-11-17 14:18:47 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2020-12-28 14:29:15 +0000 |
| commit | 3da25b8a3b97d01025ace11db449ca4768cdfa25 (patch) | |
| tree | 983cc5b65e6c164dd812b6d1f97d7cd5abc0774a /addons/website_mail_channel/static | |
| parent | 38c5bd45c450bf04e7cc0a53d2051522332e97ed (diff) | |
[FIX] website_mail_channel: fix discussion group snippet without group
Prevent crash while trying to subscribe to a non existing channel from
a misconfigured snippet.
Also now let the user create the channel linked to the discussion group
directly on snippet drop if no channel is available to select
automatically.
task-2356955
closes odoo/odoo#60608
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/website_mail_channel/static')
| -rw-r--r-- | addons/website_mail_channel/static/src/snippets/s_channel/options.js | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/addons/website_mail_channel/static/src/snippets/s_channel/options.js b/addons/website_mail_channel/static/src/snippets/s_channel/options.js index b6d89d8928f..5b51bb6afc2 100644 --- a/addons/website_mail_channel/static/src/snippets/s_channel/options.js +++ b/addons/website_mail_channel/static/src/snippets/s_channel/options.js @@ -11,9 +11,30 @@ options.registry.Channel = options.Class.extend({ /** * @override */ + async start() { + await this._super(...arguments); + this.publicChannels = await this._getPublicChannels(); + }, + /** + * @override + */ cleanForSave: function () { this.$target.addClass('d-none'); }, + /** + * If we have already created channels => select the first one + * else => modal prompt (create a new channel) + * + * @override + */ + onBuilt() { + if (this.publicChannels.length) { + this.$target[0].dataset.id = this.publicChannels[0][0]; + } else { + const widget = this._requestUserValueWidgets('create_mail_channel_opt')[0]; + widget.$el.click(); + } + }, //-------------------------------------------------------------------------- // Options @@ -56,12 +77,12 @@ options.registry.Channel = options.Class.extend({ /** * @override */ - _renderCustomXML: function (uiFragment) { - return this._rpc({ - model: 'mail.channel', - method: 'name_search', - args: ['', [['public', '=', 'public']]], - }).then(channels => { + _renderCustomXML(uiFragment) { + // TODO remove this part in master + const createChannelEl = uiFragment.querySelector('we-button[data-create-channel]'); + createChannelEl.dataset.name = 'create_mail_channel_opt'; + + return this._getPublicChannels().then(channels => { const menuEl = uiFragment.querySelector('.select_discussion_list'); for (const channel of channels) { const el = document.createElement('we-button'); @@ -71,5 +92,16 @@ options.registry.Channel = options.Class.extend({ } }); }, + /** + * @private + * @return {Promise} + */ + _getPublicChannels() { + return this._rpc({ + model: 'mail.channel', + method: 'name_search', + args: ['', [['public', '=', 'public']]], + }); + }, }); }); |
