diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-06-20 09:55:30 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-07-12 14:54:11 +0000 |
| commit | 423cf93eb32df363c16ccabab2fddaea384ceac7 (patch) | |
| tree | a1920e9d1dae14b7661cf59c75fe04cf46b683d6 /addons/sms/static/src/js/thread_widget.js | |
| parent | 45555bdd1fddb988bfa54ff54f1bc1887d0dc1df (diff) | |
[IMP] sms: add UX elements to use SMS notifications
Purpose of this commit is to allow users to have a feedback on SMS
notifications status in chatter. This commit contains notably
* an update of systray widget that now handles SMS failures. Those are
displayed in another item of the systray and redirect to documents having
an SMS failure;
* an update of chatter widgets to support SMS notifications in messages.
Failed notifications appear in red and allow to use the SMS resend
wizard;
Mail message model gains a new has_sms_error computed and searchable field
allowing to filter on messages having failed SMS notifications. Mail thread
model gains a new message_has_sms_error computed and searchable field, based
on the one on mail.message. It allows to filter on records with failed SMS
messages directly from the systray. That way clicking on the systray entry
redirects to the right records.
Related to task 1922163
Linked to PR #33510
Co-Authored-By: Thibault Delavallee <tde@odoo.com>
Co-Authored-By: Pierre Rousseau <pro@odoo.com>
Diffstat (limited to 'addons/sms/static/src/js/thread_widget.js')
| -rw-r--r-- | addons/sms/static/src/js/thread_widget.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/addons/sms/static/src/js/thread_widget.js b/addons/sms/static/src/js/thread_widget.js new file mode 100644 index 00000000000..4655732b34d --- /dev/null +++ b/addons/sms/static/src/js/thread_widget.js @@ -0,0 +1,89 @@ +odoo.define('sms.widget.Thread', function (require) { +"use strict"; + +var ThreadWidget = require('mail.widget.Thread'); +var core = require('web.core'); + +var QWeb = core.qweb; + +ThreadWidget.include({ + events: _.extend({}, ThreadWidget.prototype.events, { + 'click .o_thread_message_sms_error': '_onClickSMSError' + }), + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + this._enabledOptions = _.defaults(this._enabledOptions, { + displaySmsIcons: true, + }); + this._disabledOptions = _.defaults(this._disabledOptions, { + displaySmsIcons: false, + }); + }, + /** + * @override + */ + render: function (thread, options) { + this._super.apply(this, arguments); + var messages = _.clone(thread.getMessages({domain: options.domain || []})); + this._renderMessageSmsPopover(messages); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Render the popover when mouse-hovering on the mail icon of a message + * in the thread. There is at most one such popover at any given time. + * + * @private + * @param {mail.model.AbstractMessage[]} messages list of messages in the + * rendered thread, for which popover on mouseover interaction is + * permitted. + */ + _renderMessageSmsPopover: function (messages) { + if (this._messageSmsPopover) { + this._messageSmsPopover.popover('hide'); + } + if (!this.$('.o_thread_sms_tooltip').length) { + return; + } + this._messageSmsPopover = this.$('.o_thread_sms_tooltip').popover({ + html: true, + boundary: 'viewport', + placement: 'auto', + trigger: 'hover', + offset: '0, 1', + content: function () { + var messageID = $(this).data('message-id'); + var message = _.find(messages, function (message) { + return message.getID() === messageID; + }); + return QWeb.render('sms.widget.Thread.Message.SmsTooltip', { + data: message.getSmsIds() + }); + }, + }); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @param {MouseEvent} ev + */ + _onClickSMSError: function (ev) { + var messageID = $(ev.currentTarget).data('message-id'); + this.do_action('sms.sms_resend_action', { + additional_context: { + default_mail_message_id: messageID + } + }); + }, +}); +}); |
