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 res = initial || "";
77 for (var i in m_list) {
78 var filter = m_list[i];
81 res += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
93 // Factory function for filters. These can be of several types.
94 function filter(id, name, field, value) {
98 res = { id: id, name: name };
100 res = { field: field, value: value };