[Commits] r1587 - in sandbox/ahocevar/playground/ux/Printing/ux: data plugins

commits at geoext.org commits at geoext.org
Tue Dec 15 23:48:24 CET 2009


Author: ahocevar
Date: 2009-12-15 23:48:24 +0100 (Tue, 15 Dec 2009)
New Revision: 1587

Modified:
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
   sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageField.js
   sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js
Log:
wherever we store or set something from a store, use a record instead of a field value.

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js	2009-12-15 13:02:49 UTC (rev 1586)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js	2009-12-15 22:48:24 UTC (rev 1587)
@@ -52,7 +52,7 @@
     handle: null,
     
     /** api: property[scale]
-     *  ``Float`` The current scale of the page. Read-only.
+     *  ``Ext.data.Record`` The current scale record of the page. Read-only.
      */
     scale: null,
     
@@ -122,7 +122,7 @@
     },
     
     /** api: method[setScale]
-     *  :param scale: ``Float`` The new scale.
+     *  :param scale: ``Ext.data.Record`` The new scale record.
      * 
      *  Updates the page geometry to match a given scale. Since this takes the
      *  current layout of the printProvider into account, this can be used to
@@ -176,7 +176,7 @@
         var extent = map.getExtent();
         var scale;
         this.printProvider.scales.each(function(rec) {
-            scale = rec.get("value");
+            scale = rec;
             return !extent.containsBounds(this.calculatePageBounds(scale));
         }, this)
         this.setScale(scale);
@@ -204,11 +204,10 @@
         var dist = f.geometry.getCentroid().distanceTo(geom);
         var scaleFits = [], distHash = {};
         this.printProvider.scales.each(function(rec){
-            var scale = rec.get("value");
-            var bounds = this.calculatePageBounds(scale);
+            var bounds = this.calculatePageBounds(rec);
             var d = Math.abs((bounds.getHeight() / 2) - dist);
             scaleFits.push(d);
-            distHash[d.toPrecision(8)] = scale;
+            distHash[d.toPrecision(8)] = rec;
         }, this);
         var min = scaleFits.concat().sort(function(a,b){return a<b?-1:1;})[0];
         var scale = distHash[min.toPrecision(8)];
@@ -271,17 +270,19 @@
     },
 
     /** private: method[calculatePageBounds]
-     *  :param scale: ``Float`` Scale to calculate the page bounds for.
+     *  :param scale: ``Ext.data.Record`` Scale record to calculate the page
+     *      bounds for.
      *  :return: ``OpenLayers.Bounds``
      *  
      *  Calculates the page bounds for a given scale.
      */
     calculatePageBounds: function(scale) {
+        var s = scale.get("value");
         var geom = this.feature.geometry;
-        var size = this.printProvider.getLayout().get("size");
+        var size = this.printProvider.layout.get("size");
         var unitsRatio = OpenLayers.INCHES_PER_UNIT[this.printProvider.units];
-        var w = size.width / 72 / unitsRatio * scale / 2;
-        var h = size.height / 72 / unitsRatio * scale / 2;
+        var w = size.width / 72 / unitsRatio * s / 2;
+        var h = size.height / 72 / unitsRatio * s / 2;
         var center = geom.getBounds().getCenterLonLat();
         
         return new OpenLayers.Bounds(center.lon - w, center.lat - h,

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-15 13:02:49 UTC (rev 1586)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-15 22:48:24 UTC (rev 1587)
@@ -127,14 +127,15 @@
     layouts: null,
     
     /** api: property[dpi]
-     *  ``String`` the name of the currently used layout. Read-only, use
-     *      :ref:`GeoExt.ux.data.PrintProvider.setDpi` to set the value.
+     *  ``Ext.data.Record`` the record for the currently used layout.
+     *  Read-only, use :ref:`GeoExt.ux.data.PrintProvider.setDpi` to set the
+     *  value.
      */
     dpi: null,
 
     /** api: property[layout]
-     *  ``String`` the name of the currently used layout. Read-only, use
-     *      :ref:`GeoExt.ux.data.PrintProvider.setLayout` to set the value.
+     *  ``Ext.data.Record`` the record of the currently used layout. Read-only,
+     *  use :ref:`GeoExt.ux.data.PrintProvider.setLayout` to set the value.
      */
     layout: null,
 
@@ -216,43 +217,24 @@
         GeoExt.ux.data.PrintProvider.superclass.constructor.apply(this, arguments);
     },
     
-    /** api: method[getLayout]
-     *  :return: ``Ext.data.Record`` the layout record of the current layout.
-     *  
-     *  Gets the current layout.
-     */
-    getLayout: function() {
-        return this.layouts.getAt(this.layouts.find("name", this.layout));
-    },
-    
     /** api: method[setLayout]
-     *  :param layout: ``String`` the name of the layout.
+     *  :param layout: ``Ext.data.Record`` the record of the layout.
      *  
      *  Sets the layout for this printProvider.
      */
     setLayout: function(layout) {
         this.layout = layout;
-        this.fireEvent("layoutchange", this, this.getLayout());
+        this.fireEvent("layoutchange", this, layout);
     },
     
-    /** api: method[getDpi]
-     *  :return: ``Ext.data.Record`` the layout record of the currently
-     *      configured dpi setting.
-     *  
-     *  Gets the current dpi setting.
-     */
-    getDpi: function() {
-        return this.dpis.getAt(this.dpis.find("value", this.dpi));
-    },
-    
     /** api: method[setDpi]
-     *  :param layout: ``Number`` the dpi setting.
+     *  :param layout: ``Ext.data.Record`` the dpi record.
      *  
      *  Sets the dpi for this printProvider.
      */
     setDpi: function(dpi) {
         this.dpi = dpi;
-        this.fireEvent("dpichange", this, this.getDpi())
+        this.fireEvent("dpichange", this, dpi)
     },
 
     /** api: method[print]
@@ -286,18 +268,18 @@
             var center = page.getCenter();
             encodedPages.push(Ext.apply({
                 center: [center.lon, center.lat],
-                scale: page.scale,
+                scale: page.scale.get("value"),
                 rotation: page.rotation
             }, page.customParams));
         }, this);
         
         var payload = Ext.apply({
             pages: encodedPages,
-            dpi: this.dpi,
+            dpi: this.dpi.get("value"),
             units: this.units,
             srs: map.baseLayer.projection.getCode(),
             layers: encodedLayers,
-            layout: this.layout
+            layout: this.layout.get("name")
         }, this.customParams);
         
         if(options.legend) {
@@ -346,8 +328,8 @@
         this.dpis.loadData(this.capabilities);
         this.layouts.loadData(this.capabilities);
         
-        this.layout = this.layouts.getAt(0).get("name");
-        this.dpi = this.dpis.getAt(0).get("value");
+        this.setLayout(this.layouts.getAt(0));
+        this.setDpi(this.dpis.getAt(0));
     },
     
     /** private: method[encodeLayer]

Modified: sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageField.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageField.js	2009-12-15 13:02:49 UTC (rev 1586)
+++ sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageField.js	2009-12-15 22:48:24 UTC (rev 1587)
@@ -51,10 +51,10 @@
      */
     init: function(target) {
         this.target = target;
-        target.on({
-            "valid": this.onFieldChange,
-            scope: this
-        });
+        onCfg = {scope: this};
+        onCfg[target instanceof Ext.form.ComboBox ? "select" : "valid"] =
+            this.onFieldChange;
+        target.on(onCfg);
         this.page.on({
             "change": this.onPageChange,
             scope: this
@@ -62,16 +62,16 @@
     },
 
     /** private: method[onFieldChange]
-     *  :param field: ``Ext.form.Field
+     *  :param field: ``Ext.form.Field``
+     *  :param record: ``Ext.data.Record`` Optional.
      *  
-     *  Handler for the target field's "valid" event.
+     *  Handler for the target field's "valid" or "select" event.
      */
-    onFieldChange: function(field) {
+    onFieldChange: function(field, record) {
         var printProvider = this.page.printProvider;
         var value = field.getValue();
         if(field.store === printProvider.scales) {
-            var i = printProvider.scales.find(field.displayField, value);
-            this.page.setScale(printProvider.scales.getAt(i).get("value"));
+            this.page.setScale(record);
         } else if(field.name == "rotation") {
             this.page.setRotation(value);
         } else {
@@ -88,12 +88,10 @@
     onPageChange: function(page) {
         var t = this.target;
         t.suspendEvents();
-        var printProvider = this.page.printProvider;
-        if(t.store === printProvider.scales) {
-            var i = t.store.find("value", this.page.scale);
-            t.setValue(t.store.getAt(i).get("name"));
+        if(t.store === page.printProvider.scales) {
+            t.setValue(page.scale.get(t.displayField));
         } else if(t.name == "rotation") {
-            t.setValue(this.page.rotation);
+            t.setValue(page.rotation);
         }
         t.resumeEvents();
     }

Modified: sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js	2009-12-15 13:02:49 UTC (rev 1586)
+++ sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js	2009-12-15 22:48:24 UTC (rev 1587)
@@ -21,6 +21,11 @@
  */
 GeoExt.ux.plugins.PrintProviderField = Ext.extend(Ext.util.Observable, {
     
+    /** private: property[target]
+     *  ``Ext.form.Field`` This plugin's target field.
+     */
+    target: null,
+    
     /** private: method[constructor]
      */
     constructor: function(config) {
@@ -35,11 +40,14 @@
      *      extends.
      */
     init: function(target) {
-        target.on({
+        this.target = target;
+        var onCfg = {
             "render": this.onRender,
-            "valid": this.onFieldChange,
             scope: this
-        });
+        };
+        onCfg[target instanceof Ext.form.ComboBox ? "select" : "valid"] =
+            this.onFieldChange;
+        target.on(onCfg);
     },
     
     /** private: method[onRender]
@@ -50,21 +58,17 @@
     onRender: function(field) {
         var printProvider = field.ownerCt.printProvider;
         if(field.store === printProvider.layouts) {
-            field.setValue(printProvider.layout);
+            field.setValue(printProvider.layout.get(field.displayField));
             printProvider.on({
                 "layoutchange": function(printProvider, layout) {
-                    printProvider.suspendEvents();
-                    field.setValue(layout.get("name"));
-                    printProvider.resumeEvents();
+                    field.setValue(layout.get(field.displayField));
                 }
             });
         } else if(field.store === printProvider.dpis) {
-            field.setValue(printProvider.dpi);
+            field.setValue(printProvider.dpi.get(field.displayField));
             printProvider.on({
                 "dpichange": function(printProvider, dpi) {
-                    printProvider.suspendEvents();
-                    field.setValue(dpi.get("value"));
-                    printProvider.resumeEvents();
+                    field.setValue(dpi.get(field.displayField));
                 }
             });
         } else {
@@ -74,17 +78,21 @@
     
     /** private: method[onFieldChange]
      *  :param field: ``Ext.form.Field``
+     *  :param record: ``Ext.data.Record`` Optional.
      *  
-     *  Handler for the target field's valid event.
+     *  Handler for the target field's "valid" or "select" event.
      */
-    onFieldChange: function(field) {
+    onFieldChange: function(field, record) {
         var printProvider = field.ownerCt.printProvider;
         var value = field.getValue();
-        if(field.store === printProvider.layouts) {
-            printProvider.setLayout(value);
-        } else if(field.store === printProvider.dpis) {
-            var i = printProvider.dpis.find(field.displayField, value);
-            printProvider.setDpi(printProvider.dpis.getAt(i).get("value"));
+        if(record) {
+            switch(field.store) {
+                case printProvider.layouts:
+                    printProvider.setLayout(record);
+                    break;
+                case printProvider.dpis:
+                    printProvider.setDpi(record);
+            }
         } else {
             printProvider.customParams[field.name] = value;
         }



More information about the Commits mailing list