[Commits] r1784 - in sandbox/ahocevar/playground: trunk/geoext/examples trunk/geoext/lib/GeoExt/data trunk/geoext/lib/GeoExt/plugins trunk/geoext/tests trunk/geoext/tests/lib/GeoExt trunk/geoext/tests/lib/GeoExt/data trunk/geoext/tests/lib/GeoExt/plugins ux/Printing/examples ux/Printing/ux/widgets/form
commits at geoext.org
commits at geoext.org
Tue Jan 19 22:17:13 CET 2010
Author: ahocevar
Date: 2010-01-19 22:17:13 +0100 (Tue, 19 Jan 2010)
New Revision: 1784
Added:
sandbox/ahocevar/playground/trunk/geoext/examples/print-form.html
sandbox/ahocevar/playground/trunk/geoext/examples/print-form.js
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintProviderField.html
Modified:
sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js
sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js
sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintProviderField.js
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html
sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js
sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js
Log:
tests and example for form plugins, fixed getAbsoluteUrl
Added: sandbox/ahocevar/playground/trunk/geoext/examples/print-form.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/examples/print-form.html (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/examples/print-form.html 2010-01-19 21:17:13 UTC (rev 1784)
@@ -0,0 +1,31 @@
+<html>
+ <head>
+ <title>GeoExt PrintPageField and PrintProviderField Example</title>
+
+ <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/ext-all.js"></script>
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/examples/shared/examples.css" />
+ <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+ <script type="text/javascript" src="print-form.js"></script>
+
+ <!-- The script below will load the capabilities of the print service
+ and save them into the global printCapabilities variable. Instead
+ of this, the PrintProvider can be configured with a url and take
+ care of fetching the capabilities. -->
+ <script type="text/javascript" src="http://demo.opengeo.org/geoserver/pdf/info.json?var=printCapabilities"></script>
+
+ </head>
+ <body>
+ <h1>Advanced Printing with Special Form Fields</h1>
+ <p>This example shows the how to accomplish advanced printing, with a
+ form controlling parameters for the
+ <a href="http://trac.mapfish.org/trac/mapfish/wiki/PrintModuleInstallation">MapFish</a>
+ or <a href="http://geoserver.org/display/GEOS/Printing+2.0+HOWTO">GeoServer</a>
+ print module.</p>
+ <p>The js is not minified so it is readable. See <a href="print-form.js">print-form.js</a>.</p>
+ <div id="content"></div>
+ </body>
+</html>
Added: sandbox/ahocevar/playground/trunk/geoext/examples/print-form.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/examples/print-form.js (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/examples/print-form.js 2010-01-19 21:17:13 UTC (rev 1784)
@@ -0,0 +1,131 @@
+ /**
+ * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+/** api: example[print-form]
+ * Advanced Printing with a Form
+ * -----------------------------
+ * Using form fields with PrintPageField and PrintProviderField plugins to
+ * control print output.
+ */
+
+var mapPanel, printPage;
+
+Ext.onReady(function() {
+ // The printProvider that connects us to the print service
+ var printProvider = new GeoExt.data.PrintProvider({
+ method: "GET", // "POST" recommended for production use
+ capabilities: printCapabilities // from the info.json script in the html
+ });
+ // Our print page. Stores scale, center and rotation and gives us a page
+ // extent feature that we can add to a layer.
+ printPage = new GeoExt.data.PrintPage({
+ printProvider: printProvider,
+ customParams: {
+ mapTitle: "Printing Demo"
+ }
+ });
+ // A layer to display the print page extent
+ var pageLayer = new OpenLayers.Layer.Vector();
+ pageLayer.addFeatures(printPage.feature);
+
+ // The map we want to print
+ mapPanel = new GeoExt.MapPanel({
+ region: "center",
+ map: {
+ eventListeners: {
+ // recenter/resize page extent after pan/zoom
+ "moveend": function(){ printPage.fit(this); }
+ }
+ },
+ layers: [
+ new OpenLayers.Layer.WMS("Tasmania", "http://demo.opengeo.org/geoserver/wms",
+ {layers: "topp:tasmania_state_boundaries"}, {singleTile: true}),
+ pageLayer
+ ],
+ center: [146.56, -41.56],
+ zoom: 6
+ });
+ // The form with fields controlling the print output
+ var formPanel = new GeoExt.form.FormPanel({
+ region: "west",
+ width: 150,
+ bodyStyle: "padding:5px",
+ labelAlign: "top",
+ defaults: {anchor: "100%"},
+ items: [{
+ xtype: "textarea",
+ name: "comment",
+ value: "",
+ fieldLabel: "Comment",
+ plugins: new GeoExt.plugins.PrintPageField({
+ printPage: printPage
+ })
+ }, {
+ xtype: "combo",
+ store: printProvider.layouts,
+ displayField: "name",
+ fieldLabel: "Layout",
+ typeAhead: true,
+ mode: "local",
+ triggerAction: "all",
+ plugins: new GeoExt.plugins.PrintProviderField({
+ printProvider: printProvider
+ })
+ }, {
+ xtype: "combo",
+ store: printProvider.dpis,
+ displayField: "name",
+ fieldLabel: "Resolution",
+ tpl: '<tpl for="."><div class="x-combo-list-item">{name} dpi</div></tpl>',
+ typeAhead: true,
+ mode: "local",
+ triggerAction: "all",
+ plugins: new GeoExt.plugins.PrintProviderField({
+ printProvider: printProvider
+ }),
+ // the plugin will work even if we modify a combo value
+ setValue: function(v) {
+ v = parseInt(v) + " dpi";
+ Ext.form.ComboBox.prototype.setValue.apply(this, arguments);
+ }
+ }, {
+ xtype: "combo",
+ store: printProvider.scales,
+ displayField: "name",
+ fieldLabel: "Scale",
+ typeAhead: true,
+ mode: "local",
+ triggerAction: "all",
+ plugins: new GeoExt.plugins.PrintPageField({
+ printPage: printPage
+ })
+ }, {
+ xtype: "textfield",
+ name: "rotation",
+ fieldLabel: "Rotation",
+ plugins: new GeoExt.plugins.PrintPageField({
+ printPage: printPage
+ })
+ }],
+ buttons: [{
+ text: "Create PDF",
+ handler: function() {
+ printProvider.print(mapPanel, printPage);
+ }
+ }]
+ });
+
+ // The main panel
+ new Ext.Panel({
+ renderTo: "content",
+ layout: "border",
+ width: 700,
+ height: 420,
+ items: [mapPanel, formPanel]
+ });
+});
Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-01-19 15:56:33 UTC (rev 1783)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-01-19 21:17:13 UTC (rev 1784)
@@ -431,10 +431,11 @@
getAbsoluteUrl: function(url) {
var a;
if(Ext.isIE) {
- if(url.indexOf("../") === 0) {
- url = window.location.pathname + "/../" + url;
- }
a = document.createElement("<a href='" + url + "'/>");
+ a.style.display = "none";
+ document.body.appendChild(a);
+ a.href = a.href;
+ document.body.removeChild(a);
} else {
a = document.createElement("a");
a.href = url;
Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js 2010-01-19 15:56:33 UTC (rev 1783)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js 2010-01-19 21:17:13 UTC (rev 1784)
@@ -13,6 +13,53 @@
* base_link = `Ext.util.Observable <http://extjs.com/deploy/dev/docs/?class=Ext.util.Observable>`_
*/
+/** api: example
+ * A form with a combo box for the scale and text fields for rotation and a
+ * page title. The page title is a custom parameter of the print module's
+ * page configuration:
+ *
+ * .. code-block:: javascript
+ *
+ * var printPage = new GeoExt.data.PrintPage({
+ * printProvider: new GeoExt.data.PrintProvider({
+ * capabilities: printCapabilities
+ * })
+ * });
+ * new Ext.form.FormPanel({
+ * renderTo: "form",
+ * width: 200,
+ * height: 300,
+ * items: [{
+ * xtype: "combo",
+ * displayField: "name",
+ * store: printPage.scales, // printPage.scale
+ * fieldLabel: "Scale",
+ * typeAhead: true,
+ * mode: "local",
+ * forceSelection: true,
+ * triggerAction: "all",
+ * selectOnFocus: true,
+ * plugins: new GeoExt.plugins.PrintPageField({
+ * printPage: printPage
+ * })
+ * }, {
+ * xtype: "textfield",
+ * name: "rotation", // printPage.rotation
+ * fieldLabel: "Rotation",
+ * plugins: new GeoExt.plugins.PrintPageField({
+ * printPage: printPage
+ * })
+ * }, {
+ * xtype: "textfield",
+ * name: "mapTitle", // printPage.customParams["mapTitle"]
+ * fieldLabel: "Map Title",
+ * plugins: new GeoExt.plugins.PrintPageField({
+ * printPage: printPage
+ * })
+ * }]
+ * }):
+ */
+
/** api: constructor
* .. class:: PrintPageField
*
@@ -21,14 +68,15 @@
*/
GeoExt.plugins.PrintPageField = Ext.extend(Ext.util.Observable, {
- /** api: config[page]
+ /** api: config[printPage]
* ``GeoExt.data.PrintPage`` The print page to synchronize with.
*/
- /** private: property[page]
+ /** private: property[printPage]
* ``GeoExt.data.PrintPage`` The print page to synchronize with.
+ * Read-only.
*/
- page: null,
+ printPage: null,
/** private: property[target]
* ``Ext.form.Field`` This plugin's target field.
@@ -55,7 +103,7 @@
onCfg[target instanceof Ext.form.ComboBox ? "select" : "valid"] =
this.onFieldChange;
target.on(onCfg);
- this.page.on({
+ this.printPage.on({
"change": this.onPageChange,
scope: this
});
@@ -68,34 +116,34 @@
* Handler for the target field's "valid" or "select" event.
*/
onFieldChange: function(field, record) {
- var printProvider = this.page.printProvider;
+ var printProvider = this.printPage.printProvider;
var value = field.getValue();
this._updating = true;
if(field.store === printProvider.scales) {
- this.page.setScale(record);
+ this.printPage.setScale(record);
} else if(field.name == "rotation") {
- this.page.setRotation(value);
+ !isNaN(value) && this.printPage.setRotation(value);
} else {
- this.page.customParams[field.name] = value;
+ this.printPage.customParams[field.name] = value;
}
delete this._updating;
},
/** private: method[onPageChange]
- * :param page: :class:`GeoExt.data.PrintPage`
+ * :param printPage: :class:`GeoExt.data.PrintPage`
*
* Handler for the "change" event for the page this plugin is configured
* with.
*/
- onPageChange: function(page) {
+ onPageChange: function(printPage) {
if(!this._updating) {
var t = this.target;
t.suspendEvents();
- if(t.store === page.printProvider.scales) {
- t.setValue(page.scale.get(t.displayField));
+ if(t.store === printPage.printProvider.scales) {
+ t.setValue(printPage.scale.get(t.displayField));
} else if(t.name == "rotation") {
- t.setValue(page.rotation);
- t.setDisabled(!page.printProvider.layout.get("rotation"));
+ t.setValue(printPage.rotation);
+ t.setDisabled(!printPage.printProvider.layout.get("rotation"));
}
t.resumeEvents();
}
@@ -106,7 +154,7 @@
destroy: function() {
this.target.un("select", this.onFieldChange, this);
this.target.un("valid", this.onFieldChange, this);
- this.page.un("change", this.onPageChange, this);
+ this.printPage.un("change", this.onPageChange, this);
GeoExt.plugins.PrintPageField.superclass.destroy.apply(this, arguments);
}
Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintProviderField.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintProviderField.js 2010-01-19 15:56:33 UTC (rev 1783)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/plugins/PrintProviderField.js 2010-01-19 21:17:13 UTC (rev 1784)
@@ -7,6 +7,56 @@
*/
Ext.namespace("GeoExt.plugins");
+/** api: example
+ * A form with combo boxes for layout and resolution, and a text field for a
+ * map title. The latter is a custom parameter to the print module:
+ *
+ * .. code-block:: javascript
+ *
+ * var printProvider = new GeoExt.data.PrintProvider({
+ * capabilities: printCapabilities
+ * });
+ * new Ext.form.FormPanel({
+ * renderTo: "form",
+ * width: 200,
+ * height: 300,
+ * items: [{
+ * xtype: "combo",
+ * displayField: "name",
+ * store: printProvider.layouts, // printProvider.layout
+ * fieldLabel: "Layout",
+ * typeAhead: true,
+ * mode: "local",
+ * forceSelection: true,
+ * triggerAction: "all",
+ * selectOnFocus: true,
+ * plugins: new GeoExt.plugins.PrintProviderField({
+ * printProvider: printProvider
+ * })
+ * }, {
+ * xtype: "combo",
+ * displayField: "name",
+ * store: printProvider.dpis, // printProvider.dpi
+ * fieldLabel: "Resolution",
+ * typeAhead: true,
+ * mode: "local",
+ * forceSelection: true,
+ * triggerAction: "all",
+ * selectOnFocus: true,
+ * plugins: new GeoExt.plugins.PrintProviderField({
+ * printProvider: printProvider
+ * })
+ * }, {
+ * xtype: "textfield",
+ * name: "mapTitle", // printProvider.customParams.mapTitle
+ * fieldLabel: "Map Title",
+ * plugins: new GeoExt.plugins.PrintProviderField({
+ * printProvider: printProvider
+ * })
+ * }]
+ * }):
+ */
+
/** api: (define)
* module = GeoExt.plugins
* class = PrintProviderField
Modified: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html 2010-01-19 15:56:33 UTC (rev 1783)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html 2010-01-19 21:17:13 UTC (rev 1784)
@@ -72,6 +72,15 @@
t.ok(log.dpichange[1] == dpi, "dpi passed as 2nd argment of the dpichange listener.");
}
+ function test_getAbsoluteUrl(t) {
+ t.plan(2);
+
+ var getAbsoluteUrl = GeoExt.data.PrintProvider.prototype.getAbsoluteUrl;
+ var baseUrl = parent.location.href.substr(0, parent.location.href.indexOf("/tests/run-tests.html"));
+ t.eq(getAbsoluteUrl("/foo/bar.html"), location.protocol + "//" + location.host + (location.port && ":" + location.port) + "/foo/bar.html", "Relative url converted to absolute url correctly.");
+ t.eq(getAbsoluteUrl("../../../../bar.html"), baseUrl + "/bar.html", "Relative url with relative path converted to absolute url correctly.");
+ }
+
function test_print(t) {
t.plan(1);
var log = {};
@@ -133,7 +142,7 @@
var layerStore = new GeoExt.data.LayerStore({
layers: [layers[0], layers[1]]
});
- layerStore.getAt(1).set("legendURL", "../../../../resources/images/default/anchor.png");
+ layerStore.getAt(1).set("legendURL", "http://trac.geoext.org/chrome/site/img/GeoExt.png");
// a legend panel to test all legend encoders
var legend = new GeoExt.LegendPanel({
@@ -154,9 +163,7 @@
printProvider.print(map, [printPage], {legend: legend});
Ext.Ajax.request = origRequest;
- var baseUrl = parent.location.href.substr(0, parent.location.href.indexOf("/tests/run-tests.html"));
- var imgUrl = baseUrl + "/resources/images/default/anchor.png";
- var expect = {"units":"degrees","srs":"EPSG:4326","layout":"A4 portrait","dpi":75,"layers":[{"baseURL":"http://demo.opengeo.org/geoserver/wms","opacity":1,"singleTile":false,"type":"WMS","layers":["topp:tasmania_state_boundaries","topp:tasmania_water_bodies"],"format":"image/gif","styles":[""],"customParams":{"VENDORFOO":"bar"}},{"baseURL":"http://c0.labs.metacarta.com/wms-c/cache/","opacity":1,"singleTile":false,"type":"TileCache","layer":"basic","maxExtent":[-180,-90,180,90],"tileSize":[256,256],"extension":"png","resolutions":[0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125,0.000021457672119140625]},{"type":"Image","baseURL":"http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif","opacity":1,"extent":[-180,-88.759,180,88.759],"pixelSize":[580,288],"name":"image"},{"type":"Vector","styles":{"1":{"fillColor":"#ee9900","fillOpacity":0.4,"hoverFillColor":"white","hoverFillOpacity":0.8,"strokeColor":"#ee9900","strokeOpacity":1,"strokeWidth":1,"strokeLinecap":"round","strokeDashstyle":"solid","hoverStrokeColor":"red","hoverStrokeOpacity":1,"hoverStrokeWidth":0.2,"pointRadius":6,"hoverPointRadius":1,"hoverPointUnit":"%","pointerEvents":"visiblePainted","cursor":"inherit"}},"styleProperty":"_gx_style","geoJson":{"type":"FeatureCollection","features":[{"type":"Feature","id":"OpenLayers.Feature.Vector_72","properties":{"_gx_style":1},"geometry":{"type":"Point","coordinates":[1,2]}}]},"name":"vector","opacity":1}],"pages":[{"mapTitle":"foo","comment":"bar","center":[1,2],"scale":4000000,"rotation":0}],"customParam":"foo","legends":[{"name":"osm","classes":[{"name":"","icon":imgUrl}]},{"name":"wms","classes":[{"name":"","icons":["http://demo.opengeo.org/geoserver/wms?FORMAT=image%2Fgif&VENDORFOO=bar&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&LAYER=topp%3Atasmania_state_boundaries","http://demo.opengeo.org/geoserver/wms?FORMAT=image%2Fgif&VENDORFOO=bar&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&LAYER=topp%3Atasmania_water_bodies"]}]}]};
+ var expect = {"units":"degrees","srs":"EPSG:4326","layout":"A4 portrait","dpi":75,"layers":[{"baseURL":"http://demo.opengeo.org/geoserver/wms","opacity":1,"singleTile":false,"type":"WMS","layers":["topp:tasmania_state_boundaries","topp:tasmania_water_bodies"],"format":"image/gif","styles":[""],"customParams":{"VENDORFOO":"bar"}},{"baseURL":"http://c0.labs.metacarta.com/wms-c/cache/","opacity":1,"singleTile":false,"type":"TileCache","layer":"basic","maxExtent":[-180,-90,180,90],"tileSize":[256,256],"extension":"png","resolutions":[0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125,0.000021457672119140625]},{"type":"Image","baseURL":"http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif","opacity":1,"extent":[-180,-88.759,180,88.759],"pixelSize":[580,288],"name":"image"},{"type":"Vector","styles":{"1":{"fillColor":"#ee9900","fillOpacity":0.4,"hoverFillColor":"white","hoverFillOpacity":0.8,"strokeColor":"#ee9900","strokeOpacity":1,"strokeWidth":1,"strokeLinecap":"round","strokeDashstyle":"solid","hoverStrokeColor":"red","hoverStrokeOpacity":1,"hoverStrokeWidth":0.2,"pointRadius":6,"hoverPointRadius":1,"hoverPointUnit":"%","pointerEvents":"visiblePainted","cursor":"inherit"}},"styleProperty":"_gx_style","geoJson":{"type":"FeatureCollection","features":[{"type":"Feature","id":"OpenLayers.Feature.Vector_72","properties":{"_gx_style":1},"geometry":{"type":"Point","coordinates":[1,2]}}]},"name":"vector","opacity":1}],"pages":[{"mapTitle":"foo","comment":"bar","center":[1,2],"scale":4000000,"rotation":0}],"customParam":"foo","legends":[{"name":"osm","classes":[{"name":"","icon":"http://trac.geoext.org/chrome/site/img/GeoExt.png"}]},{"name":"wms","classes":[{"name":"","icons":["http://demo.opengeo.org/geoserver/wms?FORMAT=image%2Fgif&VENDORFOO=bar&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&LAYER=topp%3Atasmania_state_boundaries","http://demo.opengeo.org/geoserver/wms?FORMAT=image%2Fgif&VENDORFOO=bar&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&LAYER=topp%3Atasmania_water_bodies"]}]}]};
t.eq(log.request.jsonData, expect, "Request with encoded layers and legend is correct.");
Added: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintPageField.html 2010-01-19 21:17:13 UTC (rev 1784)
@@ -0,0 +1,114 @@
+<!DOCTYPE html>
+<html debug="true">
+ <head>
+ <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+ <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){
+ t.plan(1);
+
+ var log = {};
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ })
+ });
+ var plugin = new GeoExt.plugins.PrintPageField({
+ printPage: printPage
+ });
+
+ var field = {
+ on: function(cfg) {
+ log.on = cfg;
+ }
+ }
+ plugin.init(field);
+
+ t.ok(log.on["valid"] === plugin.onFieldChange, "onFieldChange handler set correctly.");
+ }
+
+ function test_onFieldChange(t) {
+ t.plan(2);
+
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ customParams: {foo: "bar"}
+ });
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: printProvider
+ });
+ var plugin = new GeoExt.plugins.PrintPageField({
+ printPage: printPage
+ });
+ var field = {
+ name: "foo",
+ initialConfig: {},
+ getValue: function() {
+ return "foobar";
+ }
+ }
+ plugin.onFieldChange(field);
+
+ t.eq(printPage.customParams.foo, "foobar", "Custom field value updated in printPage.");
+
+ delete field.name;
+ field.store = printProvider.scales;
+ field.displayField = "name";
+ plugin.onFieldChange(field, printProvider.scales.getAt(1));
+
+ t.eq(printPage.scale.get("name"), printProvider.scales.getAt(1).get("name"), "Scale value updated in printPage.");
+ }
+
+ function test_onPageChange(t) {
+ t.plan(3);
+
+ var log = {};
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ customParams: {foo: "bar"}
+ });
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: printProvider
+ });
+ var plugin = new GeoExt.plugins.PrintPageField({
+ printPage: printPage
+ });
+ var field = {
+ displayField: "name",
+ store: printProvider.scales,
+ initialConfig: {},
+ on: function(cfg) {
+ log.on = cfg;
+ },
+ getValue: function() {
+ return "foobar";
+ },
+ setValue: function(value) {
+ log.setValue = value;
+ },
+ suspendEvents: Ext.emptyFn,
+ resumeEvents: Ext.emptyFn
+ }
+ plugin.init(field);
+
+ printPage.setScale(printProvider.scales.getAt(1));
+ t.eq(log.setValue, printProvider.scales.getAt(1).get("name"), "Plugin updated scale name on printPage change.");
+
+ delete log.setValue;
+ plugin.onFieldChange(field, printProvider.scales.getAt(0));
+
+ t.ok(printPage.scale === printProvider.scales.getAt(0), "Scale set on field change.");
+ t.eq(log.setValue, undefined, "setValue not called while updating.");
+ }
+
+ </script>
+ </head>
+ <body>
+ <div id="form" style="width:400px; height:300px"></div>
+ </body>
+</html>
Added: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintProviderField.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintProviderField.html (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/plugins/PrintProviderField.html 2010-01-19 21:17:13 UTC (rev 1784)
@@ -0,0 +1,137 @@
+<!DOCTYPE html>
+<html debug="true">
+ <head>
+ <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+ <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){
+ t.plan(2);
+
+ var log = {};
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ });
+ var plugin = new GeoExt.plugins.PrintProviderField({
+ printProvider: printProvider
+ });
+
+ var field = {
+ on: function(cfg) {
+ log.on = cfg;
+ }
+ }
+ plugin.init(field);
+
+ t.ok(log.on["valid"] === plugin.onFieldChange, "onFieldChange handler set correctly.");
+ t.ok(log.on["render"] === plugin.onRender, "onRender handler set correctly.");
+ }
+
+ function test_render(t) {
+ t.plan(2);
+
+ var log = {};
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ customParams: {foo: "bar"}
+ });
+ var plugin = new GeoExt.plugins.PrintProviderField({
+ printProvider: printProvider
+ });
+
+ var field = {
+ name: "foo",
+ initialConfig: {},
+ setValue: function(value) {
+ log.setValue = value;
+ }
+ }
+ plugin.onRender(field);
+
+ t.eq(log.setValue, "bar", "Initial custom value set correctly on printProvider.");
+
+ delete field.name;
+ field.store = printProvider.layouts;
+ field.displayField = "name";
+ plugin.onRender(field);
+
+ t.eq(log.setValue, printProvider.layout.get(field.displayField), "Initial layout value set correctly on printProvider.");
+ }
+
+ function test_onFieldChange(t) {
+ t.plan(2);
+
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ customParams: {foo: "bar"}
+ });
+ var plugin = new GeoExt.plugins.PrintProviderField({
+ printProvider: printProvider
+ });
+ var field = {
+ name: "foo",
+ initialConfig: {},
+ getValue: function() {
+ return "foobar";
+ }
+ }
+ plugin.onFieldChange(field);
+
+ t.eq(printProvider.customParams.foo, "foobar", "Custom field value updated in printProvider.");
+
+ delete field.name;
+ field.store = printProvider.layouts;
+ field.displayField = "name";
+ plugin.onFieldChange(field, printProvider.layouts.getAt(1));
+
+ t.eq(printProvider.layout.get("name"), printProvider.layouts.getAt(1).get("name"), "Layout value updated in printProvider.");
+ }
+
+ function test_onProviderChange(t) {
+ t.plan(3);
+
+ var log = {};
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ customParams: {foo: "bar"}
+ });
+ var plugin = new GeoExt.plugins.PrintProviderField({
+ printProvider: printProvider
+ });
+ var field = {
+ displayField: "name",
+ store: printProvider.layouts,
+ initialConfig: {},
+ on: function(cfg) {
+ log.on = cfg;
+ },
+ getValue: function() {
+ return "foobar";
+ },
+ setValue: function(value) {
+ log.setValue = value;
+ }
+ }
+ plugin.init(field);
+ plugin.onRender(field);
+
+ printProvider.setLayout(printProvider.layouts.getAt(1));
+ t.eq(log.setValue, printProvider.layouts.getAt(1).get("name"), "Plugin updated layout name on printProvider change.");
+
+ delete log.setValue;
+ plugin.onFieldChange(field, printProvider.layouts.getAt(0));
+
+ t.ok(printProvider.layout === printProvider.layouts.getAt(0), "Layout set on field change.");
+ t.eq(log.setValue, undefined, "setValue not called while updating.");
+ }
+
+ </script>
+ </head>
+ <body>
+ <div id="form" style="width:400px; height:300px"></div>
+ </body>
+</html>
Modified: sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html 2010-01-19 15:56:33 UTC (rev 1783)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html 2010-01-19 21:17:13 UTC (rev 1784)
@@ -15,6 +15,8 @@
<li>lib/GeoExt/data/WMSCapabilitiesReader.html</li>
<li>lib/GeoExt/data/WMSDescribeLayerReader.html</li>
<li>lib/GeoExt/data/WMCReader.html</li>
+ <li>lib/GeoExt/plugins/PrintPageField.html</li>
+ <li>lib/GeoExt/plugins/PrintProviderField.html</li>
<li>lib/GeoExt/widgets/Action.html</li>
<li>lib/GeoExt/widgets/FeatureRenderer.html</li>
<li>lib/GeoExt/widgets/LayerOpacitySlider.html</li>
Modified: sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js 2010-01-19 15:56:33 UTC (rev 1783)
+++ sandbox/ahocevar/playground/ux/Printing/examples/SimplePrint.js 2010-01-19 21:17:13 UTC (rev 1784)
@@ -56,7 +56,7 @@
}, OpenLayers.Feature.Vector.style["default"]), {
context: {
getRotation: function(feature) {
- return printForm.page.rotation;
+ return printForm.printPage.rotation;
},
getStrokeColor: function(feature) {
return feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point" ?
@@ -91,7 +91,7 @@
fieldLabel: "Title",
value: "A custom title",
plugins: new GeoExt.plugins.PrintPageField({
- page: printForm.page
+ printPage: printForm.printPage
})
});
printForm.insert(1, {
@@ -100,7 +100,7 @@
name: "comment",
value: "A custom comment",
plugins: new GeoExt.plugins.PrintPageField({
- page: printForm.page
+ printPage: printForm.printPage
})
});
Modified: sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js 2010-01-19 15:56:33 UTC (rev 1783)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/form/SimplePrint.js 2010-01-19 21:17:13 UTC (rev 1784)
@@ -92,7 +92,7 @@
*/
printExtent: null,
- /** api: property[page]
+ /** api: property[printPage]
* :class:`GeoExt.data.PrintPage` The print page for this form. Useful
* e.g. for rotating handles when used in a style map context. Read-only.
*/
@@ -103,14 +103,14 @@
initComponent: function() {
GeoExt.ux.form.SimplePrint.superclass.initComponent.call(this);
- this.page = new GeoExt.data.PrintPage({
+ this.printPage = new GeoExt.data.PrintPage({
printProvider: this.initialConfig.printProvider
});
this.printExtent = new GeoExt.PrintExtent({
printProvider: this.initialConfig.printProvider,
layer: this.initialConfig.layer,
- pages: [this.page]
+ pages: [this.printPage]
});
this.mapPanel.add(this.printExtent);
@@ -179,7 +179,7 @@
triggerAction: "all",
selectOnFocus: true,
plugins: new GeoExt.plugins.PrintPageField({
- page: this.page
+ printPage: this.printPage
})
});
this.initialConfig.hideRotation !== true && this.add({
@@ -191,7 +191,7 @@
return !isNaN(v)
},
plugins: new GeoExt.plugins.PrintPageField({
- page: this.page
+ printPage: this.printPage
})
});
@@ -218,7 +218,7 @@
* Handler for the map's moveend event
*/
onMoveend: function() {
- this.page.fit(this.mapPanel.map);
+ this.printPage.fit(this.mapPanel.map);
},
/** private: method[beforeDestroy]
More information about the Commits
mailing list