diff --git a/lib/OpenLayers/Protocol.js b/lib/OpenLayers/Protocol.js index 926df4fd9d..a2d30b4c4c 100755 --- a/lib/OpenLayers/Protocol.js +++ b/lib/OpenLayers/Protocol.js @@ -139,6 +139,16 @@ OpenLayers.Protocol = OpenLayers.Class({ */ commit: function() { }, + + /** + * Method: abort + * Abort an ongoing request. + * + * Parameters: + * response - {} + */ + abort: function(response) { + }, CLASS_NAME: "OpenLayers.Protocol" }); diff --git a/lib/OpenLayers/Protocol/HTTP.js b/lib/OpenLayers/Protocol/HTTP.js index 515bcb4a23..47a7d1bea9 100644 --- a/lib/OpenLayers/Protocol/HTTP.js +++ b/lib/OpenLayers/Protocol/HTTP.js @@ -441,6 +441,21 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { return resp; }, + /** + * Method: abort + * Abort an ongoing request, the response object passed to + * this method must come from this HTTP protocol (as a result + * of a create, read, update, delete or commit operation). + * + * Parameters: + * response - {} + */ + abort: function(response) { + if (response) { + response.priv.abort(); + } + }, + /** * Method: callUserCallback * This method is used from within the commit method each time an diff --git a/lib/OpenLayers/Strategy/BBOX.js b/lib/OpenLayers/Strategy/BBOX.js index f37fd0154d..fc88fe7bd3 100644 --- a/lib/OpenLayers/Strategy/BBOX.js +++ b/lib/OpenLayers/Strategy/BBOX.js @@ -157,13 +157,9 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { * returned by the layer protocol. */ triggerRead: function() { - var filter = this.createFilter(); - if (this.response && this.response.priv && - typeof this.response.priv.abort == "function") { - this.response.priv.abort(); - } + this.layer.protocol.abort(this.response); this.response = this.layer.protocol.read({ - filter: filter, + filter: this.createFilter(), callback: this.merge, scope: this }); diff --git a/tests/Strategy/BBOX.html b/tests/Strategy/BBOX.html index bb019de260..a7f159a1ab 100644 --- a/tests/Strategy/BBOX.html +++ b/tests/Strategy/BBOX.html @@ -76,7 +76,7 @@ } function test_triggerRead(t) { - t.plan(7); + t.plan(4); var s = new OpenLayers.Strategy.BBOX(); @@ -85,32 +85,26 @@ s.createFilter = function() { return filter; }; + s.response = {"fake": "response"}; - s.setLayer({ - protocol: { - read: function(options) { - t.ok(options.filter == filter, - "protocol read called with correct filter"); - t.ok(options.callback == s.merge, - "protocol read called with correct callback"); - t.ok(options.scope == s, - "protocol read called with correct scope"); - } + var protocol = new OpenLayers.Protocol({ + read: function(options) { + t.ok(options.filter == filter, + "protocol read called with correct filter"); + t.ok(options.callback == s.merge, + "protocol read called with correct callback"); + t.ok(options.scope == s, + "protocol read called with correct scope"); + }, + abort: function(response) { + t.eq(response, s.response, + "protocol abort called with correct response"); } }); - // 3 tests - s.triggerRead(); + s.setLayer({protocol: protocol}); // 4 tests - s.response = { - priv: { - abort: function() { - t.ok(true, - "triggerRead aborts previous read request"); - } - } - }; s.triggerRead(); }