Tweak
[mkws-moved-to-github.git] / src / mkws-widget-termlists.js
1 mkws.registerWidgetType('Termlists', function() {
2     var that = this;
3     var facets = that.config.facets;
4
5     this.team.queue("termlists").subscribe(function(data) {
6         // display if we first got results
7         $(that.node).show();
8     });
9
10     widget.autosearch(that);
11 });
12
13
14 mkws.registerWidgetType('Facet', function() {
15     var facetConfig = {
16         xtargets: [ "Sources",  16, false ],
17         subject:  [ "Subjects", 10, true ],
18         author:   [ "Authors",  10, true ]
19     }
20
21     var that = this;
22     var name = that.config.facet;
23     var ref = facetConfig[name] || alert("no facet definition for '" + name + "'");
24     var caption = ref[0];
25     var max = ref[1];
26     var pzIndex = ref[2] ? name : null;
27
28     that.team.queue("termlists").subscribe(function(data) {
29         data = data[name];
30
31         var teamName = that.team.name();
32         var acc = [];
33         acc.push('<div class="termtitle">' + mkws.M(caption) + '</div>');
34         for (var i = 0; i < data.length && i < max; i++) {
35             acc.push('<div class="term">');
36             acc.push('<a href="#" ');
37             var action = '';
38             if (!pzIndex) {
39                 // Special case: target selection
40                 acc.push('target_id='+data[i].id+' ');
41                 if (!that.team.targetFiltered(data[i].id)) {
42                     action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
43                 }
44             } else {
45                 action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
46             }
47             acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
48                      + ' <span>' + data[i].freq + '</span>');
49             acc.push('</div>');
50         }
51
52         $(that.node).html(acc.join(''));
53     });
54 });