From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../snailmail_notification_popover.js | 86 ++++++++++++++++++++++ .../snailmail_notification_popover.scss | 7 ++ .../snailmail_notification_popover.xml | 13 ++++ 3 files changed, 106 insertions(+) create mode 100644 addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js create mode 100644 addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.scss create mode 100644 addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.xml (limited to 'addons/snailmail/static/src/components/snailmail_notification_popover') diff --git a/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js new file mode 100644 index 00000000..0845ce07 --- /dev/null +++ b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js @@ -0,0 +1,86 @@ +odoo.define('snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js', function (require) { +'use strict'; + +const { Component } = owl; +const useStore = require('mail/static/src/component_hooks/use_store/use_store.js'); + +class SnailmailNotificationPopover extends Component { + + /** + * @override + */ + constructor(...args) { + super(...args); + useStore(props => { + const message = this.env.models['mail.message'].get(props.messageLocalId); + const notifications = message ? message.notifications : []; + return { + message: message ? message.__state : undefined, + notifications: notifications.map(notification => notification ? notification.__state : undefined), + }; + }, { + compareDepth: { + notifications: 1, + }, + }); + } + + /** + * @returns {string} + */ + get iconClass() { + switch (this.notification.notification_status) { + case 'sent': + return 'fa fa-check'; + case 'ready': + return 'fa fa-clock-o'; + case 'canceled': + return 'fa fa-trash-o'; + default: + return 'fa fa-exclamation text-danger'; + } + } + + /** + * @returns {string} + */ + get iconTitle() { + switch (this.notification.notification_status) { + case 'sent': + return this.env._t("Sent"); + case 'ready': + return this.env._t("Awaiting Dispatch"); + case 'canceled': + return this.env._t("Canceled"); + default: + return this.env._t("Error"); + } + } + + /** + * @returns {mail.message} + */ + get message() { + return this.env.models['mail.message'].get(this.props.messageLocalId); + } + + /** + * @returns {mail.notification} + */ + get notification() { + // Messages from snailmail are considered to have at most one notification. + return this.message.notifications[0]; + } + +} + +Object.assign(SnailmailNotificationPopover, { + props: { + messageLocalId: String, + }, + template: 'snailmail.SnailmailNotificationPopover', +}); + +return SnailmailNotificationPopover; + +}); diff --git a/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.scss b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.scss new file mode 100644 index 00000000..970bc79d --- /dev/null +++ b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.scss @@ -0,0 +1,7 @@ +// ----------------------------------------------------------------------------- +// Layout +// ----------------------------------------------------------------------------- + +.o_SnailmailNotificationPopover_icon { + margin-inline-end: map-get($spacers, 2); +} diff --git a/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.xml b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.xml new file mode 100644 index 00000000..873b08f4 --- /dev/null +++ b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.xml @@ -0,0 +1,13 @@ + + + + +
+ + + + +
+
+ +
-- cgit v1.2.3