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];
19 if (filter.type === 'target') {
20 callback(filter.id, filter.name);
25 that.visitFields = function(callback) {
26 for (var i in m_list) {
27 var filter = m_list[i];
28 if (filter.type === 'field') {
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].type === 'target' ||
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 that.visitFields(function(field, value) {
79 res += field + "=" + value.replace(/[\\|,]/g, '\\$&');
88 // Factory functions for filters. These can be of several types.
89 function targetFilter(id, name) {
97 function fieldFilter(field, value) {
105 function categoryFilter(id) {