From: Mike Taylor Date: Thu, 27 Mar 2014 17:03:55 +0000 (+0000) Subject: Factor common code out of delimitTarget and delimitQuery into new X-Git-Tag: 1.0.0~1144 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=ad3513b39688df357a22801cd81dcad61e0b6743;p=mkws-moved-to-github.git Factor common code out of delimitTarget and delimitQuery into new utility function removeMatchingFilters. --- diff --git a/src/mkws-team.js b/src/mkws-team.js index 100ce3e..7490999 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -166,18 +166,7 @@ function team($, teamName) { that.delimitTarget = function(id) { log("delimitTarget(id=" + id + ")"); - var newFilters = []; - for (var i in m_filters) { - var filter = m_filters[i]; - if (filter.id) { - log("delimitTarget() removing filter " + $.toJSON(filter)); - } else { - log("delimitTarget() keeping filter " + $.toJSON(filter)); - newFilters.push(filter); - } - } - m_filters = newFilters; - + removeMatchingFilters(function(f) { return f.id }); triggerSearch(); return false; }; @@ -186,23 +175,25 @@ function team($, teamName) { that.delimitQuery = function(field, value) { log("delimitQuery(field=" + field + ", value=" + value + ")"); + removeMatchingFilters(function(f) { return f.field && field == f.field && value == f.value }); + triggerSearch(); + return false; + }; + + + function removeMatchingFilters(matchFn) { var newFilters = []; for (var i in m_filters) { var filter = m_filters[i]; - if (filter.field && - field == filter.field && - value == filter.value) { - log("delimitQuery() removing filter " + $.toJSON(filter)); + if (matchFn(filter)) { + log("removeMatchingFilters() removing filter " + $.toJSON(filter)); } else { - log("delimitQuery() keeping filter " + $.toJSON(filter)); + log("removeMatchingFilters() keeping filter " + $.toJSON(filter)); newFilters.push(filter); } } m_filters = newFilters; - - triggerSearch(); - return false; - }; + } that.showPage = function(pageNum)