~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Filter/Logical.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
 
2
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 
3
  * full text of the license. */
 
4
 
 
5
 
 
6
/**
 
7
 * @requires OpenLayers/Filter.js
 
8
 */
 
9
 
 
10
/**
 
11
 * Class: OpenLayers.Filter.Logical
 
12
 * This class represents ogc:And, ogc:Or and ogc:Not rules.
 
13
 * 
 
14
 * Inherits from
 
15
 * - <OpenLayers.Filter>
 
16
 */
 
17
OpenLayers.Filter.Logical = OpenLayers.Class(OpenLayers.Filter, {
 
18
 
 
19
    /**
 
20
     * APIProperty: filters
 
21
     * {Array(<OpenLayers.Filter>)} Child filters for this filter.
 
22
     */
 
23
    filters: null, 
 
24
     
 
25
    /**
 
26
     * APIProperty: type
 
27
     * {String} type of logical operator. Available types are:
 
28
     * - OpenLayers.Filter.Locical.AND = "&&";
 
29
     * - OpenLayers.Filter.Logical.OR  = "||";
 
30
     * - OpenLayers.Filter.Logical.NOT = "!";
 
31
     */
 
32
    type: null,
 
33
 
 
34
    /** 
 
35
     * Constructor: OpenLayers.Filter.Logical
 
36
     * Creates a logical filter (And, Or, Not).
 
37
     *
 
38
     * Parameters:
 
39
     * options - {Object} An optional object with properties to set on the
 
40
     *     filter.
 
41
     * 
 
42
     * Returns:
 
43
     * {<OpenLayers.Filter.Logical>}
 
44
     */
 
45
    initialize: function(options) {
 
46
        this.filters = [];
 
47
        OpenLayers.Filter.prototype.initialize.apply(this, [options]);
 
48
    },
 
49
    
 
50
    /** 
 
51
     * APIMethod: destroy
 
52
     * Remove reference to child filters.
 
53
     */
 
54
    destroy: function() {
 
55
        this.filters = null;
 
56
        OpenLayers.Filter.prototype.destroy.apply(this);
 
57
    },
 
58
 
 
59
    /**
 
60
     * APIMethod: evaluate
 
61
     * Evaluates this filter in a specific context.  Should be implemented by
 
62
     *     subclasses.
 
63
     * 
 
64
     * Parameters:
 
65
     * context - {Object} Context to use in evaluating the filter.
 
66
     * 
 
67
     * Returns:
 
68
     * {Boolean} The filter applies.
 
69
     */
 
70
    evaluate: function(context) {
 
71
        switch(this.type) {
 
72
            case OpenLayers.Filter.Logical.AND:
 
73
                for (var i=0, len=this.filters.length; i<len; i++) {
 
74
                    if (this.filters[i].evaluate(context) == false) {
 
75
                        return false;
 
76
                    }
 
77
                }
 
78
                return true;
 
79
                
 
80
            case OpenLayers.Filter.Logical.OR:
 
81
                for (var i=0, len=this.filters.length; i<len; i++) {
 
82
                    if (this.filters[i].evaluate(context) == true) {
 
83
                        return true;
 
84
                    }
 
85
                }
 
86
                return false;
 
87
            
 
88
            case OpenLayers.Filter.Logical.NOT:
 
89
                return (!this.filters[0].evaluate(context));
 
90
        }
 
91
    },
 
92
    
 
93
    CLASS_NAME: "OpenLayers.Filter.Logical"
 
94
});
 
95
 
 
96
 
 
97
OpenLayers.Filter.Logical.AND = "&&";
 
98
OpenLayers.Filter.Logical.OR  = "||";
 
99
OpenLayers.Filter.Logical.NOT = "!";