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