X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-termlists.js;h=cb07b28598c8ebde1bb1770e61dfa852f7e686f3;hb=950c995e759d65d8dd4e9fc11383d4ed269b35bd;hp=69d97a556d9818ecb154d085c8df3d4462d1bc49;hpb=a442ae54ee85ce806e8b9c33b6e4845f7c7fde92;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js index 69d97a5..cb07b28 100644 --- a/src/mkws-widget-termlists.js +++ b/src/mkws-widget-termlists.js @@ -1,73 +1,74 @@ mkws.registerWidgetType('Termlists', function() { - var that = this; - var M = mkws.M; + var that = this; + + // Initially hide the termlists; display when we get results + mkws.$(document).ready(function() { + that.node.hide(); + }); + this.team.queue("termlists").subscribe(function(data) { + that.node.show(); + }); + + var acc = []; + var facets = this.config.facets; + acc.push('
' + mkws.M('Termlists') + '
'); + for (var i = 0; i < facets.length; i++) { + acc.push('
', '
'); + } + this.node.html(acc.join('')); + + this.autosearch(); +}); - var facetConfig = { - xtargets: [ "Sources", 16, false ], - subject: [ "Subjects", 10, true ], - author: [ "Authors", 10, true ] - } - this.team.queue("termlists").subscribe(function(data) { - // no facets: this should never happen - var facets = that.config.facets; +mkws.registerWidgetType('Facet', function() { + var facetConfig = { + xtargets: [ "Sources", 16, false ], + subject: [ "Subjects", 10, true ], + author: [ "Authors", 10, true ] + } - // display if we first got results - $(that.node).show(); + var that = this; + var name = that.config.facet; + var ref = facetConfig[name] || [ "Unknown", 10, true ]; + var caption = this.config['facet_caption_' + name] || ref[0]; + var max = parseInt(this.config['facet_max_' + name] || ref[1]); + var pzIndex = ref[2] ? name : null; - var acc = []; - acc.push('
' + M('Termlists') + '
'); - for (var i = 0; i < facets.length; i++) { - var name = facets[i] - var ref = facetConfig[name]; - if (!ref) { - alert("bad facet configuration: '" + name + "'"); - } else { - acc.push('
'); - acc.push('
'); - } - } - $(that.node).html(acc.join('')); + that.toString = function() { + return '[Widget ' + that.team.name() + ':' + that.type + '(' + name + ')]'; + }; + that.team.queue("termlists").subscribe(function(data) { + data = data[name]; + var template = that.team.loadTemplate('facetTitle-' + caption, mkws.M(caption)) + var title = template({ query: that.config.query }); + var acc = []; + acc.push('
', title, '
'); - for (var i = 0; i < facets.length; i++) { - var name = facets[i] - var ref = facetConfig[name]; - var caption = ref[0]; - 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); - } - } + var teamName = that.team.name(); + for (var i = 0; i < data.length && i < max; i++) { + var fn, datum; + // General case modifies the query; special case selects a target + if (pzIndex) { + fn = 'limitQuery'; datum = pzIndex; + } else if (!that.team.targetFiltered(data[i].id)) { + fn = 'limitTarget'; datum = data[i].id; + } + var action = ''; + if (fn) { + action = 'mkws.' + fn + '(\'' + teamName + '\', \'' + datum + '\', \'' + data[i].name + '\')'; + } - function makeSingleFacet(caption, data, max, pzIndex) { - var teamName = that.team.name(); + acc.push('
', + '', data[i].name, '', + '', data[i].freq, '', + '
'); + } - 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('
'); - } - return acc.join(''); - } - }); + that.node.html(acc.join('')); + }); - widget.autosearch(that); + this.autosearch(); });