X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fmkws-filter.js;h=eff521cb8116134a0533725b832a5ee4e2e6a246;hb=d2de378b5618363f7cbd66bc91ece4c8f1157af4;hp=aa3a2049de407af95447d4929d27e9feb0243189;hpb=f2a9caeb4ad7aab086b46af8d3050e0ba22e0e47;p=mkws-moved-to-github.git diff --git a/src/mkws-filter.js b/src/mkws-filter.js index aa3a204..eff521c 100644 --- a/src/mkws-filter.js +++ b/src/mkws-filter.js @@ -5,14 +5,32 @@ function filterSet(team) { var that = {}; - that.list = function() { - return m_list; - }; + that.toJSON = function() { + return $.toJSON(m_list); + } that.add = function(filter) { m_list.push(filter); }; + that.visitTargets = function(callback) { + for (var i in m_list) { + var filter = m_list[i]; + if (filter.id) { + callback(filter.id, filter.name); + } + } + }; + + that.visitFields = function(callback) { + for (var i in m_list) { + var filter = m_list[i]; + if (!filter.id) { + callback(filter.field, filter.value); + } + } + }; + that.removeMatching = function(matchFn) { var newList = []; for (var i in m_list) { @@ -43,8 +61,7 @@ function filterSet(team) { for (var i in m_list) { var filter = m_list[i]; if (filter.id) { - if (res) - res += ","; + if (res) res += ","; if (filter.id.match(/^[a-z:]+[=~]/)) { m_team.log("filter '" + filter.id + "' already begins with SETTING OP"); } else { @@ -57,6 +74,21 @@ function filterSet(team) { return res; } + that.pp2limit = function(initial) { + var res = initial || ""; + + for (var i in m_list) { + var filter = m_list[i]; + if (!filter.id) { + if (res) res += ","; + res += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&'); + } + } + + return res; + } + + return that; }