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_error_dialog | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/snailmail/static/src/components/snailmail_error_dialog')
2 files changed, 174 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates xml:space="preserve"> + + <t t-name="snailmail.SnailmailErrorDialog" owl="1"> + <Dialog contentClass="'o_SnailmailErrorDialog'" title="title" size="'medium'" t-ref="dialog"> + <t t-if="message and notification"> + <t t-if="notification.failure_type === 'sn_credit'"> + <p class="o_SnailmailErrorDialog_contentCredit"> + The letter could not be sent due to insufficient credits on your IAP account. + </p> + <t t-if="env.messaging.snailmail_credits_url"> + <div class="text-right"> + <a class="btn btn-link" t-att-href="env.messaging.snailmail_credits_url" target="_blank"> + <i class="fa fa-arrow-right"/> Buy credits + </a> + </div> + </t> + </t> + <t t-elif="notification.failure_type === 'sn_trial'"> + <p class="o_SnailmailErrorDialog_contentTrial"> + You need credits on your IAP account to send a letter. + </p> + <t t-if="env.messaging.snailmail_credits_url_trial"> + <div class="text-right"> + <a class="btn btn-link" t-att-href="env.messaging.snailmail_credits_url_trial"> + <i class="fa fa-arrow-right"/> Buy credits + </a> + </div> + </t> + </t> + <t t-elif="notification.failure_type === 'sn_price'"> + <p class="o_SnailmailErrorDialog_contentPrice"> + The country to which you want to send the letter is not supported by our service. + </p> + </t> + <t t-elif="notification.failure_type === 'sn_error'"> + <p class="o_SnailmailErrorDialog_contentError"> + An unknown error occurred. Please contact our <a href="https://www.odoo.com/help" target="new">support</a> for further assistance. + </p> + </t> + + <t t-set-slot="buttons"> + <t t-if="hasCreditsError"> + <button class="o_SnailmailErrorDialog_resendLetterButton btn btn-primary" t-on-click="_onClickResendLetter">Re-send letter</button> + </t> + <button class="o_SnailmailErrorDialog_cancelLetterButton btn" + t-att-class="{ + 'btn-primary': !hasCreditsError, + 'btn-secondary': hasCreditsError, + }" + t-on-click="_onClickCancelLetter" + > + Cancel letter + </button> + <button class="o_SnailmailErrorDialog_closeButton btn btn-secondary" t-on-click="_onClickClose">Close</button> + </t> + </t> + </Dialog> + </t> + +</templates> |
