[Commits] r1080 - in sandbox/camptocamp/geobretagne: examples lib/GeoExt lib/GeoExt/adapter tests tests/lib/GeoExt tests/lib/GeoExt/adapter

commits at geoext.org commits at geoext.org
Mon Jun 15 11:00:07 CEST 2009


Author: elemoine
Date: 2009-06-15 11:00:07 +0200 (Mon, 15 Jun 2009)
New Revision: 1080

Added:
   sandbox/camptocamp/geobretagne/lib/GeoExt/adapter/
   sandbox/camptocamp/geobretagne/lib/GeoExt/adapter/override-ext-ajax.js
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/adapter/
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/adapter/override-ext-ajax.html
Modified:
   sandbox/camptocamp/geobretagne/examples/wms-capabilities.html
   sandbox/camptocamp/geobretagne/tests/list-tests.html
Log:
applying patch-92-r1078-A0.diff from ticket #92


Modified: sandbox/camptocamp/geobretagne/examples/wms-capabilities.html
===================================================================
--- sandbox/camptocamp/geobretagne/examples/wms-capabilities.html	2009-06-15 08:49:30 UTC (rev 1079)
+++ sandbox/camptocamp/geobretagne/examples/wms-capabilities.html	2009-06-15 09:00:07 UTC (rev 1080)
@@ -2,9 +2,11 @@
     <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.com/deploy/dev/examples/shared/examples.css"></link>
+
+        <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-rc2/OpenLayers.js"></script>
         <script type="text/javascript" src="../lib/GeoExt.js"></script>
         

Added: sandbox/camptocamp/geobretagne/lib/GeoExt/adapter/override-ext-ajax.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/adapter/override-ext-ajax.js	                        (rev 0)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/adapter/override-ext-ajax.js	2009-06-15 09:00:07 UTC (rev 1080)
@@ -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: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/adapter/override-ext-ajax.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/adapter/override-ext-ajax.html	                        (rev 0)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/adapter/override-ext-ajax.html	2009-06-15 09:00:07 UTC (rev 1080)
@@ -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: sandbox/camptocamp/geobretagne/tests/list-tests.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/list-tests.html	2009-06-15 08:49:30 UTC (rev 1079)
+++ sandbox/camptocamp/geobretagne/tests/list-tests.html	2009-06-15 09:00:07 UTC (rev 1080)
@@ -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