[Commits] r1608 - in sandbox/ahocevar/playground/ux/Printing: examples ux/data ux/widgets/form

commits at geoext.org commits at geoext.org
Thu Dec 24 19:44:23 CET 2009


Author: ahocevar
Date: 2009-12-24 19:44:23 +0100 (Thu, 24 Dec 2009)
New Revision: 1608

Modified:
   sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
   sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
   sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/PrintForm.js
   sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js
Log:
fixes and improvements suggested by bartvde

Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.html	2009-12-23 17:25:59 UTC (rev 1607)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.html	2009-12-24 18:44:23 UTC (rev 1608)
@@ -18,8 +18,8 @@
         make them available in the printCapabilities variable.
         The script tag below can be removed when configuring the printProvider
         with url instead of capabilities
+        <script type="text/javascript" src="http://demo.mapfish.org/mapfishsample/1.2/print/info.json?var=printCapabilities"></script>
         -->
-        <script type="text/javascript" src="http://demo.mapfish.org/mapfishsample/1.2/print/info.json?var=printCapabilities"></script>
         
     </head>
     <body>

Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.js	2009-12-23 17:25:59 UTC (rev 1607)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.js	2009-12-24 18:44:23 UTC (rev 1608)
@@ -5,13 +5,13 @@
     printProvider = new GeoExt.ux.data.PrintProvider({
         // using get for remote service access without same origin restriction.
         // For asynchronous requests, we would set method to "POST".
-        method: "GET",
-        //method: "POST",
+        //method: "GET",
+        method: "POST",
         
         // capabilities from script tag in Printing.html. For asynchonous
         // loading, we would configure url instead of capabilities.
-        capabilities: printCapabilities
-        //url: "/geoserver/pdf/"
+        //capabilities: printCapabilities
+        url: "/geoserver/pdf/"
     });
     
     var mapPanel = new GeoExt.MapPanel({
@@ -90,13 +90,14 @@
     
     /* add the print form to its container and make sure that the print page
      * fits the max extent
-     */
     formCt.add(printForm);
     formCt.doLayout();
     printForm.pages[0].fitPage(mapPanel.map);
+     */
 
     /* use this code block instead of the above one if you configured the
      * printProvider with url instead of capabilities
+     */
     var myMask = new Ext.LoadMask(formCt.body, {msg:"Loading data..."});
     myMask.show();
     printProvider.on("loadcapabilities", function() {
@@ -105,6 +106,5 @@
         formCt.doLayout();
         printForm.pages[0].fitPage(mapPanel.map);
     });
-     */
     
 });

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-23 17:25:59 UTC (rev 1607)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-24 18:44:23 UTC (rev 1608)
@@ -186,7 +186,30 @@
              *    PrintProvider
              *  * dpi - ``Ext.data.Record`` the new dpi record
              */
-            "dpichange"
+            "dpichange",
+            
+            /** api: events[beforeprint]
+             *  Triggered when the print method is called.
+             *  
+             *  Listener arguments:
+             *  * printProvider - :class:`GeoExt.ux.data.PrintProvider` this
+             *    PrintProvider
+             *  * map - ``OpenLayers.Map`` the map being printed
+             *  * pages - Array of :class:`GeoExt.ux.data.PrintPage` the print
+             *    pages being printed
+             *  * options - ``Object`` the options to the print command
+             */
+            "beforeprint",
+            
+            /** api: events[print]
+             *  Triggered when the print document is opened.
+             *  
+             *  Listener arguments:
+             *  * printProvider - :class:`GeoExt.ux.data.PrintProvider` this
+             *    PrintProvider
+             *  * url - ``String`` the url of the print document
+             */
+            "print"
         ]);
         
         this.scales = new Ext.data.JsonStore({
@@ -261,11 +284,14 @@
      *  with the resulting PDF.
      */
     print: function(map, pages, options) {
-        options = options || {};
         if(map instanceof GeoExt.MapPanel) {
             map = map.map;
         }
-        
+        options = options || {};
+        if(this.fireEvent("beforeprint", this, map, pages, options) === false) {
+            return;
+        }
+
         var jsonData = Ext.apply({
             units: map.baseLayer.units,
             srs: map.baseLayer.projection.getCode(),
@@ -297,15 +323,20 @@
         if(options.legend) {
             var encodedLegends = [];
             options.legend.items.each(function(cmp) {
-                var encFn = this.encoders.legends[cmp.getXType()];
-                encodedLegends = encodedLegends.concat(encFn.call(this, cmp));
+                if(cmp.isVisible()) {
+                    var encFn = this.encoders.legends[cmp.getXType()];
+                    encodedLegends = encodedLegends.concat(
+                        encFn.call(this, cmp));
+                }
             }, this);
             jsonData.legends = encodedLegends;
         }
 
         if(this.method === "GET") {
-            window.open(this.capabilities.printURL + "?spec=" +
-                escape(Ext.encode(jsonData)));
+            var url = this.capabilities.printURL + "?spec=" +
+                escape(Ext.encode(jsonData));
+            window.open(url);
+            this.fireEvent("print", this, url);
         } else {
             Ext.Ajax.request({
                 url: this.capabilities.createURL,
@@ -324,7 +355,9 @@
                         // This avoids popup blockers for all other browers
                         window.location.href = url;                        
                     } 
-                }
+                    this.fireEvent("print", this, url);
+                },
+                scope: this
             });
         }
     },
@@ -339,7 +372,7 @@
             success: function(response) {
                 this.capabilities = Ext.decode(response.responseText);
                 this.loadStores();
-                this.fireEvent("loadcapabilities", this.capabilities);
+                this.fireEvent("loadcapabilities", this, this.capabilities);
             },
             scope: this
         });
@@ -365,7 +398,7 @@
     encodeLayer: function(layer) {
         var encLayer;
         for(var c in this.encoders.layers) {
-            if(layer instanceof OpenLayers.Layer[c]) {
+            if(OpenLayers.Layer[c] && layer instanceof OpenLayers.Layer[c]) {
                 encLayer = this.encoders.layers[c].call(this, layer);
                 break;
             }

Modified: sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/PrintForm.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/PrintForm.js	2009-12-23 17:25:59 UTC (rev 1607)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/PrintForm.js	2009-12-24 18:44:23 UTC (rev 1608)
@@ -157,10 +157,10 @@
         Ext.each(this.pages, function(page) {
             this.layer.removeFeatures(page.feature, page.handle);
         }, this);
+        this.control.destroy();
         if(!this.initialConfig.layer) {
             this.layer.destroy();
         }
-        this.control.destroy();
         delete this.layer;
         delete this.map;
         delete this.control;

Modified: sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js	2009-12-23 17:25:59 UTC (rev 1607)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js	2009-12-24 18:44:23 UTC (rev 1608)
@@ -31,17 +31,49 @@
 GeoExt.ux.form.SimplePrint = Ext.extend(GeoExt.ux.form.PrintForm, {
     
     /* begin i18n */
+    /** api: property[layoutText] ``String`` i18n */
     layoutText: "Layout",
+    /** api: property[dpiText] ``String`` i18n */
     dpiText: "DPI",
+    /** api: property[scaleText] ``String`` i18n */
     scaleText: "Scale",
+    /** api: property[rotationText] ``String`` i18n */
     rotationText: "Rotation",
+    /** api: property[printText] ``String`` i18n */
     printText: "Print",
+    /** api: property[creatingPdfText] ``String`` i18n */
+    creatingPdfText: "Creating PDF...",
     /* end i18n */
    
-   /** api: property[printOptions]
-    *  ``Object`` Optional options for the printProvider's print command.
-    */
-   printOptions: null,
+    /** api: config[printOptions]
+     *  ``Object`` Optional options for the printProvider's print command.
+     */
+
+    /** api: property[printOptions]
+     *  ``Object`` Optional options for the printProvider's print command.
+     */
+    printOptions: null,
+    
+    /** api: config[hideUnique]
+     *  ``Boolean`` If set to false, combo boxes for stores with just one value
+     *  will be rendered. Default is true.
+     */
+    
+    /** api: config[hideRotation]
+     *  ``Boolean`` If set to true, the Rotation field will not be rendered.
+     *  Default is false.
+     */
+    
+    /** api: config[busyMask]
+     *  ``Ext.LoadMask`` A LoadMask to use while the print document is
+     *  prepared. Optional, will be auto-created with ``creatingPdfText` if
+     *  not provided.
+     */
+    
+    /** private: property[busyMask]
+     *  ``Ext.LoadMask``
+     */
+    busyMask: null,
    
     /** private: method[initComponent]
      */
@@ -52,18 +84,40 @@
             printProvider: this.printProvider,
             layer: this.layer
         }));
+        
+        if (!this.busyMask) {
+            this.busyMask = new Ext.LoadMask(Ext.getBody(), {
+                msg: this.creatingPdfText
+            });
+        }
 
-        this.initForm();
+        this.printProvider.on({
+            "beforeprint": this.busyMask.show,
+            "print": this.busyMask.hide,
+            scope: this.busyMask
+        });
+
+        if(this.printProvider.capabilities) {
+            this.initForm();
+        } else {
+            this.printProvider.on({
+                "loadcapabilities": this.initForm,
+                scope: this,
+                single: true
+            });
+        }
     },
     
     /** private: method[initForm]
      *  Creates and adds items to the form.
      */
     initForm: function() {
-        var items = [{
+        var p = this.printProvider;
+        var hideUnique = this.initialConfig.hideUnique !== false;
+        !(hideUnique && p.layouts.getCount() <= 1) && this.add({
             xtype: "combo",
             fieldLabel: this.layoutText,
-            store: this.printProvider.layouts,
+            store: p.layouts,
             displayField: "name",
             typeAhead: true,
             mode: "local",
@@ -71,10 +125,11 @@
             triggerAction: "all",
             selectOnFocus: true,
             plugins: new GeoExt.ux.plugins.PrintProviderField()
-        }, {
+        });
+        !(hideUnique && p.dpis.getCount() <= 1) && this.add({
             xtype: "combo",
             fieldLabel: this.dpiText,
-            store: this.printProvider.dpis,
+            store: p.dpis,
             displayField: "name",
             typeAhead: true,
             mode: "local",
@@ -82,10 +137,11 @@
             triggerAction: "all",
             selectOnFocus: true,
             plugins: new GeoExt.ux.plugins.PrintProviderField()
-        }, {
+        });
+        !(hideUnique && p.scales.getCount() <= 1) && this.add({
             xtype: "combo",
             fieldLabel: this.scaleText,
-            store: this.printProvider.scales,
+            store: p.scales,
             displayField: "name",
             typeAhead: true,
             mode: "local",
@@ -95,7 +151,8 @@
             plugins: new GeoExt.ux.plugins.PrintPageField({
                 page: this.pages[0]
             })
-        }, {
+        });
+        this.initialConfig.hideRotation !== true && this.add({
             xtype: "textfield",
             fieldLabel: this.rotationText,
             name: "rotation",
@@ -106,21 +163,26 @@
             plugins: new GeoExt.ux.plugins.PrintPageField({
                 page: this.pages[0]
             })
-        }];
-        Ext.each(items, function(item){
-            this.add(item);
-        }, this);
+        });
 
         this.addButton({
             text: this.printText,
             handler: function() {
-                this.printProvider.print(this.map, this.pages,
+                p.print(this.map, this.pages,
                     this.printOptions);
             },
             scope: this
         });
 
         this.doLayout();
+    },
+    
+    beforeDestroy: function() {
+        this.printProvider.un({
+            "beforePrint": this.busyMask.show,
+            "print": this.busyMask.hide
+        });
+        GeoExt.ux.SimplePrint.superclass.beforeDestroy.apply(this, arguments);
     }
     
 });



More information about the Commits mailing list