Template Targets widget
authorJason Skomorowski <jason@indexdata.com>
Tue, 5 Aug 2014 13:56:36 +0000 (09:56 -0400)
committerJason Skomorowski <jason@indexdata.com>
Tue, 5 Aug 2014 14:20:01 +0000 (10:20 -0400)
src/mkws-widget-main.js
src/mkws-widget-main.templates/Targets.handlebars [new file with mode: 0644]

index e327941..224595e 100644 (file)
@@ -6,30 +6,25 @@
 mkws.registerWidgetType('Targets', function() {
   if (!this.config.show_switch) return;
   var that = this;
-  var M = mkws.M;
 
   this.node.html('No information available yet.');
   this.node.css("display", "none");
 
   this.team.queue("targets").subscribe(function(data) {
-    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>';
-
+    // There is a bug in pz2.js
+    var cleandata = [];
     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>";
+      var cur = {};
+      cur.id = data[i].id;
+      cur.hits = data[i].hits;
+      cur.diagnostic = data[i].diagnostic;
+      cur.records = data[i].records;
+      cur.state = data[i].state;
+      cleandata.push(cur);
     }
 
-    table += '</tbody></table>';
-    that.node.html(table);
+    var template = that.team.loadTemplate(that.config.template || "Targets");
+    that.node.html(template({data: cleandata}));
   });
 });
 
diff --git a/src/mkws-widget-main.templates/Targets.handlebars b/src/mkws-widget-main.templates/Targets.handlebars
new file mode 100644 (file)
index 0000000..4be3a21
--- /dev/null
@@ -0,0 +1,33 @@
+{{!
+Target detail
+
+data:
+  id - target id
+  hits - number of hits for this target
+  diagnostic - 
+  records - 
+  state - target state
+}}
+<table>
+  <thead>
+    <tr>
+      <td>{{mkws-translate "Target ID"}}</td>
+      <td>{{mkws-translate "Hits"}}</td>
+      <td>{{mkws-translate "Diags"}}</td>
+      <td>{{mkws-translate "Records"}}</td>
+      <td>{{mkws-translate "State"}}</td>
+      </td>
+    </tr>
+  </thead>
+  <tbody>
+  {{#each data}}
+    <tr>
+      <td>{{{id}}}</td>
+      <td>{{hits}}</td>
+      <td>{{diagnostic}}</td>
+      <td>{{records}}</td>
+      <td>{{hits}}</td>
+    </tr>
+  {{/each}}
+  </tbody>
+</table>