Targets list is now generated by widget, not team.
authorMike Taylor <mike@indexdata.com>
Tue, 4 Mar 2014 14:07:47 +0000 (14:07 +0000)
committerMike Taylor <mike@indexdata.com>
Tue, 4 Mar 2014 14:07:47 +0000 (14:07 +0000)
This is done using publish/subscribe -- yay!
For some reason, the CSS styles are not getting applied.

tools/htdocs/mkws.js

index 9cbd283..a2f1ef9 100644 (file)
@@ -179,9 +179,43 @@ function widget($, team, type, node) {
        node: node
     };
 
+    var M = mkws.M;
+
+    if (type === 'Targets') {
+       promoteTargets();
+    }
+
     // ### More to do here, surely: e.g. wiring into the team
     mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
 
+    function promoteTargets() {
+       mkws.debug("promoting widget to type Targets");
+       mkws.queue("targets").subscribe(function(data) {
+           mkws.debug("notified that there are targets");
+
+           if (node.length === 0) alert("huh?!");
+
+           var table ='<table><thead><tr>' +
+               '<td>' + M('Target ID') + '</td>' +
+               '<td>' + M('Hits') + '</td>' +
+               '<td>' + M('Diags') + '</td>' +
+               '<td>' + M('Records') + '</td>' +
+               '<td>' + M('State') + '</td>' +
+               '</tr></thead><tbody>';
+
+           for (var i = 0; i < data.length; i++) {
+               table += "<tr><td>" + data[i].id +
+                   "</td><td>" + data[i].hits +
+                   "</td><td>" + data[i].diagnostic +
+                   "</td><td>" + data[i].records +
+                   "</td><td>" + data[i].state + "</td></tr>";
+           }
+           
+           table += '</tbody></table>';
+           $(node).html(table);
+       });
+    }
+
     return that;
 }
 
@@ -258,27 +292,7 @@ function team($, teamName) {
 
     function onBytarget(data, teamName) {
        debug("target");
-       var node = findnode('.mkwsBytarget');
-       if (node.length === 0) return;
-
-       var table ='<table><thead><tr>' +
-           '<td>' + M('Target ID') + '</td>' +
-           '<td>' + M('Hits') + '</td>' +
-           '<td>' + M('Diags') + '</td>' +
-           '<td>' + M('Records') + '</td>' +
-           '<td>' + M('State') + '</td>' +
-           '</tr></thead><tbody>';
-
-       for (var i = 0; i < data.length; i++) {
-            table += "<tr><td>" + data[i].id +
-               "</td><td>" + data[i].hits +
-               "</td><td>" + data[i].diagnostic +
-               "</td><td>" + data[i].records +
-               "</td><td>" + data[i].state + "</td></tr>";
-       }
-
-       table += '</tbody></table>';
-       node.html(table);
+       mkws.queue("targets").publish(data);
     }