summaryrefslogtreecommitdiff
path: root/addons/snailmail/static/src/components/message/message.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/snailmail/static/src/components/message/message.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/snailmail/static/src/components/message/message.js')
-rw-r--r--addons/snailmail/static/src/components/message/message.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/addons/snailmail/static/src/components/message/message.js b/addons/snailmail/static/src/components/message/message.js
new file mode 100644
index 00000000..1033c901
--- /dev/null
+++ b/addons/snailmail/static/src/components/message/message.js
@@ -0,0 +1,87 @@
+odoo.define('snailmail/static/src/components/message/message.js', function (require) {
+'use strict';
+
+const components = {
+ Message: require('mail/static/src/components/message/message.js'),
+ SnailmailErrorDialog: require('snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js'),
+ SnailmailNotificationPopover: require('snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js'),
+};
+
+const { patch } = require('web.utils');
+
+const { useState } = owl;
+
+Object.assign(components.Message.components, {
+ SnailmailErrorDialog: components.SnailmailErrorDialog,
+ SnailmailNotificationPopover: components.SnailmailNotificationPopover,
+});
+
+patch(components.Message, 'snailmail/static/src/components/message/message.js', {
+ /**
+ * @override
+ */
+ _constructor() {
+ this._super(...arguments);
+ this.snailmailState = useState({
+ // Determine if the error dialog is displayed.
+ hasDialog: false,
+ });
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ _onClickFailure() {
+ if (this.message.message_type === 'snailmail') {
+ /**
+ * Messages from snailmail are considered to have at most one
+ * notification. The failure type of the whole message is considered
+ * to be the same as the one from that first notification, and the
+ * click action will depend on it.
+ */
+ switch (this.message.notifications[0].failure_type) {
+ case 'sn_credit':
+ // URL only used in this component, not received at init
+ this.env.messaging.fetchSnailmailCreditsUrl();
+ this.snailmailState.hasDialog = true;
+ break;
+ case 'sn_error':
+ this.snailmailState.hasDialog = true;
+ break;
+ case 'sn_fields':
+ this.message.openMissingFieldsLetterAction();
+ break;
+ case 'sn_format':
+ this.message.openFormatLetterAction();
+ break;
+ case 'sn_price':
+ this.snailmailState.hasDialog = true;
+ break;
+ case 'sn_trial':
+ // URL only used in this component, not received at init
+ this.env.messaging.fetchSnailmailCreditsUrlTrial();
+ this.snailmailState.hasDialog = true;
+ break;
+ }
+ } else {
+ this._super(...arguments);
+ }
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _onDialogClosedSnailmailError() {
+ this.snailmailState.hasDialog = false;
+ },
+});
+
+});