Insert missing semicolons after function assignments.
[mkws-moved-to-github.git] / src / mkws-widget-facets.js
index 575a655..ffe344b 100644 (file)
@@ -1,8 +1,16 @@
-mkws.registerWidgetType('termlists', function() {
-  // Initially hide the termlists; display when we get results
+mkws.registerWidgetType('facets', function() {
+  // Initially hide the facets; display when we get results
   var that = this;
   var team = this.team;
+
+  this.team.queue("searchtriggered").subscribe(function() {
+    var op = that.config.newsearch_opacity;
+    if (op !== undefined) { that.node.fadeTo(500, op); }
+  });
+
   team.queue("facets").subscribe(function(data) {
+    that.node.stop();
+    that.node.css('opacity', 1);
     that.node.addClass("active");
   });
 
@@ -37,24 +45,23 @@ mkws.registerWidgetType('facet', function() {
     data = data[name];
     var terms = [];
     var teamName = team.name();
+    var base = team.filters();
     for (var i = 0; i < data.length && i < max; i++) {
-      var linkdata = "";
-      var action = "";
+      var fs = $.extend(true, {}, base);
+      //team.warn("fs = " + mkws.$.toJSON(fs));
+      //team.warn("team.filters = " + mkws.$.toJSON(team.filters()));
       if (!pzIndex) {
         // Special case: target selection
-        linkdata += ('target_id='+data[i].id+' ');
-        if (!team.targetFiltered(data[i].id)) {
-          action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
-        }
+        team.warn("before: team.filters = " + mkws.$.toJSON(team.filters()));
+        fs.add(targetFilter(data[i].id, data[i].name));
+        team.warn("after: team.filters = " + mkws.$.toJSON(team.filters()));
       } else {
-        action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
+        fs.add(fieldFilter(pzIndex, data[i].name));
       }
-      linkdata += 'onclick="' + action + ';return false;"';
       terms.push({
         term: data[i].name,
-        field: data[i].id,
         count: data[i].freq,
-        linkdata: linkdata
+        href: '#' + team.urlFragment({ filters: fs })
       }); 
     }
     // configured template > facet specific template > default facet template
@@ -64,16 +71,15 @@ mkws.registerWidgetType('facet', function() {
     } else {
       template = team.loadTemplate("facet-" + name);
       if (template) {
-        that.log("Using facet-" + name + " template.")
+        that.info("Using facet-" + name + " template.")
       } else {
-        that.log("No " + name + " specific template, using default.")
+        that.info("No " + name + " specific template, using default.")
         template = team.loadTemplate("facet");
       }
     }
     that.node.html(template({
       name: name,
       caption: caption,
-      query: that.config.query,
       terms: terms
     }));
   });