From e6b4761bec890dcfda735f95640f57a25b65105c Mon Sep 17 00:00:00 2001 From: Zelong Lin Date: Tue, 30 Nov 2021 13:57:54 +0000 Subject: [PATCH] [FIX] discuss: clicking on attachment download closes current rtc call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using with 'download' attribute to download the attachment. Prevent calling .navigate() interrupting the current call. task-2692597 closes odoo/odoo#80903 X-original-commit: 97fa88c2e8407972c83c93d4d2198633a5560ecc Signed-off-by: Sébastien Theys (seb) --- .../src/components/attachment_viewer/attachment_viewer.js | 3 +-- addons/mail/static/src/models/attachment/attachment.js | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js index fa8088b3254..cd926048172 100644 --- a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js +++ b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js @@ -139,8 +139,7 @@ export class AttachmentViewer extends Component { * @private */ _download() { - const id = this.attachmentViewer.attachment.id; - this.env.services.navigate(`/web/content/ir.attachment/${id}/datas`, { download: true }); + this.attachmentViewer.attachment.download(); } /** diff --git a/addons/mail/static/src/models/attachment/attachment.js b/addons/mail/static/src/models/attachment/attachment.js index a02b9152bfb..abf4c1301ad 100644 --- a/addons/mail/static/src/models/attachment/attachment.js +++ b/addons/mail/static/src/models/attachment/attachment.js @@ -51,7 +51,12 @@ registerModel({ * Send the attachment for the browser to download. */ download() { - this.env.services.navigate(`/web/content/ir.attachment/${this.id}/datas`, { download: true }); + const downloadLink = document.createElement('a'); + downloadLink.setAttribute('href', `/web/content/ir.attachment/${this.id}/datas?download=true`); + // Adding 'download' attribute into a link prevents open a new tab or change the current location of the window. + // This avoids interrupting the activity in the page such as rtc call. + downloadLink.setAttribute('download', ''); + downloadLink.click(); }, /** * Handles click on download icon.