From 423cf93eb32df363c16ccabab2fddaea384ceac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 20 Jun 2019 09:55:30 +0000 Subject: [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 Co-Authored-By: Pierre Rousseau --- addons/sms/static/src/js/thread_widget.js | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 addons/sms/static/src/js/thread_widget.js (limited to 'addons/sms/static/src/js/thread_widget.js') 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 + } + }); + }, +}); +}); -- cgit v1.2.3