X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-termlists.js;h=33d12b92255e538a33188256a7d8a93ca629ceda;hb=b75f69516de319ca5c283a70238a482e86303138;hp=7b843110afab31533176f17ad9c444e18808078c;hpb=6069b9f448eca6edf56b8bfbd572fc733effd5a9;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js index 7b84311..33d12b9 100644 --- a/src/mkws-widget-termlists.js +++ b/src/mkws-widget-termlists.js @@ -1,34 +1,46 @@ mkws.registerWidgetType('Termlists', function() { var that = this; - var facets = that.config.facets; - var M = mkws.M; + // Initially hide the termlists; display when we get results + $(document).ready(function() { + $(that.node).hide(); + }); this.team.queue("termlists").subscribe(function(data) { - // display if we first got results $(that.node).show(); }); + var acc = []; + var facets = this.config.facets; + acc.push('
' + mkws.M('Termlists') + '
'); 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 { - (function(ref, name) { - var caption = ref[0]; - that.team.queue("termlists").subscribe(function(data) { - makeSingleFacet(caption, data[name], ref[1], ref[2] ? name : null); - }) - }(ref, name)); - } + acc.push('
', '
'); } - - function makeSingleFacet(caption, data, max, pzIndex) { - that.log("in makeSingleFacet(" + caption + ")"); - var teamName = that.team.name(); + $(this.node).html(acc.join('')); + + widget.autosearch(this); +}); + + +mkws.registerWidgetType('Facet', function() { + var facetConfig = { + xtargets: [ "Sources", 16, false ], + subject: [ "Subjects", 10, true ], + author: [ "Authors", 10, true ] + } + + var that = this; + var name = that.config.facet; + var ref = facetConfig[name] || alert("no facet definition for '" + name + "'"); + var caption = ref[0]; + var max = ref[1]; + var pzIndex = ref[2] ? name : null; + + that.team.queue("termlists").subscribe(function(data) { + data = data[name]; + var teamName = that.team.name(); var acc = []; - acc.push('
' + M(caption) + '
'); + acc.push('
' + mkws.M(caption) + '
'); for (var i = 0; i < data.length && i < max; i++) { acc.push('
'); acc.push('' + data[i].freq + ''); acc.push('
'); } - that.team.findnode('.mkwsFacet' + caption).html(acc.join('')); - } - widget.autosearch(that); + $(that.node).html(acc.join('')); + }); });