1 // Factory function for sets of filters.
2 function filterSet(team) {
8 that.toJSON = function() {
9 return mkws.$.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.visitCategories = function(callback) {
35 for (var i in m_list) {
36 var filter = m_list[i];
37 if (filter.type === 'category') {
43 that.removeMatching = function(matchFn) {
45 for (var i in m_list) {
46 var filter = m_list[i];
47 if (matchFn(filter)) {
48 m_team.log("removeMatching: removing filter " + mkws.$.toJSON(filter));
50 m_team.log("removeMatching: keeping filter " + mkws.$.toJSON(filter));
57 that.targetFiltered = function(id) {
58 for (var i = 0; i < m_list.length; i++) {
59 if (m_list[i].type === 'target' ||
60 m_list[i].id === 'pz:id=' + id) {
67 that.pp2filter = function() {
70 that.visitTargets(function(id, name) {
72 if (id.match(/^[a-z:]+[=~]/)) {
73 m_team.log("filter '" + id + "' already begins with SETTING OP");
83 that.pp2limit = function(initial) {
84 var res = initial || "";
86 that.visitFields(function(field, value) {
88 res += field + "=" + value.replace(/[\\|,]/g, '\\$&');
93 that.pp2catLimit = function() {
96 that.visitCategories(function(id) {
98 res += "category~" + id.replace(/[\\|,]/g, '\\$&');
107 // Factory functions for filters. These can be of several types.
108 function targetFilter(id, name) {
116 function fieldFilter(field, value) {
124 function categoryFilter(id) {