filter factory accepts name argument.
[mkws-moved-to-github.git] / src / mkws-filter.js
1 // Factory function for sets of filters.
2 function filterSet() {
3     var that = {};
4     var m_list = [];
5
6     that.list = function() {
7         return m_list;
8     };
9
10     that.add = function(filter) {
11         m_list.push(filter);
12     };
13
14     that.removeMatching = function(matchFn) {
15         var newList = [];
16         for (var i in m_list) {
17             var filter = m_list[i];
18             if (matchFn(filter)) {
19                 log("removeMatching() removing filter " + $.toJSON(filter));
20             } else {
21                 log("removeMatching() keeping filter " + $.toJSON(filter));
22                 newList.push(filter);
23             }
24         }
25         m_list = newList;
26     };
27
28     return that;
29 }
30
31
32 // Factory function for filters. These can be of several types.
33 function filter(id, name, field, value) {
34     var res;
35
36     if (id) {
37         res = { id: id, name: name };
38     } else {
39         res = { field: field, value: value };
40     }
41
42     return res;
43 }