X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-team.js;h=1ad267de0a3f3852bdf6c3f8eccf73864458b276;hb=21fc191d487bffa9592be523f1fb54ad3f44ef08;hp=aa84176a111be0384f9e99a604132da9626f4271;hpb=fa40f69b16aa52d1fa87827143ea13eb0c9de7f4;p=mkws-moved-to-github.git diff --git a/src/mkws-team.js b/src/mkws-team.js index aa84176..1ad267d 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -15,7 +15,7 @@ function team($, teamName) { var m_query; // initially undefined var m_sortOrder; // will be set below var m_perpage; // will be set below - var m_filters = []; + var m_filterSet = filterSet(that); var m_totalRecordCount = 0; var m_currentPage = 1; var m_currentRecordId = ''; @@ -40,7 +40,7 @@ function team($, teamName) { that.currentPage = function() { return m_currentPage; }; that.currentRecordId = function() { return m_currentRecordId; }; that.currentRecordData = function() { return m_currentRecordData; }; - that.filters = function() { return m_filters; }; + that.filters = function() { return m_filterSet.list(); }; that.config = function() { return m_config; }; // Accessor methods for individual widgets: writers @@ -163,19 +163,13 @@ function team($, teamName) { that.targetFiltered = function(id) { - for (var i = 0; i < m_filters.length; i++) { - if (m_filters[i].id === id || - m_filters[i].id === 'pz:id=' + id) { - return true; - } - } - return false; + return m_filterSet.targetFiltered(id); }; that.limitTarget = function(id, name) { log("limitTarget(id=" + id + ", name=" + name + ")"); - m_filters.push({ id: id, name: name }); + m_filterSet.add(filter(id, name)); triggerSearch(); return false; }; @@ -183,7 +177,7 @@ function team($, teamName) { that.limitQuery = function(field, value) { log("limitQuery(field=" + field + ", value=" + value + ")"); - m_filters.push({ field: field, value: value }); + m_filterSet.add(filter(null, null, field, value)); triggerSearch(); return false; }; @@ -191,15 +185,15 @@ function team($, teamName) { that.limitCategory = function(id) { log("limitCategory(id=" + id + ")"); - m_filters.push({ category: id }); - //triggerSearch(); + // ### Add a filter + // ### triggerSearch() if there's a query return false; }; that.delimitTarget = function(id) { log("delimitTarget(id=" + id + ")"); - removeMatchingFilters(function(f) { return f.id }); + m_filterSet.removeMatching(function(f) { return f.id }); triggerSearch(); return false; }; @@ -207,27 +201,12 @@ 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 }); + m_filterSet.removeMatching(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 (matchFn(filter)) { - log("removeMatchingFilters() removing filter " + $.toJSON(filter)); - } else { - log("removeMatchingFilters() keeping filter " + $.toJSON(filter)); - newFilters.push(filter); - } - } - m_filters = newFilters; - } - - that.showPage = function(pageNum) { m_currentPage = pageNum; m_paz.showPage(m_currentPage - 1); @@ -269,7 +248,7 @@ function team($, teamName) { return; } - m_filters = [] + m_filterSet = filterSet(that); triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery); switchView('records'); // In case it's configured to start off as hidden m_submitted = true; @@ -281,8 +260,6 @@ function team($, teamName) { resetPage(); queue("navi").publish(); - var pp2filter = ""; - var pp2limit = limit || ""; // Continue to use previous query/sort-order unless new ones are specified if (query) { @@ -295,26 +272,11 @@ function team($, teamName) { m_perpage = perpage; } if (targets) { - m_filters.push({ id: targets, name: targets }); + m_filterSet.add(filter(id, id)); } - for (var i in m_filters) { - var filter = m_filters[i]; - if (filter.id) { - if (pp2filter) - pp2filter += ","; - if (filter.id.match(/^[a-z:]+[=~]/)) { - log("filter '" + filter.id + "' already begins with SETTING OP"); - } else { - filter.id = 'pz:id=' + filter.id; - } - pp2filter += filter.id; - } else { - if (pp2limit) - pp2limit += ","; - pp2limit += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&'); - } - } + var pp2filter = m_filterSet.pp2filter(); + var pp2limit = m_filterSet.pp2limit(limit); var params = {}; if (pp2limit) { @@ -329,11 +291,9 @@ function team($, teamName) { params.torusquery = torusquery; } - log("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", " + + log("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filterSet.list()) + ", " + "pp2filter = " + pp2filter + ", params = " + $.toJSON(params)); - // We can use: params.torusquery = "udb=NAME" - // Note: that won't work when running against raw pazpar2 m_paz.search(m_query, m_perpage, m_sortOrder, pp2filter, undefined, params); }