X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-termlists.js;h=776ef5b009047d092b48efb2578306d66552b73b;hb=8d43b38a531101963703b6e98681d0de683298ff;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..776ef5b 100644 --- a/src/mkws-widget-termlists.js +++ b/src/mkws-widget-termlists.js @@ -1,53 +1,68 @@ mkws.registerWidgetType('Termlists', function() { - var that = this; - var facets = that.config.facets; - var M = mkws.M; - - this.team.queue("termlists").subscribe(function(data) { - // display if we first got results - $(that.node).show(); - }); - - 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)); - } - } - - function makeSingleFacet(caption, data, max, pzIndex) { - that.log("in makeSingleFacet(" + caption + ")"); - var teamName = that.team.name(); - - var acc = []; - acc.push('
' + M(caption) + '
'); - for (var i = 0; i < data.length && i < max; i++) { - acc.push('
'); - acc.push('' + data[i].name + '' - + ' ' + data[i].freq + ''); - acc.push('
'); - } - that.team.findnode('.mkwsFacet' + caption).html(acc.join('')); + var that = this; + + // Initially hide the termlists; display when we get results + mkws.$(document).ready(function() { + that.jqnode.hide(); + }); + this.team.queue("termlists").subscribe(function(data) { + that.jqnode.show(); + }); + + var acc = []; + var facets = this.config.facets; + acc.push('
' + mkws.M('Termlists') + '
'); + for (var i = 0; i < facets.length; i++) { + acc.push('
', '
'); + } + this.jqnode.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.toString = function() { + return '[Widget ' + that.team.name() + ':' + that.type + '(' + name + ')]'; + }; + + that.team.queue("termlists").subscribe(function(data) { + data = data[name]; + + var teamName = that.team.name(); + var acc = []; + acc.push('
' + mkws.M(caption) + '
'); + for (var i = 0; i < data.length && i < max; i++) { + acc.push('
'); + acc.push('' + data[i].name + '' + + ' ' + data[i].freq + ''); + acc.push('
'); } - widget.autosearch(that); + that.jqnode.html(acc.join('')); + }); });