[Commits] r2196 - in core/trunk/geoext: lib/GeoExt/plugins tests/lib/GeoExt/plugins

commits at geoext.org commits at geoext.org
Mon May 17 14:34:31 CEST 2010


Author: pgiraud
Date: 2010-05-17 14:34:31 +0200 (Mon, 17 May 2010)
New Revision: 2196

Modified:
   core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js
   core/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html
Log:
adds setValue method which is called in the init method, avoids problems when the page has already been initialized

Modified: core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js	2010-05-17 12:30:09 UTC (rev 2195)
+++ core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js	2010-05-17 12:34:31 UTC (rev 2196)
@@ -111,6 +111,7 @@
             "layoutchange": this.onLayoutChange,
             scope: this
         });
+        this.setValue(this.printPage);
     },
 
     /** private: method[onFieldChange]
@@ -141,14 +142,7 @@
      */
     onPageChange: function(printPage) {
         if(!this._updating) {
-            var t = this.target;
-            t.suspendEvents();
-            if(t.store === printPage.printProvider.scales) {
-                t.setValue(printPage.scale.get(t.displayField));
-            } else if(t.name == "rotation") {
-                t.setValue(printPage.rotation);
-            }
-            t.resumeEvents();
+            this.setValue(printPage);
         }
     },
     
@@ -162,7 +156,25 @@
         var t = this.target;
         t.name == "rotation" && t.setDisabled(!layout.get("rotation"));
     },
-    
+
+    /** private: method[setValue]
+     *  :param printPage: :class:`GeoExt.data.PrintPage`
+     *
+     *  Sets the value in the target field.
+     */
+    setValue: function(printPage) {
+        var t = this.target;
+        t.suspendEvents();
+        if(t.store === printPage.printProvider.scales) {
+            if(printPage.scale) {
+                t.setValue(printPage.scale.get(t.displayField));
+            }
+        } else if(t.name == "rotation") {
+            t.setValue(printPage.rotation);
+        }
+        t.resumeEvents();
+    },
+
     /** private: method[destroy]
      */
     destroy: function() {

Modified: core/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html	2010-05-17 12:30:09 UTC (rev 2195)
+++ core/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html	2010-05-17 12:34:31 UTC (rev 2196)
@@ -8,8 +8,8 @@
 
     <script type="text/javascript">
         var printCapabilities = {"scales":[{"name":"1:25,000","value":"25000"},{"name":"1:50,000","value":"50000"},{"name":"1:100,000","value":"100000"},{"name":"1:200,000","value":"200000"},{"name":"1:500,000","value":"500000"},{"name":"1:1,000,000","value":"1000000"},{"name":"1:2,000,000","value":"2000000"},{"name":"1:4,000,000","value":"4000000"}],"dpis":[{"name":"75","value":"75"},{"name":"150","value":"150"},{"name":"300","value":"300"}],"layouts":[{"name":"A4 portrait","map":{"width":440,"height":483},"rotation":true},{"name":"Legal","map":{"width":440,"height":483},"rotation":false}],"printURL":"http://demo.opengeo.org/geoserver/pdf/print.pdf","createURL":"http://demo.opengeo.org/geoserver/pdf/create.json"};
-        
-        function test_init(t){
+
+         function test_init(t){
             t.plan(1);
             
             var log = {};
@@ -25,13 +25,77 @@
             var field = {
                 on: function(cfg) {
                     log.on = cfg;
-                }
+                },
+                suspendEvents: Ext.emptyFn,
+                resumeEvents: Ext.emptyFn
             };
             plugin.init(field);
             
             t.ok(log.on["valid"] === plugin.onFieldChange, "onFieldChange handler set correctly.");
         }
-            
+
+        function test_init__scales_field(t){
+            t.plan(1);
+
+            var log = {};
+            var printPage = new GeoExt.data.PrintPage({
+                printProvider: new GeoExt.data.PrintProvider({
+                    capabilities: printCapabilities
+                })
+            });
+            var scaleRecord = printPage.printProvider.scales.getAt(0);
+            printPage.setScale(scaleRecord);
+            var plugin = new GeoExt.plugins.PrintPageField({
+                printPage: printPage
+            });
+
+            var field = {
+                on: function(cfg) {
+                    log.on = cfg;
+                },
+                setValue: function(v) {
+                    log.value = v;
+                },
+                store: printPage.printProvider.scales,
+                displayField: "name",
+                suspendEvents: Ext.emptyFn,
+                resumeEvents: Ext.emptyFn
+            };
+            plugin.init(field);
+
+            t.eq(log.value, scaleRecord.get("name"), "field value set correctly");
+        }
+
+        function test_init__rotation_field(t){
+            t.plan(1);
+
+            var log = {};
+            var printPage = new GeoExt.data.PrintPage({
+                printProvider: new GeoExt.data.PrintProvider({
+                    capabilities: printCapabilities
+                })
+            });
+            printPage.setRotation(10, true);
+            var plugin = new GeoExt.plugins.PrintPageField({
+                printPage: printPage
+            });
+
+            var field = {
+                on: function(cfg) {
+                    log.on = cfg;
+                },
+                setValue: function(v) {
+                    log.value = v;
+                },
+                name: "rotation",
+                suspendEvents: Ext.emptyFn,
+                resumeEvents: Ext.emptyFn
+            };
+            plugin.init(field);
+
+            t.eq(log.value, 10, "field value set correctly");
+        }
+
         function test_onFieldChange(t) {
             t.plan(2);
 



More information about the Commits mailing list