2
* Copyright (C) 2007 Camptocamp
4
* This file is part of MapFish Client
6
* MapFish Client is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* MapFish Client is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with MapFish Client. If not, see <http://www.gnu.org/licenses/>.
21
* @requires OpenLayers/Util.js
22
* @requires OpenLayers/Protocol.js
23
* @requires core/Searcher.js
27
* Class: mapfish.Protocol.MergeFilterDecorator
28
* Instances of this class decorate a protocol by merging filters provided
29
* by searchers before invoking the decorated protocol's read method.
32
* - <OpenLayers.Protocol>
35
mapfish.Protocol.MergeFilterDecorator = OpenLayers.Class(OpenLayers.Protocol, {
38
* Array({<mapfish.Searcher>} Array of searchers from which the merge
39
* filter decorator gets filters.
44
* APIProperty: protocol
45
* {<OpenLayers.Protocol>} The decorated protocol.
50
* Constructor: mapfish.Protocol.MergeFilterDecorator
55
initialize: function(options) {
57
OpenLayers.Protocol.prototype.initialize.call(this, options);
62
* Register a searcher.
64
register: function(searcher) {
65
this.searchers.push(searcher);
69
* APIMethod: unregister
70
* Unregister a searcher.
72
unregister: function(searcher) {
73
OpenLayers.Util.removeItem(searcher, this.searchers);
78
* Create features, this method does nothing more than calling
79
* the decorator protocol's create method.
82
* features - {Array({<OpenLayers.Feature.Vector>})} or
83
* {<OpenLayers.Feature.Vector>}
84
* options - {Object} Optional object for configuring the request.
85
* This object is modified and should not be reused.
88
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
89
* object, this object is also passed to the callback function when
90
* the request completes.
92
"create": function(features, options) {
93
return this.protocol.create(features, options);
98
* Merge filters provided by searchers, and call the decorated
99
* protocol's read method, passing it the merged filter.
102
* options - {Object} Optional object for configuring the request.
103
* This object is modified and should not be reused.
106
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
107
* object, this object is also passed to the callback function when
108
* the request completes.
110
"read": function(options) {
111
options.filter = this.mergeFilters(
112
options.filter || options.params, options.searcher);
113
delete options.searcher;
114
return this.protocol.read(options);
118
* Method: mergeFilters
119
* Merge filters provided by searchers.
122
* filter - {<OpenLayers.Filter>}|{Object}
123
* searcher - {<mapfish.Searcher>}
126
* {<OpenLayers.Filter>} The resulting filter.
128
mergeFilters: function(filter, searcher) {
130
for (i = 0, len = this.searchers.length; i < len; i++) {
131
s = this.searchers[i];
133
filter = this.toFilter(s.getFilter(), filter);
144
* filter - {<OpenLayers.Filter>}
147
* {<OpenLayers.Filter.Logical>}
149
toFilter: function(obj, filter) {
154
filter = new OpenLayers.Filter.Logical({
155
type: OpenLayers.Filter.Logical.AND
157
} else if (!this.isFilter(filter)) {
158
filter = this.fromObjToFilter(filter);
159
} else if (!this.isLogicalFilter(filter)) {
160
filter = new OpenLayers.Filter.Logical({
161
type: OpenLayers.Filter.Logical.AND,
165
var filters = filter.filters;
166
if (this.isFilter(obj)) {
169
filters.push(this.fromObjToFilter(obj));
175
* Method: fromObjToFilter
181
* {<OpenLayers.Filter.Logical>}
183
fromObjToFilter: function(obj) {
185
for (var key in obj) {
187
new OpenLayers.Filter.Comparison({
188
type: OpenLayers.Filter.Comparison.EQUAL_TO,
194
return new OpenLayers.Filter.Logical({
195
type: OpenLayers.Filter.Logical.AND,
201
* Method: isLogicalFilter
202
* Check if the object passed is a <OpenLayers.Filter.Logical> object.
210
isLogicalFilter: function(obj) {
211
return !!obj.CLASS_NAME &&
212
!!obj.CLASS_NAME.match(/^OpenLayers\.Filter\.Logical/);
217
* Check if the object passed is a <OpenLayers.Filter> object.
225
isFilter: function(obj) {
226
return !!obj.CLASS_NAME &&
227
!!obj.CLASS_NAME.match(/^OpenLayers\.Filter/);
232
* Update features, this method does nothing more than calling
233
* the decorator protocol's update method.
236
* features - {Array({<OpenLayers.Feature.Vector>})} or
237
* {<OpenLayers.Feature.Vector>}
238
* options - {Object} Optional object for configuring the request.
239
* This object is modified and should not be reused.
242
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
243
* object, this object is also passed to the callback function when
244
* the request completes.
246
"update": function(features, options) {
247
return this.protocol.update(features, options);
252
* Delete features, this method does nothing more than calling
253
* the decorator protocol's delete method.
256
* features - {Array({<OpenLayers.Feature.Vector>})} or
257
* {<OpenLayers.Feature.Vector>}
258
* options - {Object} Optional object for configuring the request.
259
* This object is modified and should not be reused.
262
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
263
* object, this object is also passed to the callback function when
264
* the request completes.
266
"delete": function(features, options) {
267
return this.protocol["delete"](features, options);
272
* Commit created, updated and deleted features, this method does nothing
273
* more than calling the decorated protocol's commit method.
276
* features - {Array({<OpenLayers.Feature.Vector>})}
277
* options - {Object} Object whose possible keys are "create", "update",
278
* "delete", "callback" and "scope", the values referenced by the
279
* first three are objects as passed to the "create", "update", and
280
* "delete" methods, the value referenced by the "callback" key is
281
* a function which is called when the commit operation is complete
282
* using the scope referenced by the "scope" key.
285
* {Array({<OpenLayers.Protocol.Response>})} An array of
286
* <OpenLayers.Protocol.Response> objects.
288
commit: function(features, options) {
289
return this.protocol.commit(features, options);
292
CLASS_NAME: "mapfish.Protocol.MergeFilterDecorator"