Ignore vim swap files.
[mkws-moved-to-github.git] / src / mkws-widget-main.js
index 6daac14..5106839 100644 (file)
@@ -8,8 +8,8 @@ mkws.registerWidgetType('Targets', function() {
   var that = this;
   var M = mkws.M;
 
-  this.jqnode.html('No information available yet.');
-  this.jqnode.css("display", "none");
+  this.node.html('No information available yet.');
+  this.node.css("display", "none");
 
   this.team.queue("targets").subscribe(function(data) {
     var table ='<table><thead><tr>' +
@@ -29,7 +29,7 @@ mkws.registerWidgetType('Targets', function() {
     }
 
     table += '</tbody></table>';
-    that.jqnode.html(table);
+    that.node.html(table);
   });
 });
 
@@ -39,7 +39,7 @@ mkws.registerWidgetType('Stat', function() {
   var M = mkws.M;
 
   this.team.queue("stat").subscribe(function(data) {
-    that.jqnode.html(' -- ' +
+    that.node.html(' -- ' +
                       '<span class="mkwsClientCount">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
                       ' -- ' +
                       M('Retrieved records') + ': ' + data.records + '/' + data.hits);
@@ -52,7 +52,7 @@ mkws.registerWidgetType('Pager', function() {
   var M = mkws.M;
 
   this.team.queue("pager").subscribe(function(data) {
-    that.jqnode.html(drawPager(data))
+    that.node.html(drawPager(data))
 
     function drawPager(data) {
       var teamName = that.team.name();
@@ -116,31 +116,29 @@ mkws.registerWidgetType('Records', function() {
   var team = this.team;
 
   this.team.queue("records").subscribe(function(data) {
-    var html = [];
     for (var i = 0; i < data.hits.length; i++) {
       var hit = data.hits[i];
       that.team.queue("record").publish(hit);
-      var divId = team.recordElementId(hit.recid[0]);
-      html.push('<div class="mkwsSummary mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
+      hit.detailLinkId = team.recordElementId(hit.recid[0]);
+      hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
+      hit.containerClass = "mkwsSummary mkwsTeam_" + team.name();
+      hit.containerClass += " " + hit.detailLinkId;
       // ### At some point, we may be able to move the
       // m_currentRecordId and m_currentRecordData members
       // from the team object into this widget.
       if (hit.recid == team.currentRecordId()) {
-        if (team.currentRecordData())
-          html.push(team.renderDetails(team.currentRecordData()));
+        if (team.currentRecordData()) {
+          hit.renderedDetails = team.renderDetails(team.currentRecordData());
+          console.log(hit.renderedDetails); 
+        } 
       }
     }
-    that.jqnode.html(html.join(''));
-
-    function renderSummary(hit) {
-      var template = team.loadTemplate(that.config.template || "Summary");
-      hit._id = team.recordElementId(hit.recid[0]);
-      hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
-      return template(hit);
-    }
+    var template = team.loadTemplate(that.config.template || "Records");
+    var targs = $.extend({}, {"hits": data.hits}, that.config.template_vars);
+    that.node.html(template(targs));
   });
 
-  widget.autosearch(that);
+  that.autosearch();
 });
 
 
@@ -166,7 +164,7 @@ mkws.registerWidgetType('Navi', function() {
         ');return false;">' + value + '</a>';
     });
 
-    that.jqnode.html(text);
+    that.node.html(text);
   });
 });
 
@@ -177,8 +175,8 @@ mkws.registerWidgetType('Navi', function() {
 mkws.registerWidgetType('Sort', function() {
   var that = this;
 
-  this.jqnode.change(function() {
-    that.team.set_sortOrder(that.jqnode.val());
+  this.node.change(function() {
+    that.team.set_sortOrder(that.node.val());
     if (that.team.submitted()) {
       that.team.reShow();
     }
@@ -190,8 +188,8 @@ mkws.registerWidgetType('Sort', function() {
 mkws.registerWidgetType('Perpage', function() {
   var that = this;
 
-  this.jqnode.change(function() {
-    that.team.set_perpage(that.jqnode.val());
+  this.node.change(function() {
+    that.team.set_perpage(that.node.val());
     if (that.team.submitted()) {
       that.team.reShow();
     }
@@ -204,7 +202,7 @@ mkws.registerWidgetType('Done', function() {
   var that = this;
 
   this.team.queue("complete").subscribe(function(n) {
-    that.jqnode.html("Search complete: found " + n + " records");
+    that.node.html("Search complete: found " + n + " records");
   });
 });
 
@@ -212,11 +210,11 @@ mkws.registerWidgetType('Done', function() {
 mkws.registerWidgetType('Switch', function() {
   if (!this.config.show_switch) return;
   var tname = this.team.name();
-  this.jqnode.html('\
+  this.node.html('\
 <a href="#" onclick="mkws.switchView(\'' + tname + '\', \'records\')">Records</a><span> \
 | \
 </span><a href="#" onclick="mkws.switchView(\'' + tname + '\', \'targets\')">Targets</a>');
-  widget.hideWhenNarrow(this);
+  this.hideWhenNarrow();
 });
 
 
@@ -224,7 +222,7 @@ mkws.registerWidgetType('Search', function() {
   var tname = this.team.name();
   var M = mkws.M;
 
-  this.jqnode.html('\
+  this.node.html('\
 <form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
   <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + this.config.query_width + '" />\
   <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
@@ -234,7 +232,7 @@ mkws.registerWidgetType('Search', function() {
 
 mkws.registerWidgetType('SearchForm', function() {
   var team = this.team;
-  this.jqnode.submit(function() {
+  this.node.submit(function() {
     var val = team.widget('Query').value();
     team.newSearch(val);
     return false;
@@ -245,7 +243,7 @@ mkws.registerWidgetType('SearchForm', function() {
 mkws.registerWidgetType('Results', function() {
   var tname = this.team.name();
 
-  this.jqnode.html('\
+  this.node.html('\
 <table width="100%" border="0" cellpadding="6" cellspacing="0">\
   <tr>\
     <td class="mkwsTermlists-Container-wide mkwsTeam_' + tname + '" width="250" valign="top">\
@@ -265,7 +263,7 @@ mkws.registerWidgetType('Results', function() {
   </tr>\
 </table>');
 
-  widget.autosearch(this);
+  this.autosearch();
 });
 
 
@@ -283,13 +281,13 @@ mkws.registerWidgetType('Ranking', function() {
   }
   s += '</form>';
 
-  this.jqnode.html(s);
+  this.node.html(s);
 
 
   function mkwsHtmlSort() {
     var order = that.team.sortOrder();
 
-    that.log("HTML sort, sortOrder = '" + order + "'");
+    that.log("making sort HTML, sortOrder = '" + order + "'");
     var sort_html = '<select class="mkwsSort mkwsTeam_' + tname + '">';
 
     for(var i = 0; i < that.config.sort_options.length; i++) {
@@ -311,7 +309,7 @@ mkws.registerWidgetType('Ranking', function() {
   function mkwsHtmlPerpage() {
     var perpage = that.team.perpage();
 
-    that.log("HTML perpage, perpage = " + perpage);
+    that.log("making perpage HTML, perpage = " + perpage);
     var perpage_html = '<select class="mkwsPerpage mkwsTeam_' + tname + '">';
 
     for(var i = 0; i < that.config.perpage_options.length; i++) {
@@ -371,8 +369,8 @@ mkws.registerWidgetType('Lang', function() {
     }
   }
 
-  this.jqnode.html(data);
-  widget.hideWhenNarrow(this);
+  this.node.html(data);
+  this.hideWhenNarrow();
 
 
   // set or re-set "lang" URL parameter
@@ -400,11 +398,46 @@ mkws.registerWidgetType('MOTD', function() {
   var container = this.team.widget('MOTDContainer');
   if (container) {
     // Move the MOTD from the provided element down into the container
-    this.jqnode.appendTo(container.node); // #### can this be container.jqnode
+    this.node.appendTo(container.node);
   }
 });
 
 
+// This widget has no functionality of its own, but its configuration
+// is copied up into its team, allowing it to affect other widgets in
+// the team.
+//
+mkws.registerWidgetType('Config', function() {
+  var c = this.config;
+  for (var name in c) {
+    if (c.hasOwnProperty(name)) {
+      this.team.config()[name] = c[name];
+      this.log(this + " copied property " + name + "='" + c[name] + "' up to team");
+    }
+  }
+});
+
+
+mkws.registerWidgetType('Progress', function() {
+  var that = this;
+
+  this.node.hide();
+  this.team.queue("stat").subscribe(function(data) {
+    var s = '<span class="mkwsDone">';
+    for (var i = 0; i < data.clients; i++) {
+      if (i == data.clients - data.activeclients) {
+        s += '</span>';
+        s += '<span class="mkwsWaiting">';
+      }
+      s += '&#x2588';
+    }
+    s += '</span>';
+    that.node.html(s);
+    that.node.show();
+  });
+});
+
+
 // Some elements have mkws* classes that makes them appear as widgets
 // -- for example, because we want to style them using CSS -- but have
 // no actual functionality. We register these to prevent ignorable