Separate out callback for displaying termlists area and filling individual lists.
[mkws-moved-to-github.git] / src / mkws-widget-termlists.js
index b140198..e61ea64 100644 (file)
@@ -3,31 +3,12 @@ mkws.registerWidgetType('Termlists', function() {
     var facets = that.config.facets;
     var M = mkws.M;
 
-    mkws.facetConfig = {
-       xtargets: [ "Sources",  16, false ],
-       subject:  [ "Subjects", 10, true ],
-       author:   [ "Authors",  10, true ]
-    }
-
-    var acc = [];
-    acc.push('<div class="title">' + M('Termlists') + '</div>');
-    for (var i = 0; i < facets.length; i++) {
-       var name = facets[i]
-       var ref = mkws.facetConfig[name];
-       if (!ref) {
-           alert("bad facet configuration: '" + name + "'");
-       } else {
-           acc.push('<div class="mkwsFacet mkwsFacet' + ref[0] + ' mkwsTeam_' + that.team.name() + '">');
-           acc.push('</div>');
-       }
-    }
-    $(that.node).html(acc.join(''));
-
-
     this.team.queue("termlists").subscribe(function(data) {
        // display if we first got results
        $(that.node).show();
+    });
 
+    this.team.queue("termlists").subscribe(function(data) {
        for (var i = 0; i < facets.length; i++) {
            var name = facets[i]
            var ref = mkws.facetConfig[name];
@@ -35,8 +16,7 @@ mkws.registerWidgetType('Termlists', function() {
            if (!ref) {
                alert("bad facet configuration: '" + name + "'");
            } else {
-               var output = makeSingleFacet(ref[0], data[name], ref[1], ref[2] ? name : null);
-               that.team.findnode('.mkwsFacet' + caption).html(output);
+               makeSingleFacet(ref[0], data[name], ref[1], ref[2] ? name : null);
            }
        }
 
@@ -63,7 +43,7 @@ mkws.registerWidgetType('Termlists', function() {
                         + ' <span>' + data[i].freq + '</span>');
                acc.push('</div>');
            }
-           return acc.join('');
+           that.team.findnode('.mkwsFacet' + caption).html(acc.join(''));
        }
     });