From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../attachment_delete_confirm_dialog.js | 92 ++++++++++++++++++++++ .../attachment_delete_confirm_dialog.xml | 12 +++ 2 files changed, 104 insertions(+) create mode 100644 addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js create mode 100644 addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.xml (limited to 'addons/mail/static/src/components/attachment_delete_confirm_dialog') diff --git a/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js b/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js new file mode 100644 index 00000000..ab7e155a --- /dev/null +++ b/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js @@ -0,0 +1,92 @@ +odoo.define('mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js', function (require) { +'use strict'; + +const useShouldUpdateBasedOnProps = require('mail/static/src/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props.js'); +const useStore = require('mail/static/src/component_hooks/use_store/use_store.js'); + +const components = { + Dialog: require('web.OwlDialog'), +}; + +const { Component } = owl; +const { useRef } = owl.hooks; + +class AttachmentDeleteConfirmDialog extends Component { + + /** + * @override + */ + constructor(...args) { + super(...args); + useShouldUpdateBasedOnProps(); + useStore(props => { + const attachment = this.env.models['mail.attachment'].get(props.attachmentLocalId); + return { + attachment: attachment ? attachment.__state : undefined, + }; + }); + // to manually trigger the dialog close event + this._dialogRef = useRef('dialog'); + } + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * @returns {mail.attachment} + */ + get attachment() { + return this.env.models['mail.attachment'].get(this.props.attachmentLocalId); + } + + /** + * @returns {string} + */ + getBody() { + return _.str.sprintf( + this.env._t(`Do you really want to delete "%s"?`), + owl.utils.escape(this.attachment.displayName) + ); + } + + /** + * @returns {string} + */ + getTitle() { + return this.env._t("Confirmation"); + } + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + _onClickCancel() { + this._dialogRef.comp._close(); + } + + /** + * @private + */ + _onClickOk() { + this._dialogRef.comp._close(); + this.attachment.remove(); + this.trigger('o-attachment-removed', { attachmentLocalId: this.props.attachmentLocalId }); + } + +} + +Object.assign(AttachmentDeleteConfirmDialog, { + components, + props: { + attachmentLocalId: String, + }, + template: 'mail.AttachmentDeleteConfirmDialog', +}); + +return AttachmentDeleteConfirmDialog; + +}); diff --git a/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.xml b/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.xml new file mode 100644 index 00000000..6b466a9b --- /dev/null +++ b/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.xml @@ -0,0 +1,12 @@ + + + + +

+ + + + +

+
+
-- cgit v1.2.3