[Commits] r2526 - in core/trunk/geoext: lib/GeoExt/data tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Mon Dec 13 12:28:50 CET 2010
Author: bartvde
Date: 2010-12-13 12:28:49 +0100 (Mon, 13 Dec 2010)
New Revision: 2526
Modified:
core/trunk/geoext/lib/GeoExt/data/PrintProvider.js
core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
Log:
add beforedownload event in PrintProvider, r=ahocevar (closes #388)
Modified: core/trunk/geoext/lib/GeoExt/data/PrintProvider.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-12-10 14:49:29 UTC (rev 2525)
+++ core/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-12-13 11:28:49 UTC (rev 2526)
@@ -218,6 +218,7 @@
/** api: event[beforeprint]
* Triggered when the print method is called.
+ * TODO: rename this event to beforeencode
*
* Listener arguments:
*
@@ -281,8 +282,22 @@
* * encodedLayer - ``Object`` the encoded layer that will be
* sent to the print service.
*/
- "encodelayer"
+ "encodelayer",
+ /** api: events[beforedownload]
+ * Triggered before the PDF is downloaded. By returning false from
+ * a listener, the default handling of the PDF can be cancelled
+ * and applications can take control over downloading the PDF.
+ * TODO: rename to beforeprint after the current beforeprint event
+ * has been renamed to beforeencode.
+ *
+ * Listener arguments:
+ * * printProvider - :class:`GeoExt.data.PrintProvider` this
+ * PrintProvider
+ * * url - ``String`` the url of the print document
+ */
+ "beforedownload"
+
);
GeoExt.data.PrintProvider.superclass.constructor.apply(this, arguments);
@@ -441,8 +456,7 @@
if(this.method === "GET") {
var url = Ext.urlAppend(this.capabilities.printURL,
"spec=" + encodeURIComponent(Ext.encode(jsonData)));
- window.open(url);
- this.fireEvent("print", this, url);
+ this.download(url);
} else {
Ext.Ajax.request({
url: this.capabilities.createURL,
@@ -453,15 +467,7 @@
// to security settings. So we'll display the pdf inline.
var url = Ext.decode(response.responseText).getURL +
(Ext.isIE ? "?inline=true" : "");
- if(Ext.isOpera || Ext.isIE) {
- // Make sure that Opera and IE don't replace the
- // content tab with the pdf
- window.open(url);
- } else {
- // This avoids popup blockers for all other browsers
- window.location.href = url;
- }
- this.fireEvent("print", this, url);
+ this.download(url);
},
failure: function(response) {
this.fireEvent("printexception", this, response);
@@ -472,6 +478,23 @@
}
},
+ /** private: method[download]
+ * :param url: ``String``
+ */
+ download: function(url) {
+ if (this.fireEvent("beforedownload", this, url) !== false) {
+ if (Ext.isOpera || Ext.isIE) {
+ // Make sure that Opera and IE don't replace the
+ // content tab with the pdf
+ window.open(url);
+ } else {
+ // This avoids popup blockers for all other browsers
+ window.location.href = url;
+ }
+ }
+ this.fireEvent("print", this, url);
+ },
+
/** api: method[loadCapabilities]
*
* Loads the capabilities from the print service. If this instance is
Modified: core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html 2010-12-10 14:49:29 UTC (rev 2525)
+++ core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html 2010-12-13 11:28:49 UTC (rev 2526)
@@ -115,7 +115,8 @@
map_resolution: 150
}, encodedLayer.customParams);
}
- }
+ },
+ "beforedownload": OpenLayers.Function.False
}
});
var printPage = new GeoExt.data.PrintPage({
@@ -195,11 +196,17 @@
var origRequest = Ext.Ajax.request;
Ext.Ajax.request = function(req) {
log.request = req;
+ var _isIE = Ext.isIE;
var _open = window.open;
- window.open = Ext.emptyFn;
+ // fake Ext.isIE so we will get window.open in all browsers
+ Ext.isIE = true;
+ window.open = function() {
+ t.fail("window open should not be called since beforedownload returns false");
+ }
req.success.call(req.scope, {
responseText: '{"getURL":"foo"}'
});
+ Ext.isIE = _isIE;
window.open = _open;
}
printProvider.print(map, [printPage], {overview: overview, legend: legend});
More information about the Commits
mailing list