diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json index 8989d34a33..8a6158ab92 100644 --- a/application/Espo/Resources/i18n/en_US/Global.json +++ b/application/Espo/Resources/i18n/en_US/Global.json @@ -247,6 +247,7 @@ "Tree View": "Tree View", "Unlink All": "Unlink All", "Total": "Total", + "Print": "Print", "Print to PDF": "Print to PDF", "Default": "Default", "Number": "Number", diff --git a/client/src/views/email/record/detail.js b/client/src/views/email/record/detail.js index 44b35f83d9..14753921ad 100644 --- a/client/src/views/email/record/detail.js +++ b/client/src/views/email/record/detail.js @@ -164,6 +164,11 @@ define('views/email/record/detail', ['views/record/detail'], function (Dep) { hidden: !(this.model.get('isHtml') && this.model.get('bodyPlain')) }); + this.addDropdownItem({ + label: 'Print', + name: 'print', + }); + this.listenTo(this.model, 'change:isImportant', () => { if (this.model.get('isImportant')) { this.hideActionItem('markAsImportant'); @@ -481,6 +486,43 @@ define('views/email/record/detail', ['views/record/detail'], function (Dep) { }); }, + actionPrint: function () { + /** @type {module:views/fields/wysiwyg.Class} */ + let bodyView = this.getFieldView('body'); + + if (!bodyView) { + return; + } + + let iframe = bodyView.$el.find('iframe').get(0); + + if (iframe) { + iframe.contentWindow.print(); + + return; + } + + let el = bodyView.$el.get(0); + /** @type {Element} */ + let recordElement = this.$el.get(0); + + iframe = document.createElement('iframe'); + iframe.style.display = 'none'; + + recordElement.append(iframe); + + let contentWindow = iframe.contentWindow; + + contentWindow.document.open(); + contentWindow.document.write(el.innerHTML); + contentWindow.document.close(); + contentWindow.focus(); + contentWindow.print(); + contentWindow.onafterprint = () => { + recordElement.removeChild(iframe); + } + }, + errorHandlerSendingFail: function (data) { if (!this.model.id) { this.model.id = data.id;