1 // Factory function for sets of filters.
2 function filterSet(team) {
8 that.toJSON = function() {
9 return $.toJSON(m_list);
12 that.add = function(filter) {
16 that.visitTargets = function(callback) {
17 for (var i in m_list) {
18 var filter = m_list[i];
20 callback(filter.id, filter.name);
25 that.visitFields = function(callback) {
26 for (var i in m_list) {
27 var filter = m_list[i];
29 callback(filter.field, filter.value);
34 that.removeMatching = function(matchFn) {
36 for (var i in m_list) {
37 var filter = m_list[i];
38 if (matchFn(filter)) {
39 m_team.log("removeMatching() removing filter " + $.toJSON(filter));
41 m_team.log("removeMatching() keeping filter " + $.toJSON(filter));
48 that.targetFiltered = function(id) {
49 for (var i = 0; i < m_list.length; i++) {
50 if (m_list[i].id === id ||
51 m_list[i].id === 'pz:id=' + id) {
58 that.pp2filter = function() {
61 that.visitTargets(function(id, name) {
63 if (id.match(/^[a-z:]+[=~]/)) {
64 m_team.log("filter '" + id + "' already begins with SETTING OP");
74 that.pp2limit = function(initial) {
75 var OLD = that.OLD_pp2limit(initial);
76 var NEW = that.NEW_pp2limit(initial);
78 alert("pp2limit(): OLD[" + OLD + "] !== NEW[" + NEW + "]");
83 that.OLD_pp2limit = function(initial) {
84 var res = initial || "";
86 for (var i in m_list) {
87 var filter = m_list[i];
90 res += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
97 that.NEW_pp2limit = function(initial) {
98 return that.OLD_pp2limit(initial);
105 // Factory function for filters. These can be of several types.
106 function filter(id, name, field, value) {
110 res = { id: id, name: name };
112 res = { field: field, value: value };