[Commits] r1259 - in core/trunk/geoext: examples lib/GeoExt lib/GeoExt/adapter tests tests/lib/GeoExt tests/lib/GeoExt/adapter
commits at geoext.org
commits at geoext.org
Wed Jul 15 10:49:15 CEST 2009
Author: elemoine
Date: 2009-07-15 10:49:15 +0200 (Wed, 15 Jul 2009)
New Revision: 1259
Added:
core/trunk/geoext/lib/GeoExt/adapter/
core/trunk/geoext/lib/GeoExt/adapter/override-ext-ajax.js
core/trunk/geoext/tests/lib/GeoExt/adapter/
core/trunk/geoext/tests/lib/GeoExt/adapter/override-ext-ajax.html
Modified:
core/trunk/geoext/examples/wms-capabilities.html
core/trunk/geoext/tests/list-tests.html
Log:
An Ext.lib.Ajax adapter making every Ajax request initiated by Ext objects go through OpenLayers' Ajax system, useful when Ajax request needs to go through a proxy (OpenLayers.ProxyHost) and to handle Ajax errors in just one place, r=ahocevar (closes #92)
Modified: core/trunk/geoext/examples/wms-capabilities.html
===================================================================
--- core/trunk/geoext/examples/wms-capabilities.html 2009-07-14 23:10:40 UTC (rev 1258)
+++ core/trunk/geoext/examples/wms-capabilities.html 2009-07-15 08:49:15 UTC (rev 1259)
@@ -2,9 +2,10 @@
<head>
<title>GeoExt WMS Capabilities Example</title>
- <script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.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 type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt/adapter/override-ext-ajax.js"></script>
<script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
<script type="text/javascript" src="../lib/GeoExt.js"></script>
Added: core/trunk/geoext/lib/GeoExt/adapter/override-ext-ajax.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/adapter/override-ext-ajax.js (rev 0)
+++ core/trunk/geoext/lib/GeoExt/adapter/override-ext-ajax.js 2009-07-15 08:49:15 UTC (rev 1259)
@@ -0,0 +1,80 @@
+/**
+ * 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: (define)
+ * module = Ext.lib.Ajax
+ */
+
+(function() {
+
+ /** private: function[createComplete]
+ * ``Function``
+ */
+ var createComplete = function(fn, cb) {
+ return function(request) {
+ if(cb && cb[fn]) {
+ cb[fn].call(cb.scope || window, {
+ responseText: request.responseText,
+ responseXML: request.responseXML,
+ argument: cb.argument
+ });
+ }
+ };
+ };
+
+ Ext.apply(Ext.lib.Ajax, {
+ /** private: method[request]
+ */
+ request: function(method, uri, cb, data, options) {
+ options = options || {};
+ var hs = options.headers;
+ if(options.xmlData) {
+ if(!hs || !hs["Content-Type"]) {
+ hs = hs || {};
+ hs["Content-Type"] = "text/xml";
+ }
+ method = (method ? method :
+ (options.method ? options.method : "POST"));
+ data = options.xmlData;
+ } else if(options.jsonData) {
+ if(!hs || !hs["Content-Type"]) {
+ hs = hs || {};
+ hs["Content-Type"] = "application/json";
+ }
+ method = (method ? method :
+ (options.method ? options.method : "POST"));
+ data = typeof options.jsonData == "object" ?
+ Ext.encode(options.jsonData) : options.jsonData;
+ }
+ return OpenLayers.Request.issue({
+ success: createComplete("success", cb),
+ failure: createComplete("failure", cb),
+ headers: options.headers,
+ method: method,
+ headers: hs,
+ data: data,
+ url: uri
+ });
+ },
+
+ /** private: method[isCallInProgress]
+ * :params request: ``Object`` The XHR object.
+ */
+ isCallInProgress: function(request) {
+ // do not prevent our caller from calling abort()
+ return true;
+ },
+
+ /** private: method[abort]
+ * :params request: ``Object`` The XHR object.
+ */
+ abort: function(request) {
+ request.abort();
+ }
+ });
+})();
Added: core/trunk/geoext/tests/lib/GeoExt/adapter/override-ext-ajax.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/adapter/override-ext-ajax.html (rev 0)
+++ core/trunk/geoext/tests/lib/GeoExt/adapter/override-ext-ajax.html 2009-07-15 08:49:15 UTC (rev 1259)
@@ -0,0 +1,168 @@
+<!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/adapter/override-ext-ajax.js"></script>
+ <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+ <script type="text/javascript">
+ function setup() {
+ window._xhr = OpenLayers.Request.XMLHttpRequest;
+ var anon = new Function();
+ OpenLayers.Request.XMLHttpRequest = function() {};
+ OpenLayers.Request.XMLHttpRequest.prototype = {
+ open: anon,
+ setRequestHeader: anon,
+ send: anon
+ };
+ OpenLayers.Request.XMLHttpRequest.DONE = 4;
+ }
+
+ function teardown() {
+ OpenLayers.Request.XMLHttpRequest = window._xhr;
+ }
+
+ function test_request(t) {
+ t.plan(7);
+
+ /*
+ * Setup
+ */
+
+ setup();
+
+ var _srh;
+ var proto = OpenLayers.Request.XMLHttpRequest.prototype;
+
+ var request, data;
+
+ var argument= {"some": "argument"};
+ var scope = {"some": "scope"};
+ var headers = {"some": "headers"};
+
+ var successObj, failureObj;
+ var success = function(o) {
+ successObj = {scope: this, arg: o.argument};
+ };
+ var failure = function(o) {
+ failureObj = {scope: this, arg: o.argument};
+ };
+
+ /*
+ * Test
+ */
+
+ // test "success" callback
+ // 3 tests
+ data = "some data";
+ successObj = failureObj = null;
+ _srh = proto.setRequestHeader;
+ proto.setRequestHeader = function(k, v) {
+ t.ok(k == "some" && v == "headers",
+ "headers properly set");
+ };
+ request = Ext.lib.Ajax.request("GET", "http://foo",
+ {
+ success: success,
+ failure: failure,
+ argument: argument,
+ scope: scope
+ },
+ data,
+ {
+ headers: headers
+ }
+ );
+ request.readyState = OpenLayers.Request.XMLHttpRequest.DONE;
+ request.status = 200;
+ request.onreadystatechange();
+ t.eq(successObj.scope, scope,
+ "success cb called with proper scope");
+ t.eq(successObj.arg, argument,
+ "success cb called with proper argument");
+ proto.setRequestHeader = _srh;
+
+ // test "failure" callback
+ // 2 tests
+ data = "some data";
+ successObj = failureObj = null;
+ request = Ext.lib.Ajax.request("GET", "http://foo",
+ {
+ success: success,
+ failure: failure,
+ argument: argument,
+ scope: scope
+ },
+ data,
+ {
+ headers: headers
+ }
+ );
+ request.readyState = OpenLayers.Request.XMLHttpRequest.DONE;
+ request.status = 400;
+ request.onreadystatechange();
+ t.eq(failureObj.scope, scope,
+ "failure cb called with proper scope");
+ t.eq(failureObj.arg, argument,
+ "failure cb called with proper argument");
+
+ // test xmlData
+ // 1 test
+ data = "some data";
+ _srh = proto.setRequestHeader;
+ proto.setRequestHeader = function(k, v) {
+ t.ok(k == "Content-Type" && v == "text/xml",
+ "Content-Type header properly set");
+ };
+ request = Ext.lib.Ajax.request("GET", "http://foo",
+ {
+ },
+ null,
+ {
+ xmlData: data
+ }
+ );
+ proto.setRequestHeader = _srh;
+
+ // test jsonData
+ // 1 test
+ data = "some data";
+ _srh = proto.setRequestHeader;
+ proto.setRequestHeader = function(k, v) {
+ t.ok(k == "Content-Type" && v == "application/json",
+ "Content-Type header properly set");
+ };
+ request = Ext.lib.Ajax.request("GET", "http://foo",
+ {
+ },
+ null,
+ {
+ jsonData: data
+ }
+ );
+ proto.setRequestHeader = _srh;
+
+ /*
+ * Teardown
+ */
+ teardown();
+ }
+
+ function test_serializeForm(t) {
+ t.plan(1);
+
+ var expect = "key1=val1&key2=val2";
+ var result = Ext.lib.Ajax.serializeForm(Ext.get("form").dom);
+ t.eq(result, expect,
+ "serializeForm returns expected result (" + expect + ")");
+ }
+ </script>
+ <body>
+ <form id="form">
+ <input type="text" name="key1" value="val1"></input>
+ <input type="checkbox" name="key2" value="val2" checked="checked"></input>
+ </form>
+ </body>
+</html>
Modified: core/trunk/geoext/tests/list-tests.html
===================================================================
--- core/trunk/geoext/tests/list-tests.html 2009-07-14 23:10:40 UTC (rev 1258)
+++ core/trunk/geoext/tests/list-tests.html 2009-07-15 08:49:15 UTC (rev 1259)
@@ -1,4 +1,5 @@
<ul id="testlist">
+ <li>lib/GeoExt/adapter/override-ext-ajax.html</li>
<li>lib/GeoExt/data/FeatureRecord.html</li>
<li>lib/GeoExt/data/FeatureReader.html</li>
<li>lib/GeoExt/data/FeatureStore.html</li>
More information about the Commits
mailing list