[Commits] r1646 - in sandbox/cmoullet/ux/Printer: examples ux/layout

commits at geoext.org commits at geoext.org
Sun Jan 3 11:27:36 CET 2010


Author: cmoullet
Date: 2010-01-03 11:27:36 +0100 (Sun, 03 Jan 2010)
New Revision: 1646

Added:
   sandbox/cmoullet/ux/Printer/ux/layout/GeoExtPrinter.js
Modified:
   sandbox/cmoullet/ux/Printer/examples/PrinterExample.html
   sandbox/cmoullet/ux/Printer/examples/PrinterExample.js
   sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js
   sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html
Log:
Add e GeoExtPrinter in order to print iframe

Modified: sandbox/cmoullet/ux/Printer/examples/PrinterExample.html
===================================================================
--- sandbox/cmoullet/ux/Printer/examples/PrinterExample.html	2010-01-03 07:51:58 UTC (rev 1645)
+++ sandbox/cmoullet/ux/Printer/examples/PrinterExample.html	2010-01-03 10:27:36 UTC (rev 1646)
@@ -9,6 +9,7 @@
     <script type="text/javascript" src="../ux/layout/LayoutStore.js"></script>
     <script type="text/javascript" src="../ux/layout/LayoutPrinter.js"></script>
     <script type="text/javascript" src="../ux/layout/ExtPrinter.js"></script>
+    <script type="text/javascript" src="../ux/layout/GeoExtPrinter.js"></script>
     <script type="text/javascript" src="../ux/widgets/PrinterPanel.js"></script>
     <script type="text/javascript" src="../ux/widgets/PrinterWindow.js"></script>
     <script type="text/javascript" src="PrinterExample.js"></script>

Modified: sandbox/cmoullet/ux/Printer/examples/PrinterExample.js
===================================================================
--- sandbox/cmoullet/ux/Printer/examples/PrinterExample.js	2010-01-03 07:51:58 UTC (rev 1645)
+++ sandbox/cmoullet/ux/Printer/examples/PrinterExample.js	2010-01-03 10:27:36 UTC (rev 1646)
@@ -41,6 +41,15 @@
         }
     });
 
+    toolbar.push({
+        text: 'Iframe print',
+        enableToggle: false,
+        handler: function() {
+            GeoExt.ux.layout.LayoutPrinter(map, OpenLayers.i18n('A4 portrait'));
+            GeoExt.ux.layout.print();
+        }
+    });
+
     viewport = new Ext.Viewport({
         layout: "border",
         id: 'mainViewport',

Added: sandbox/cmoullet/ux/Printer/ux/layout/GeoExtPrinter.js
===================================================================
--- sandbox/cmoullet/ux/Printer/ux/layout/GeoExtPrinter.js	                        (rev 0)
+++ sandbox/cmoullet/ux/Printer/ux/layout/GeoExtPrinter.js	2010-01-03 10:27:36 UTC (rev 1646)
@@ -0,0 +1,58 @@
+Ext.namespace("GeoExt.ux.layout");
+
+GeoExt.ux.layout.print = function(config) {
+
+    var c = document.getElementById('printcontainer');
+    var iFrame = document.getElementById('printframe');
+
+    var strHTML;
+
+    //Get rid of the old crap so we don't copy it
+    //to our iframe
+    if (iFrame != null) c.removeChild(iFrame);
+    if (c != null) document.body.removeChild(c);
+
+    var page = GeoExt.ux.layout.getHtmlPage(GeoExt.ux.layout.LayoutPrinter.layout);
+    var pageUrl = null;
+    if (page.indexOf('http://') === 0) {
+        pageUrl = page;
+    } else {
+        pageUrl = "../ux/layout/" + page;
+    }
+
+    var conn = new Ext.data.Connection();
+    conn.request({
+        url: pageUrl,
+        method: 'GET',
+        success: function(responseObject) {
+            //alert(responseObject.responseText);
+            strHTML = responseObject.responseText;
+            
+            //I coun't get FF to print a hidden iframe,
+            //so I encapsulated it in a hidden div.
+            c = document.createElement('div');
+            c.setAttribute('style', 'width:0px;height:0px;' + (Ext.isSafari ? 'display:none;' : 'visibility:hidden;'));
+            c.setAttribute('id', 'printcontainer');
+            document.body.appendChild(c);
+
+            //IE doesn't like style attributes anymore?
+            if (Ext.isIE)
+                c.style.display = 'none';
+
+            iFrame = document.createElement('iframe');
+            iFrame.setAttribute('id', 'printframe');
+            iFrame.setAttribute('name', 'printframe');
+            c.appendChild(iFrame);
+
+            //Write our new document to the iframe
+            iFrame.contentWindow.document.open();
+            iFrame.contentWindow.document.write(strHTML);
+            iFrame.contentWindow.document.close();
+        },
+        failure: function() {
+
+        }
+    });
+
+
+};
\ No newline at end of file

Modified: sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js
===================================================================
--- sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js	2010-01-03 07:51:58 UTC (rev 1645)
+++ sandbox/cmoullet/ux/Printer/ux/layout/LayoutPrinter.js	2010-01-03 10:27:36 UTC (rev 1646)
@@ -81,7 +81,6 @@
 
     }
     childWindow.map.setCenter(GeoExt.ux.layout.LayoutPrinter.map.getCenter(), GeoExt.ux.layout.LayoutPrinter.map.getZoom());
-    childWindow.print();
 };
 
 GeoExt.ux.layout.LayoutPrinter.layout = null;

Modified: sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html
===================================================================
--- sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html	2010-01-03 07:51:58 UTC (rev 1645)
+++ sandbox/cmoullet/ux/Printer/ux/layout/a4_portrait.html	2010-01-03 10:27:36 UTC (rev 1646)
@@ -33,9 +33,22 @@
     <script type="text/javascript" src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
     <script type="text/javascript">
         var map;
+        var layer;
         function init() {
             map = new OpenLayers.Map('map');
-            window.opener.GeoExt.ux.layout.LayoutPrinter.Apply(window);
+            if (window.opener) {
+                window.opener.GeoExt.ux.layout.LayoutPrinter.Apply(window);
+            } else if (window.parent) {
+                var iFrame = window.parent.document.getElementById('printframe');
+                window.parent.GeoExt.ux.layout.LayoutPrinter.Apply(iFrame.contentWindow);
+                //window.parent.GeoExt.ux.layout.LayoutPrinter.Apply(window);
+            } 
+            if (OpenLayers.Util.getBrowserName() == 'msie') {
+                document.execCommand('print');
+            } else {
+                window.print();
+            }
+
         }
     </script>
 



More information about the Commits mailing list