[Commits] r1340 - in core/trunk/geoext: lib/GeoExt/widgets/form tests/lib/GeoExt/widgets/form

commits at geoext.org commits at geoext.org
Thu Aug 27 09:03:53 CEST 2009


Author: pgiraud
Date: 2009-08-27 09:03:53 +0200 (Thu, 27 Aug 2009)
New Revision: 1340

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/form/BasicForm.js
   core/trunk/geoext/lib/GeoExt/widgets/form/SearchAction.js
   core/trunk/geoext/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/trunk/geoext/lib/GeoExt/widgets/form/BasicForm.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/form/BasicForm.js	2009-08-27 07:00:12 UTC (rev 1339)
+++ core/trunk/geoext/lib/GeoExt/widgets/form/BasicForm.js	2009-08-27 07:03:53 UTC (rev 1340)
@@ -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/trunk/geoext/lib/GeoExt/widgets/form/SearchAction.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/form/SearchAction.js	2009-08-27 07:00:12 UTC (rev 1339)
+++ core/trunk/geoext/lib/GeoExt/widgets/form/SearchAction.js	2009-08-27 07:03:53 UTC (rev 1340)
@@ -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/trunk/geoext/tests/lib/GeoExt/widgets/form/SearchAction.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/form/SearchAction.html	2009-08-27 07:00:12 UTC (rev 1339)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/form/SearchAction.html	2009-08-27 07:03:53 UTC (rev 1340)
@@ -63,8 +63,69 @@
         /*
          * Test
          */
-       action.run();
+
+        action.run();
+
+        /*
+         * Tear down
+         */
+
+        form.destroy();
     }
+
+    function test_abort(t) {
+        t.plan(2);
+
+        /*
+         * Set up
+         */
+
+        var field, form, action, protocol, log = {};
+
+        var field = new Ext.form.TextField({
+            name: "foo__eq",
+            value: "bar"
+        });
+
+        form = new Ext.form.FormPanel({
+            renderTo: "form",
+            items: [field]
+        });
+
+        protocol = new OpenLayers.Protocol({
+            read: function(options) {
+                return "something";
+            },
+            abort: function() {
+                log.abort++;
+            }
+        });
+
+        action = new GeoExt.form.SearchAction(form.getForm(), {
+            protocol: protocol,
+            clientValidation: false,
+            abortPrevious: true
+        });
+
+        /*
+         * Test
+         */
+
+        log.abort = 0;
+        action.run();
+        action.run();
+        t.ok(log.abort == 1, "protocol abort called once");
+
+        log.abort = 0;
+        action.options.abortPrevious = false;
+        action.run();
+        t.ok(log.abort == 0, "protocol abort not called");
+
+        /*
+         * Tear down
+         */
+        form.destroy();
+    }
     </script>
   <body>
     <div id="form"></div>



More information about the Commits mailing list