The Reference Universe widget now specifies to use the correct target.
[mkws-moved-to-github.git] / examples / htdocs / mkws-widget-ru.js
index 97db1a2..b616b33 100644 (file)
@@ -1,11 +1,33 @@
-mkws.registerWidgetType('ReferenceUniverse', function() {
-    //this.team.config.service_proxy_auth = "http://mkws.indexdata.com/service-proxy/?command=auth&action=login&username=paratext&password=paratext_mkc";
-    // this.team.config.perpage_default = 5;
-    // this.team.config.sort_default = "position";
-    var teamClass = 'mkwsTeam_' + this.team.name();
-    var html = "<h2>Reference Universe results:</h2>\n";
-    html += '<div class="mkwsRecords ' + teamClass 
-            + '" autosearch="' + this.node.attr("autosearch")
-            + '" sort="position" perpage="5"></div>';
-    this.node.html(html);
+mkws.registerWidgetType('reference-universe', function() {
+  if (!this.config.target) this.config.target = 'paratext_ruprime';
+  if (!this.config.perpage) this.config.perpage = 5;
+  if (!this.config.sort) this.config.sort = "position";
+  this.team.registerTemplate('reference-universe', '\
+<h2>Results from Reference Universe</h2>\
+<ul>\
+{{#each hits}}\
+  <li>\
+    {{#mkws-first md-electronic-url}}\
+    <a href="{{this}}">\
+    {{/mkws-first}}\
+      {{md-title}}\
+    </a>\
+  {{#if md-title-remainder}}\
+    <span>{{md-title-remainder}}</span>\
+  {{/if}}\
+  {{#if md-title-responsibility}}\
+    <span><i>{{md-title-responsibility}}</i></span>\
+  {{/if}}\
+  </li>\
+{{/each}}\
+</ul>\
+');
+
+  var that = this;
+  var template = that.team.loadTemplate(that.config.template || "reference-universe");
+  this.team.queue("records").subscribe(function(data) {
+    that.node.html(template(data));
+  }); 
+  that.autosearch();
 });
+