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_error_dialog.js | 113 +++++++++++++++++++++ .../snailmail_error_dialog.xml | 61 +++++++++++ 2 files changed, 174 insertions(+) create mode 100644 addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js create mode 100644 addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.xml (limited to 'addons/snailmail/static/src/components/snailmail_error_dialog') diff --git a/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js b/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js new file mode 100644 index 00000000..a7daf7c1 --- /dev/null +++ b/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js @@ -0,0 +1,113 @@ +odoo.define('snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js', function (require) { +'use strict'; + +const useStore = require('mail/static/src/component_hooks/use_store/use_store.js'); + +const Dialog = require('web.OwlDialog'); + +const { Component } = owl; +const { useRef } = owl.hooks; + +class SnailmailErrorDialog 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 + ), + snailmail_credits_url: this.env.messaging.snailmail_credits_url, + snailmail_credits_url_trial: this.env.messaging.snailmail_credits_url_trial, + }; + }, { + compareDepth: { + notifications: 1, + }, + }); + // to manually trigger the dialog close event + this._dialogRef = useRef('dialog'); + } + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * @returns {boolean} + */ + get hasCreditsError() { + return ( + this.notification.failure_type === 'sn_credit' || + this.notification.failure_type === 'sn_trial' + ); + } + + /** + * @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]; + } + + /** + * @returns {string} + */ + get title() { + return this.env._t("Failed letter"); + } + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + _onClickCancelLetter() { + this._dialogRef.comp._close(); + this.message.cancelLetter(); + } + + /** + * @private + */ + _onClickClose() { + this._dialogRef.comp._close(); + } + + /** + * @private + */ + _onClickResendLetter() { + this._dialogRef.comp._close(); + this.message.resendLetter(); + } + +} + +Object.assign(SnailmailErrorDialog, { + components: { Dialog }, + props: { + messageLocalId: String, + }, + template: 'snailmail.SnailmailErrorDialog', +}); + +return SnailmailErrorDialog; + +}); diff --git a/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.xml b/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.xml new file mode 100644 index 00000000..bf4f026e --- /dev/null +++ b/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.xml @@ -0,0 +1,61 @@ + + + + + + + +

+ The letter could not be sent due to insufficient credits on your IAP account. +

+ + + +
+ +

+ You need credits on your IAP account to send a letter. +

+ + + +
+ +

+ The country to which you want to send the letter is not supported by our service. +

+
+ +

+ An unknown error occurred. Please contact our support for further assistance. +

+
+ + + + + + + + +
+
+
+ +
-- cgit v1.2.3