1 mkws.registerWidgetType('Termlists', function() {
5 this.team.queue("termlists").subscribe(function(data) {
7 alert("termlists event when there are no termlists");
11 // no facets: this should never happen
12 var facets = that.config.facets;
13 if (!facets || facets.length == 0) {
14 alert("onTerm called even though we have no facets: " + $.toJSON(data));
19 // display if we first got results
23 acc.push('<div class="title">' + M('Termlists') + '</div>');
25 for (var i = 0; i < facets.length; i++) {
26 if (facets[i] == "xtargets") {
27 addSingleFacet(acc, "Sources", data.xtargets, 16, null);
28 } else if (facets[i] == "subject") {
29 addSingleFacet(acc, "Subjects", data.subject, 10, "subject");
30 } else if (facets[i] == "author") {
31 addSingleFacet(acc, "Authors", data.author, 10, "author");
33 alert("bad facet configuration: '" + facets[i] + "'");
37 $(that.node).html(acc.join(''));
39 function addSingleFacet(acc, caption, data, max, pzIndex) {
40 var teamName = that.team.name();
41 acc.push('<div class="facet mkwsFacet' + caption + ' mkwsTeam_' + teamName + '">');
42 acc.push('<div class="termtitle">' + M(caption) + '</div>');
43 for (var i = 0; i < data.length && i < max; i++) {
44 acc.push('<div class="term">');
45 acc.push('<a href="#" ');
48 // Special case: target selection
49 acc.push('target_id='+data[i].id+' ');
50 if (!that.team.targetFiltered(data[i].id)) {
51 action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
54 action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
56 acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
57 + ' <span>' + data[i].freq + '</span>');
64 widget.autosearch(that);