1 mkws.registerWidgetType('Termlists', function() {
5 this.team.queue("termlists").subscribe(function(data) {
6 // no facets: this should never happen
7 var facets = that.config.facets;
8 if (!facets || facets.length == 0) {
9 alert("onTerm called even though we have no facets: " + $.toJSON(data));
14 // display if we first got results
18 acc.push('<div class="title">' + M('Termlists') + '</div>');
20 for (var i = 0; i < facets.length; i++) {
21 if (facets[i] == "xtargets") {
22 addSingleFacet(acc, "Sources", data.xtargets, 16, null);
23 } else if (facets[i] == "subject") {
24 addSingleFacet(acc, "Subjects", data.subject, 10, "subject");
25 } else if (facets[i] == "author") {
26 addSingleFacet(acc, "Authors", data.author, 10, "author");
28 alert("bad facet configuration: '" + facets[i] + "'");
32 $(that.node).html(acc.join(''));
34 function addSingleFacet(acc, caption, data, max, pzIndex) {
35 var teamName = that.team.name();
36 acc.push('<div class="mkwsFacet mkwsFacet' + caption + ' mkwsTeam_' + teamName + '">');
37 acc.push('<div class="termtitle">' + M(caption) + '</div>');
38 for (var i = 0; i < data.length && i < max; i++) {
39 acc.push('<div class="term">');
40 acc.push('<a href="#" ');
43 // Special case: target selection
44 acc.push('target_id='+data[i].id+' ');
45 if (!that.team.targetFiltered(data[i].id)) {
46 action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
49 action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
51 acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
52 + ' <span>' + data[i].freq + '</span>');
59 widget.autosearch(that);