X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-termlists.js;h=cb07b28598c8ebde1bb1770e61dfa852f7e686f3;hb=6ddd7a09581894d0b3cf07973fc69006fc4c10e8;hp=e61ea645d2e41144164a6e1edba893ee7ab81bb9;hpb=2e5c86e69aebc7ac594db58ac0dbc63de7397527;p=mkws-moved-to-github.git
diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js
index e61ea64..cb07b28 100644
--- a/src/mkws-widget-termlists.js
+++ b/src/mkws-widget-termlists.js
@@ -1,51 +1,74 @@
mkws.registerWidgetType('Termlists', function() {
- var that = this;
- var facets = that.config.facets;
- var M = mkws.M;
-
- this.team.queue("termlists").subscribe(function(data) {
- // display if we first got results
- $(that.node).show();
- });
-
- this.team.queue("termlists").subscribe(function(data) {
- for (var i = 0; i < facets.length; i++) {
- var name = facets[i]
- var ref = mkws.facetConfig[name];
- var caption = ref[0];
- if (!ref) {
- alert("bad facet configuration: '" + name + "'");
- } else {
- makeSingleFacet(ref[0], data[name], ref[1], ref[2] ? name : null);
- }
- }
-
-
- function makeSingleFacet(caption, data, max, pzIndex) {
- var teamName = that.team.name();
-
- var acc = [];
- acc.push('
' + M(caption) + '
');
- for (var i = 0; i < data.length && i < max; i++) {
- acc.push('');
- }
- that.team.findnode('.mkwsFacet' + caption).html(acc.join(''));
- }
- });
-
- widget.autosearch(that);
+ var that = this;
+
+ // Initially hide the termlists; display when we get results
+ mkws.$(document).ready(function() {
+ that.node.hide();
+ });
+ this.team.queue("termlists").subscribe(function(data) {
+ that.node.show();
+ });
+
+ var acc = [];
+ var facets = this.config.facets;
+ acc.push('' + mkws.M('Termlists') + '
');
+ for (var i = 0; i < facets.length; i++) {
+ acc.push('', '
');
+ }
+ this.node.html(acc.join(''));
+
+ this.autosearch();
+});
+
+
+mkws.registerWidgetType('Facet', function() {
+ var facetConfig = {
+ xtargets: [ "Sources", 16, false ],
+ subject: [ "Subjects", 10, true ],
+ author: [ "Authors", 10, true ]
+ }
+
+ var that = this;
+ var name = that.config.facet;
+ var ref = facetConfig[name] || [ "Unknown", 10, true ];
+ var caption = this.config['facet_caption_' + name] || ref[0];
+ var max = parseInt(this.config['facet_max_' + name] || ref[1]);
+ var pzIndex = ref[2] ? name : null;
+
+ that.toString = function() {
+ return '[Widget ' + that.team.name() + ':' + that.type + '(' + name + ')]';
+ };
+
+ that.team.queue("termlists").subscribe(function(data) {
+ data = data[name];
+ var template = that.team.loadTemplate('facetTitle-' + caption, mkws.M(caption))
+ var title = template({ query: that.config.query });
+ var acc = [];
+ acc.push('', title, '
');
+
+ var teamName = that.team.name();
+ for (var i = 0; i < data.length && i < max; i++) {
+ var fn, datum;
+ // General case modifies the query; special case selects a target
+ if (pzIndex) {
+ fn = 'limitQuery'; datum = pzIndex;
+ } else if (!that.team.targetFiltered(data[i].id)) {
+ fn = 'limitTarget'; datum = data[i].id;
+ }
+
+ var action = '';
+ if (fn) {
+ action = 'mkws.' + fn + '(\'' + teamName + '\', \'' + datum + '\', \'' + data[i].name + '\')';
+ }
+
+ acc.push('');
+ }
+
+ that.node.html(acc.join(''));
+ });
+
+ this.autosearch();
});