0012646: Display and print filed mails
authorMichael Spahn <m.spahn@metaways.de>
Mon, 10 Apr 2017 14:36:35 +0000 (16:36 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 11 Apr 2017 13:10:23 +0000 (15:10 +0200)
https://forge.tine20.org/view.php?id=12646

Change-Id: Iebd3671bb20ac7ae1f0f3281074dfb1a4dd0d696
Reviewed-on: http://gerrit.tine20.com/customers/4536
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/MailFiler/js/NodeEditDialog.js

index d58349c..0f0d08f 100644 (file)
@@ -52,11 +52,80 @@ Tine.MailFiler.NodeEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
             disabled: false,
             scope: this
         });
+        this.printAction = new Ext.Action({
+            requiredGrant: 'readGrant',
+            text: this.app.i18n._('Print Message'),
+            handler: this.onPrint.createDelegate(this, []),
+            disabled: false,
+            iconCls:'action_print',
+            scope:this
+        });
 
-        this.tbarItems = [this.downloadAction];
+        this.tbarItems = [this.downloadAction, this.printAction];
 
         Tine.MailFiler.NodeEditDialog.superclass.initComponent.call(this);
     },
+
+    /**
+     * Ripped of felamimail
+     *
+     * @param detailsPanel
+     */
+    onPrint: function() {
+        var id = Ext.id(),
+            doc = document,
+            frame = doc.createElement('iframe');
+
+        Ext.fly(frame).set({
+            id: id,
+            name: id,
+            style: {
+                position: 'absolute',
+                width: '210mm',
+                height: '297mm',
+                top: '-10000px',
+                left: '-10000px'
+            }
+        });
+
+        doc.body.appendChild(frame);
+
+        Ext.fly(frame).set({
+            src : Ext.SSL_SECURE_URL
+        });
+
+        var doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document,
+            content = this.getDetailsPanelContentForPrinting(this.mailDetailsPanel);
+
+        doc.open();
+        doc.write(content);
+        doc.close();
+
+        frame.contentWindow.focus();
+        frame.contentWindow.print();
+    },
+
+
+    /**
+     * get detail panel content
+     *
+     * @param {Tine.Felamimail.GridDetailsPanel} details panel
+     * @return {String}
+     */
+    getDetailsPanelContentForPrinting: function(detailsPanel) {
+        var detailsPanels = detailsPanel.getEl().query('.preview-panel-mail');
+
+        var detailsPanelContent = (detailsPanels.length > 1) ? detailsPanels[1].innerHTML : detailsPanels[0].innerHTML;
+
+        var buffer = '<html><head>';
+        buffer += '<title>' + this.app.i18n._('Print Preview') + '</title>';
+        buffer += '</head><body>';
+        buffer += detailsPanelContent;
+        buffer += '</body></html>';
+
+        return buffer;
+    },
+
     /**
      * folder or file?
      */