[Commits] r1338 - in core/tags/geoext/release-0.5: lib/GeoExt/widgets/form tests/lib/GeoExt/widgets/form

commits at geoext.org commits at geoext.org
Wed Aug 26 16:30:32 CEST 2009


Author: pgiraud
Date: 2009-08-26 16:30:31 +0200 (Wed, 26 Aug 2009)
New Revision: 1338

Modified:
   core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/BasicForm.js
   core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/SearchAction.js
   core/tags/geoext/release-0.5/tests/lib/GeoExt/widgets/form/SearchAction.html
Log:
add the ability for SearchAction to abort pending request, patches from fredj,elemoine and pgiraud, r=elemoine (Closes #146)


Modified: core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/BasicForm.js
===================================================================
--- core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/BasicForm.js	2009-08-25 22:20:05 UTC (rev 1337)
+++ core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/BasicForm.js	2009-08-26 14:30:31 UTC (rev 1338)
@@ -35,6 +35,20 @@
      */
     protocol: null,
 
+    /**
+     * private: property[prevResponse]
+     * ``OpenLayers.Protocol.Response`` The response return by a call to
+     *  protocol.read method.
+     */
+    prevResponse: null,
+
+    /**
+     * api: config[autoAbort]
+     * ``Boolean`` Tells if pending requests should be aborted
+     *      when a new action is performed.
+     */
+    autoAbort: true,
+
     /** api: method[doAction]
      *  :param action: ``String or Ext.form.Action`` Either the name
      *      of the action or a ``Ext.form.Action`` instance.
@@ -47,7 +61,10 @@
      */
     doAction: function(action, options) {
         if(action == "search") {
-            options = Ext.applyIf(options || {}, {protocol: this.protocol});
+            options = Ext.applyIf(options || {}, {
+                protocol: this.protocol,
+                abortPrevious: this.autoAbort
+            });
             action = new GeoExt.form.SearchAction(this, options);
         }
         return GeoExt.form.BasicForm.superclass.doAction.call(

Modified: core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/SearchAction.js
===================================================================
--- core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/SearchAction.js	2009-08-25 22:20:05 UTC (rev 1337)
+++ core/tags/geoext/release-0.5/lib/GeoExt/widgets/form/SearchAction.js	2009-08-26 14:30:31 UTC (rev 1338)
@@ -41,7 +41,8 @@
  *              url: "http://publicus.opengeo.org/geoserver/wfs",
  *              featureType: "tasmania_roads",
  *              featureNS: "http://www.openplans.org/topp"
- *          })
+ *          }),
+ *          abortPrevious: true
  *      });
  *
  *      formPanel.getForm().doAction(searchAction, {
@@ -62,6 +63,9 @@
  *
  *      * form ``Ext.form.BasicForm`` A basic form instance.
  *      * options ``Object`` Options passed to the protocol'read method
+ *            One can add an abortPrevious property to these options, if set
+ *            to true, the abort method will be called on the protocol if
+ *            there's a pending request.
  *
  *      When run this action builds an ``OpenLayers.Filter`` from the form
  *      and passes this filter to its protocol's read method. The form fields
@@ -110,13 +114,19 @@
         var o = this.options;
         var f = GeoExt.form.toFilter(this.form);
         if(o.clientValidation === false || this.form.isValid()){
-            this.response = o.protocol.read(
+
+            if (o.abortPrevious && this.form.prevResponse) {
+                o.protocol.abort(this.form.prevResponse);
+            }
+
+            this.form.prevResponse = o.protocol.read(
                 Ext.applyIf({
                     filter: f,
                     callback: this.handleResponse,
                     scope: this
                 }, o)
             );
+
         } else if(o.clientValidation !== false){
             // client validation failed
             this.failureType = Ext.form.Action.CLIENT_INVALID;
@@ -131,6 +141,7 @@
      *  Handle the response to the search query.
      */
     handleResponse: function(response) {
+        this.form.prevResponse = null;
         this.response = response;
         if(response.success()) {
             this.form.afterAction(this, true);

Modified: core/tags/geoext/release-0.5/tests/lib/GeoExt/widgets/form/SearchAction.html
===================================================================
--- core/tags/geoext/release-0.5/tests/lib/GeoExt/widgets/form/SearchAction.html	2009-08-25 22:20:05 UTC (rev 1337)
+++ core/tags/geoext/release-0.5/tests/lib/GeoExt/widgets/form/SearchAction.html	2009-08-26 14:30:31 UTC (rev 1338)
@@ -30,13 +30,13 @@
     }
 
     function test_run(t) {
-        t.plan(1);
+        t.plan(2);
 
         /*
          * Set up
          */
 
-        var field, form, action, protocol;
+        var field, form, action, protocol, log = {};
 
         var field = new Ext.form.TextField({
             name: "foo__eq",
@@ -63,7 +63,42 @@
         /*
          * Test
          */
-       action.run();
+        action.run();
+
+        /**
+         * Set up for abortion test
+         */
+        log.abort = 0;
+        
+        protocol = {
+            read: function(options) {
+                return "something";
+            },
+            abort: function(response) {
+                log.abort++;
+            }
+        };
+        
+        action = new GeoExt.form.SearchAction(form.getForm(), {
+            protocol: protocol,
+            abortPrevious: true,
+            clientValidation: false
+        });
+
+        /*
+         * Test
+         */
+        action.run();
+
+        action.run();
+
+        t.wait_result(0.2);
+
+        action.options.abortPrevious = false;
+        action.run();
+        
+        t.wait_result(0.2);
+        t.ok(log.abort == 1, "protocol abort is correctly called and only once");
     }
     </script>
   <body>



More information about the Commits mailing list