printer renderer for edit dialogs
authorMichael Spahn <m.spahn@metaways.de>
Wed, 5 Jul 2017 11:54:46 +0000 (13:54 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Wed, 5 Jul 2017 16:26:37 +0000 (18:26 +0200)
Change-Id: I3bb9e9ee0e51bee75e3b70e8e9db2ca651f2767f
Reviewed-on: http://gerrit.tine20.com/customers/5020
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Tested-by: Michael Spahn <m.spahn@metaways.de>
tine20/Addressbook/js/AddressRenderer.js
tine20/Addressbook/js/ContactEditDialog.js
tine20/Addressbook/js/Printer/ContactRecord.js
tine20/Addressbook/js/Printer/ListRecord.js
tine20/Calendar/js/EventEditDialog.js
tine20/Calendar/js/Printer/EventRecord.js
tine20/Tinebase/Tinebase.jsb2
tine20/Tinebase/js/ux/Printer/renderers/Base.js
tine20/Tinebase/js/ux/Printer/renderers/EditDialogRenderer.js [new file with mode: 0644]

index 24a4a04..f9422f2 100644 (file)
@@ -34,7 +34,15 @@ Tine.Addressbook.addressRenderer = function (v, metadata, record, store, a, b, c
 
     // According to config, resolve the given fields from record
     keys.forEach(function (key) {
-        local[key] = Tine.Tinebase.EncodingHelper.encode(record.get(local[key]));
+        var value = null;
+
+        if (!record.data) {
+            value = window.lodash.get(record, local[key]);
+        } else {
+            value = window.lodash.get(record.data, local[key]);
+        }
+
+        local[key] = Tine.Tinebase.EncodingHelper.encode(value);
 
         // Country code to country name
         // @todo: Wouldn't it be cool, if this could be managed by the modelconfig as well?
index 9f0d199..761a4be 100644 (file)
@@ -485,7 +485,7 @@ Tine.Addressbook.ContactEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog,
     onPrint: function(printMode) {
         this.onRecordUpdate();
         var renderer = new Tine.Addressbook.Printer.ContactRenderer();
-        renderer.print(this.record);
+        renderer.print(this);
     },
 
     /**
index 11fec8e..9bbdf83 100644 (file)
@@ -1,9 +1,9 @@
 Ext.ns('Tine.Addressbook.Printer');
 
-Tine.Addressbook.Printer.ContactRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer, {
+Tine.Addressbook.Printer.ContactRenderer = Ext.extend(Ext.ux.Printer.EditDialogRenderer, {
     stylesheetPath: 'Tinebase/css/widgets/RecordPrinter.css',
 
-    generateBody: function(contact) {
+    generateBody: function(component, data) {
         var i18n = Tine.Tinebase.appMgr.get('Addressbook').i18n;
 
         return new Promise(function (fulfill, reject) {
@@ -91,7 +91,7 @@ Tine.Addressbook.Printer.ContactRenderer = Ext.extend(Ext.ux.Printer.BaseRendere
                     },
                     addressRenderer: function (config) {
                         var renderer = Tine.widgets.grid.RendererManager.get('Addressbook', 'Addressbook_Model_Contact', 'addressblock', 'displayPanel');
-                        return renderer(null, null, contact, null, null, null, config);
+                        return renderer(null, null, data, null, null, null, config);
                     },
                     relationRenderer: function (values) {
                         return Tine.widgets.relation.Renderer.renderAll(values);
@@ -99,7 +99,7 @@ Tine.Addressbook.Printer.ContactRenderer = Ext.extend(Ext.ux.Printer.BaseRendere
                     }
 
                 });
-            fulfill(bodyTpl.apply(contact.data));
+            fulfill(bodyTpl.apply(data));
         })
     }
 });
index 81f991b..c0d5eae 100644 (file)
@@ -1,6 +1,6 @@
 Ext.ns('Tine.Addressbook.Printer');
 
-Tine.Addressbook.Printer.ListRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer, {
+Tine.Addressbook.Printer.ListRenderer = Ext.extend(Ext.ux.Printer.EditDialogRenderer, {
 
     stylesheetPath: 'Tinebase/css/widgets/RecordPrinter.css',
 
@@ -17,7 +17,7 @@ Tine.Addressbook.Printer.ListRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer,
         });
     },
 
-    generateBody: function(component) {
+    generateBody: function(component, data) {
         var i18n = Tine.Tinebase.appMgr.get('Addressbook').i18n;
         var me = this;
 
@@ -67,88 +67,8 @@ Tine.Addressbook.Printer.ListRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer,
                                 return '<div class="rp-print-single-block-heading">' + i18n._('Related to') + '</div></div>' + relations  + '</br>';
                             }
                         }
-                    }).apply(component.record.data));
+                    }).apply(data));
             });
         });
-
-
-
-
     }
-});
-
-        /*
-        var i18n = Tine.Tinebase.appMgr.get('Addressbook').i18n;
-        var bodyTpl = new Ext.XTemplate(
-            '<div class="rp-print-single">',
-            '{[Tine.widgets.printer.headerRenderer()]}',
-            '<div class="rp-print-single-block">',
-                '<div class="rp-print-single-summary">',
-                    '<span class="adb-print-single-value">{name}</span>',
-                '</div>',
-                '<div class="rp-print-single-details-row">',
-                '{[this.fieldRenderer("", "List type")]}',
-                '{[this.keyFieldRenderer("listType", values.list_type)]}',
-                '</div>',
-                '<div class="rp-print-single-details-row">',
-                '{[this.fieldRenderer(values.description, "Description")]}',
-                '</div>',
-            '</div>',
-            '</br>',
-            '<div class="rp-print-single-block-heading">', i18n._('Members'), '</div>',
-            '<div class="rp-print-single-block">',
-            '{[this.memberRenderer()]}',
-            '</div>',
-            '</br>',
-            '{[this.customFieldRenderer(values.customfields)]}',
-            '<div class="rp-print-single-block-heading">', i18n._('Related to'), '</div>',
-            '<div class="rp-print-single-block">',
-            '{[this.relationRenderer(values.relations)]}',
-            '</div>',
-            '</div>',
-
-        {
-            keyFieldRenderer: function (keyField, values) {
-                return Tine.Tinebase.widgets.keyfield.Renderer.render('Addressbook', keyField, values);
-            },
-            customFieldRenderer: function(values) {
-                var html = '';
-
-                if (values) {
-                    html = '<div class="rp-print-single-block-heading">' + i18n._('Customfields') + '</div>' +
-                    Tine.widgets.customfields.Renderer.renderAll('Addressbook', Tine.Addressbook.Model.List, values) + '</br>';
-                }
-
-                return html
-            },
-            fieldRenderer: function(fieldValue, label) {
-                return Tine.widgets.printer.fieldRenderer('Addressbook', Tine.Addressbook.Model.list, fieldValue, label);
-            },
-            relationRenderer: function(values) {
-                return Tine.widgets.relation.Renderer.renderAll(values);
-
-            },
-            memberRenderer: function() {
-                this.generateMemberGrid(list.memberGridPanel).then(function(html) {
-                    return html;
-                });
-
-            },
-
-            generateMemberGrid: function(component) {
-                var renderer = new Ext.ux.Printer.GridPanelRenderer();
-
-                return new Promise(function (fulfill, reject) {
-                    renderer.prepareData(component).then(function(data) {
-                        fulfill(new Ext.XTemplate(
-
-                            renderer.generateBody(component)
-
-                        ).apply(data));
-                    });
-                });
-            }
-        });
-        return bodyTpl.apply(record.data);
-        */
-
+});
\ No newline at end of file
index 5d27297..f3372bd 100644 (file)
@@ -323,7 +323,7 @@ Tine.Calendar.EventEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
     onPrint: function(printMode) {
         this.onRecordUpdate();
         var renderer = new Tine.Calendar.Printer.EventRenderer();
-        renderer.print(this.record);
+        renderer.print(this);
     },
 
     initComponent: function() {
index 0cabd8f..fcd8313 100644 (file)
@@ -1,7 +1,7 @@
-Tine.Calendar.Printer.EventRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer, {
+Tine.Calendar.Printer.EventRenderer = Ext.extend(Ext.ux.Printer.EditDialogRenderer, {
     stylesheetPath: 'Calendar/css/print.css',
 
-    generateBody: function(event) {
+    generateBody: function(component, data) {
         var i18n = Tine.Tinebase.appMgr.get('Calendar').i18n;
 
         return new Promise(function (fulfill, reject) {
@@ -30,11 +30,11 @@ Tine.Calendar.Printer.EventRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer, {
                         '</div>',
                         '<div class="print-single-details-row">',
                             '<span class="cal-print-single-label">', i18n._('Start Time'), '</span>',
-                            '<span class="cal-print-single-value">{[this.datetimeRenderer(values.dtstart)]}</span>',
+                            '<span class="cal-print-single-value">{values.dtstart}</span>',
                         '</div>',
                         '<div class="print-single-details-row">',
                             '<span class="cal-print-single-label">', i18n._('End Time'), '</span>',
-                            '<span class="cal-print-single-value">{[this.datetimeRenderer(values.dtend)]}</span>',
+                            '<span class="cal-print-single-value">{values.dtend}</span>',
                         '</div>',
                         // @TODO print rrule
                         '{[this.customFieldRenderer(values.customfields)]}',
@@ -46,7 +46,6 @@ Tine.Calendar.Printer.EventRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer, {
                 '</div>',
 
                 {
-                    datetimeRenderer: Tine.Calendar.EventDetailsPanel.prototype.datetimeRenderer,
                     attendeeRenderer: Tine.Calendar.EventDetailsPanel.prototype.attendeeRenderer,
                     customFieldRenderer: function(values) {
                         return Tine.widgets.customfields.Renderer.renderAll('Calendar', Tine.Calendar.Model.Event, values);
@@ -54,13 +53,11 @@ Tine.Calendar.Printer.EventRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer, {
                 }
             );
 
-            fulfill(bodyTpl.apply(event.data));
+            fulfill(bodyTpl.apply(data));
         });
     },
 
-    getTitle: function(event) {
-        return event.getTitle();
-    },
-
-
+    getTitle: function(data) {
+        return data.summary;
+    }
 });
index 2559f38..c8ab84e 100644 (file)
           "path": "js/ux/Printer/renderers/"
         },
         {
+          "text": "EditDialogRenderer.js",
+          "path": "js/ux/Printer/renderers/"
+        },
+        {
           "text": "TitleRendererManager.js",
           "path": "js/data/"
         },
index 4b07ded..e41db9b 100644 (file)
@@ -220,11 +220,11 @@ Ext.ux.Printer.BaseRenderer = Ext.extend(Object, {
         var me = this;
         return new Promise(function (fulfill, reject) {
             me.prepareData(component).then(function(data) {
-                me.generateBody(component).then(function(bodyHtml) {
+                me.generateBody(component, data).then(function(bodyHtml) {
                     fulfill(new Ext.XTemplate(
                         '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
                         '<html>',
-                        '<head>',
+                        '<head> ',
                         '<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />',
                         me.getAdditionalHeaders(),
                         '<link href="' + me.stylesheetPath + '?' + new Date().getTime() + '" rel="stylesheet" type="text/css" media="screen,print" />',
@@ -254,9 +254,10 @@ Ext.ux.Printer.BaseRenderer = Ext.extend(Object, {
     * Returns the HTML that will be placed into the print window. This should produce HTML to go inside the
     * <body> element only, as <head> is generated in the print function
     * @param {Ext.Component} component The component to render
+    * @param data The data extracted from the component
     * @return {String} The HTML fragment to place inside the print window's <body> element
     */
-    generateBody: function() {
+    generateBody: function(component, data) {
         return new Promise(function (fulfill, reject) {
             fulfill('')
         });
diff --git a/tine20/Tinebase/js/ux/Printer/renderers/EditDialogRenderer.js b/tine20/Tinebase/js/ux/Printer/renderers/EditDialogRenderer.js
new file mode 100644 (file)
index 0000000..43601a3
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Tine 2.0
+ *
+ * @package     Offertory
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Michael Spahn <m.spahn@metaways.de>
+ * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
+ *
+ */
+Ext.ns('Ext.ux.Printer');
+
+/**
+ * Render any EditDialog.
+ */
+Ext.ux.Printer.EditDialogRenderer = Ext.extend(Ext.ux.Printer.BaseRenderer, {
+    /**
+     * @param {Tine.widgets.dialog.EditDialog} editDialog the edit dialog to print
+     * @return {Array} Data suitable for use in the XTemplate
+     */
+    prepareData: function (editDialog) {
+        var me = this;
+        return new Promise(function (fulfill, reject) {
+            var form = editDialog.getForm(),
+                recordData = Ext.util.JSON.decode(Ext.util.JSON.encode(editDialog.record.data));
+
+            form.items.each(function (field) {
+                if (field.hasOwnProperty('selectedRecord')) {
+                    recordData[field.getName()] = field.getRawValue();
+                }
+            });
+
+            fulfill(recordData);
+        });
+    }
+});