1 mkws.registerWidgetType('Termlists', function() {
6 xtargets: [ "Sources", 16, false ],
7 subject: [ "Subjects", 10, true ],
8 author: [ "Authors", 10, true ]
11 this.team.queue("termlists").subscribe(function(data) {
12 // no facets: this should never happen
13 var facets = that.config.facets;
14 if (!facets || facets.length == 0) {
15 alert("onTerm called even though we have no facets: " + $.toJSON(data));
20 // display if we first got results
24 acc.push('<div class="title">' + M('Termlists') + '</div>');
25 for (var i = 0; i < facets.length; i++) {
27 var ref = facetConfig[name];
29 alert("bad facet configuration: '" + name + "'");
31 acc.push('<div class="mkwsFacet mkwsFacet' + ref[0] + ' mkwsTeam_' + that.team.name() + '">');
35 $(that.node).html(acc.join(''));
39 for (var i = 0; i < facets.length; i++) {
41 var ref = facetConfig[name];
43 alert("bad facet configuration: '" + name + "'");
45 output[name] = makeSingleFacet(ref[0], data[name], ref[1], ref[2] ? name : null);
49 for (var i = 0; i < facets.length; i++) {
51 var ref = facetConfig[name];
54 that.log("setting HTML for facet '" + name + "'");
55 that.team.findnode('.mkwsFacet' + caption).html(output[name]);
59 function makeSingleFacet(caption, data, max, pzIndex) {
60 var teamName = that.team.name();
63 a2.push('<div class="termtitle">' + M(caption) + '</div>');
64 for (var i = 0; i < data.length && i < max; i++) {
65 a2.push('<div class="term">');
66 a2.push('<a href="#" ');
69 // Special case: target selection
70 a2.push('target_id='+data[i].id+' ');
71 if (!that.team.targetFiltered(data[i].id)) {
72 action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
75 action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
77 a2.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
78 + ' <span>' + data[i].freq + '</span>');
85 widget.autosearch(that);