Generate category limits correctly -- thanks to NE!
[mkws-moved-to-github.git] / src / mkws-team.js
index 2e24854..08f67b3 100644 (file)
@@ -170,7 +170,7 @@ function team($, teamName) {
     that.limitTarget = function(id, name) {
        log("limitTarget(id=" + id + ", name=" + name + ")");
        m_filterSet.add(targetFilter(id, name));
-       triggerSearch();
+       if (m_query) triggerSearch();
        return false;
     };
 
@@ -178,31 +178,34 @@ function team($, teamName) {
     that.limitQuery = function(field, value) {
        log("limitQuery(field=" + field + ", value=" + value + ")");
        m_filterSet.add(fieldFilter(field, value));
-       triggerSearch();
+        if (m_query) triggerSearch();
        return false;
     };
 
 
     that.limitCategory = function(id) {
        log("limitCategory(id=" + id + ")");
-       // ### Add a filter
-       // ### triggerSearch() if there's a query
+        // Only one category filter at a time
+       m_filterSet.removeMatching(function(f) { return f.type === 'category' });        
+        if (id !== '') m_filterSet.add(categoryFilter(id));
+        if (m_query) triggerSearch();
        return false;
     };
 
 
     that.delimitTarget = function(id) {
        log("delimitTarget(id=" + id + ")");
-       m_filterSet.removeMatching(function(f) { return f.id });
-       triggerSearch();
+       m_filterSet.removeMatching(function(f) { return f.type === 'target' });
+        if (m_query) triggerSearch();
        return false;
     };
 
 
     that.delimitQuery = function(field, value) {
        log("delimitQuery(field=" + field + ", value=" + value + ")");
-       m_filterSet.removeMatching(function(f) { return f.field && field == f.field && value == f.value });
-       triggerSearch();
+       m_filterSet.removeMatching(function(f) { return f.type == 'field' &&
+                                                 field == f.field && value == f.value });
+        if (m_query) triggerSearch();
        return false;
     };
 
@@ -248,7 +251,7 @@ function team($, teamName) {
            return;
        }
 
-       m_filterSet = filterSet(that);
+       m_filterSet.removeMatching(function(f) { return f.type !== 'category' });
        triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery);
        switchView('records'); // In case it's configured to start off as hidden
        m_submitted = true;
@@ -260,7 +263,6 @@ function team($, teamName) {
        resetPage();
        queue("navi").publish();
 
-
        // Continue to use previous query/sort-order unless new ones are specified
        if (query) m_query = query;
        if (sortOrder) m_sortOrder = sortOrder;
@@ -269,6 +271,10 @@ function team($, teamName) {
 
        var pp2filter = m_filterSet.pp2filter();
        var pp2limit = m_filterSet.pp2limit(limit);
+        var pp2catLimit = m_filterSet.pp2catLimit();
+       if (pp2catLimit) {
+            pp2filter = pp2filter ? pp2filter + "," + pp2catLimit : pp2catLimit;
+        }
 
        var params = {};
        if (pp2limit) params.limit = pp2limit;