diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/snailmail/static/src/components/snailmail_notification_popover | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/snailmail/static/src/components/snailmail_notification_popover')
3 files changed, 106 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates xml:space="preserve"> + + <t t-name="snailmail.SnailmailNotificationPopover" owl="1"> + <div class="o_SnailmailNotificationPopover"> + <t t-if="message and notification"> + <i class="o_SnailmailNotificationPopover_icon" t-att-class="iconClass" role="img"/> + <span t-esc="iconTitle"/> + </t> + </div> + </t> + +</templates> |
