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() {
59 var OLD = that.OLD_pp2filter();
60 var NEW = that.NEW_pp2filter();
62 alert("pp2filter(): OLD[" + OLD + "] !== NEW[" + NEW + "]");
67 that.OLD_pp2filter = function() {
70 for (var i in m_list) {
71 var filter = m_list[i];
74 if (filter.id.match(/^[a-z:]+[=~]/)) {
75 m_team.log("filter '" + filter.id + "' already begins with SETTING OP");
77 filter.id = 'pz:id=' + filter.id;
86 that.NEW_pp2filter = function() {
89 that.visitTargets(function(id, name) {
91 if (id.match(/^[a-z:]+[=~]/)) {
92 m_team.log("filter '" + id + "' already begins with SETTING OP");
102 that.pp2limit = function(initial) {
103 var res = initial || "";
105 for (var i in m_list) {
106 var filter = m_list[i];
109 res += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
121 // Factory function for filters. These can be of several types.
122 function filter(id, name, field, value) {
126 res = { id: id, name: name };
128 res = { field: field, value: value };