allow protocols to be configured with a default filter, p=aabt, r=me (closes #2292)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9702 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -29,6 +29,12 @@ OpenLayers.Protocol = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
autoDestroy: true,
|
autoDestroy: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: defaultFilter
|
||||||
|
* {OpenLayers.Filter} Optional default filter to read requests
|
||||||
|
*/
|
||||||
|
defaultFilter: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Protocol
|
* Constructor: OpenLayers.Protocol
|
||||||
* Abstract class for vector protocols. Create instances of a subclass.
|
* Abstract class for vector protocols. Create instances of a subclass.
|
||||||
@@ -43,6 +49,28 @@ OpenLayers.Protocol = OpenLayers.Class({
|
|||||||
this.options = options;
|
this.options = options;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: mergeWithDefaultFilter
|
||||||
|
* Merge filter passed to the read method with the default one
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* filter - {OpenLayers.Filter}
|
||||||
|
*/
|
||||||
|
mergeWithDefaultFilter: function(filter) {
|
||||||
|
if(filter) {
|
||||||
|
if(this.defaultFilter) {
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.AND,
|
||||||
|
filters: [this.defaultFilter, filter]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter = this.defaultFilter;
|
||||||
|
}
|
||||||
|
return filter;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: destroy
|
* APIMethod: destroy
|
||||||
* Clean up the protocol.
|
* Clean up the protocol.
|
||||||
@@ -64,7 +92,9 @@ OpenLayers.Protocol = OpenLayers.Class({
|
|||||||
* object, the same object will be passed to the callback function passed
|
* object, the same object will be passed to the callback function passed
|
||||||
* if one exists in the options object.
|
* if one exists in the options object.
|
||||||
*/
|
*/
|
||||||
read: function() {
|
read: function(options) {
|
||||||
|
options = options || {};
|
||||||
|
options.filter = this.mergeWithDefaultFilter(options.filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
* is then populated with the the features received from the server.
|
* is then populated with the the features received from the server.
|
||||||
*/
|
*/
|
||||||
read: function(options) {
|
read: function(options) {
|
||||||
|
OpenLayers.Protocol.prototype.read.apply(this, arguments);
|
||||||
options = OpenLayers.Util.applyDefaults(options, this.options);
|
options = OpenLayers.Util.applyDefaults(options, this.options);
|
||||||
var readWithPOST = (options.readWithPOST !== undefined) ?
|
var readWithPOST = (options.readWithPOST !== undefined) ?
|
||||||
options.readWithPOST : this.readWithPOST;
|
options.readWithPOST : this.readWithPOST;
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ OpenLayers.Protocol.SQL.Gears = OpenLayers.Class(OpenLayers.Protocol.SQL, {
|
|||||||
* object.
|
* object.
|
||||||
*/
|
*/
|
||||||
read: function(options) {
|
read: function(options) {
|
||||||
|
OpenLayers.Protocol.prototype.read.apply(this, arguments);
|
||||||
options = OpenLayers.Util.applyDefaults(options, this.options);
|
options = OpenLayers.Util.applyDefaults(options, this.options);
|
||||||
|
|
||||||
var feature, features = [];
|
var feature, features = [];
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
* responses).
|
* responses).
|
||||||
*/
|
*/
|
||||||
read: function(options) {
|
read: function(options) {
|
||||||
|
OpenLayers.Protocol.prototype.read.apply(this, arguments);
|
||||||
options = OpenLayers.Util.extend({}, options);
|
options = OpenLayers.Util.extend({}, options);
|
||||||
OpenLayers.Util.applyDefaults(options, this.options || {});
|
OpenLayers.Util.applyDefaults(options, this.options || {});
|
||||||
var response = new OpenLayers.Protocol.Response({requestType: "read"});
|
var response = new OpenLayers.Protocol.Response({requestType: "read"});
|
||||||
|
|||||||
+21
-1
@@ -4,16 +4,36 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
function test_initialize(t) {
|
function test_initialize(t) {
|
||||||
t.plan(3);
|
t.plan(4);
|
||||||
var options = {};
|
var options = {};
|
||||||
var protocol = new OpenLayers.Protocol(options);
|
var protocol = new OpenLayers.Protocol(options);
|
||||||
|
|
||||||
t.ok(protocol instanceof OpenLayers.Protocol,
|
t.ok(protocol instanceof OpenLayers.Protocol,
|
||||||
"new OpenLayers.Protocol returns object" );
|
"new OpenLayers.Protocol returns object" );
|
||||||
t.eq(protocol.options, options, "constructor sets this.options");
|
t.eq(protocol.options, options, "constructor sets this.options");
|
||||||
|
t.eq(protocol.options.filter, null, "constructor sets defaultFilter to null");
|
||||||
t.eq(protocol.autoDestroy, true, "constructor does not modify this.autoDestroy");
|
t.eq(protocol.autoDestroy, true, "constructor does not modify this.autoDestroy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_read_defaultFilter(t) {
|
||||||
|
t.plan(3);
|
||||||
|
var defaultFilter = 'a';
|
||||||
|
var options = {
|
||||||
|
defaultFilter: defaultFilter
|
||||||
|
};
|
||||||
|
|
||||||
|
var protocol = new OpenLayers.Protocol(options);
|
||||||
|
var readFilter = 'b';
|
||||||
|
var options = { filter: readFilter };
|
||||||
|
|
||||||
|
protocol.read(options);
|
||||||
|
|
||||||
|
var filter = options.filter;
|
||||||
|
t.ok(filter instanceof OpenLayers.Filter.Logical, "read method merge default filter & options filter to a logical one");
|
||||||
|
t.eq(filter.type, OpenLayers.Filter.Logical.AND, "logical filter type is OpenLayers.Filter.Logical.AND");
|
||||||
|
t.eq(filter.filters, [defaultFilter, readFilter], "read method has merged filters");
|
||||||
|
}
|
||||||
|
|
||||||
function test_destroy(t) {
|
function test_destroy(t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
var protocol = new OpenLayers.Protocol({
|
var protocol = new OpenLayers.Protocol({
|
||||||
|
|||||||
Reference in New Issue
Block a user