X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-team.js;h=91a411cbc7f356dfdd5bf30306a61b326507d4a0;hb=1221dbafb11bc0e4479cf82b4288d73e4653dedd;hp=aa84176a111be0384f9e99a604132da9626f4271;hpb=fa40f69b16aa52d1fa87827143ea13eb0c9de7f4;p=mkws-moved-to-github.git diff --git a/src/mkws-team.js b/src/mkws-team.js index aa84176..91a411c 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(); 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,8 +185,8 @@ 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; }; @@ -215,8 +209,8 @@ function team($, teamName) { function removeMatchingFilters(matchFn) { var newFilters = []; - for (var i in m_filters) { - var filter = m_filters[i]; + for (var i in m_filterSet.list()) { + var filter = m_filterSet.list()[i]; if (matchFn(filter)) { log("removeMatchingFilters() removing filter " + $.toJSON(filter)); } else { @@ -224,7 +218,10 @@ function team($, teamName) { newFilters.push(filter); } } - m_filters = newFilters; + m_filterSet = filterSet(); + for (var i = 0; i < newFilters.length; i++) { + m_filterSet.add(newFilters[i]); + } } @@ -269,7 +266,7 @@ function team($, teamName) { return; } - m_filters = [] + m_filterSet = filterSet(); triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery); switchView('records'); // In case it's configured to start off as hidden m_submitted = true; @@ -295,11 +292,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]; + for (var i in m_filterSet.list()) { + var filter = m_filterSet.list()[i]; if (filter.id) { if (pp2filter) pp2filter += ","; @@ -309,7 +306,11 @@ function team($, teamName) { filter.id = 'pz:id=' + filter.id; } pp2filter += filter.id; - } else { + } + } + for (var i in m_filterSet.list()) { + var filter = m_filterSet.list()[i]; + if (!filter.id) { if (pp2limit) pp2limit += ","; pp2limit += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&'); @@ -329,7 +330,7 @@ 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"