X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmkws-widget-termlists.js;h=3ea68f5cbbeca4fe0611a9be6791bb9a1a3ceb85;hb=e6cb922902b29c80209e6dce577fb6c09af862c8;hp=7b843110afab31533176f17ad9c444e18808078c;hpb=6069b9f448eca6edf56b8bfbd572fc733effd5a9;p=mkws-moved-to-github.git
diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js
index 7b84311..3ea68f5 100644
--- a/src/mkws-widget-termlists.js
+++ b/src/mkws-widget-termlists.js
@@ -1,34 +1,50 @@
mkws.registerWidgetType('Termlists', function() {
var that = this;
- var facets = that.config.facets;
- var M = mkws.M;
+ // Initially hide the termlists; display when we get results
+ $(document).ready(function() {
+ $(that.node).hide();
+ });
this.team.queue("termlists").subscribe(function(data) {
- // display if we first got results
$(that.node).show();
});
+ var acc = [];
+ var facets = this.config.facets;
+ acc.push('
' + mkws.M('Termlists') + '
');
for (var i = 0; i < facets.length; i++) {
- var name = facets[i]
- var ref = mkws.facetConfig[name];
- if (!ref) {
- alert("bad facet configuration: '" + name + "'");
- } else {
- (function(ref, name) {
- var caption = ref[0];
- that.team.queue("termlists").subscribe(function(data) {
- makeSingleFacet(caption, data[name], ref[1], ref[2] ? name : null);
- })
- }(ref, name));
- }
+ acc.push('', '
');
+ }
+ $(this.node).html(acc.join(''));
+
+ widget.autosearch(this);
+});
+
+
+mkws.registerWidgetType('Facet', function() {
+ var facetConfig = {
+ xtargets: [ "Sources", 16, false ],
+ subject: [ "Subjects", 10, true ],
+ author: [ "Authors", 10, true ]
}
-
- function makeSingleFacet(caption, data, max, pzIndex) {
- that.log("in makeSingleFacet(" + caption + ")");
- var teamName = that.team.name();
+ var that = this;
+ var name = that.config.facet;
+ var ref = facetConfig[name] || alert("no facet definition for '" + name + "'");
+ var caption = ref[0];
+ var max = 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 teamName = that.team.name();
var acc = [];
- acc.push('' + M(caption) + '
');
+ acc.push('' + mkws.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);
+ $(that.node).html(acc.join(''));
+ });
});