X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fmkws-widget-main.js;h=91c2d9311ca8e48a0ac75087e895ed8087bddab6;hb=9d552877ef9bfbb92887942b9ac1870ddd12ba58;hp=6fbf5de1b2a544703d21b28651b1453c8c36c37f;hpb=cef14d4f276c60f0b7bfd7f11736d619945c9706;p=mkws-moved-to-github.git
diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js
index 6fbf5de..91c2d93 100644
--- a/src/mkws-widget-main.js
+++ b/src/mkws-widget-main.js
@@ -4,51 +4,36 @@
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.node.html('No information available yet.');
+ this.node.css("display", "none");
this.team.queue("targets").subscribe(function(data) {
- var table ='' +
- '' + M('Target ID') + ' | ' +
- '' + M('Hits') + ' | ' +
- '' + M('Diags') + ' | ' +
- '' + M('Records') + ' | ' +
- '' + M('State') + ' | ' +
- '
';
-
+ // There is a bug in pz2.js
+ var cleandata = [];
for (var i = 0; i < data.length; i++) {
- table += "" + data[i].id +
- " | " + data[i].hits +
- " | " + data[i].diagnostic +
- " | " + data[i].records +
- " | " + data[i].state + " |
";
+ 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 += '
';
- var subnode = $(that.node).children('.mkwsBytarget');
- subnode.html(table);
+ var template = that.team.loadTemplate(that.config.template || "Targets");
+ that.node.html(template({data: cleandata}));
});
});
mkws.registerWidgetType('Stat', function() {
var that = this;
- var M = mkws.M;
-
this.team.queue("stat").subscribe(function(data) {
- if (that.node.length === 0) alert("huh?!");
-
- $(that.node).html('' + M('Status info') + '' +
- ' -- ' +
- '' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' +
- ' -- ' +
- '' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '');
+ var template = that.team.loadTemplate(that.config.template || "Stat");
+ that.node.html(template(data));
});
});
@@ -58,7 +43,7 @@ mkws.registerWidgetType('Pager', function() {
var M = mkws.M;
this.team.queue("pager").subscribe(function(data) {
- $(that.node).html(drawPager(data))
+ that.node.html(drawPager(data))
function drawPager(data) {
var teamName = that.team.name();
@@ -89,7 +74,7 @@ mkws.registerWidgetType('Pager', function() {
for(var i = firstClkbl; i <= lastClkbl; i++) {
var numLabel = i;
if(i == currentPage)
- numLabel = '' + i + '';
+ numLabel = '' + i + '';
middle += ' '
+ numLabel + ' ';
@@ -122,31 +107,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('', renderSummary(hit), '
');
+ 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.node).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();
});
@@ -161,18 +144,18 @@ mkws.registerWidgetType('Navi', function() {
filters.visitTargets(function(id, name) {
if (text) text += " | ";
- text += M('source') + ': ' + name + '';
});
filters.visitFields(function(field, value) {
if (text) text += " | ";
- text += M(field) + ': ' + value + '';
});
- $(that.node).html(text);
+ that.node.html(text);
});
});
@@ -183,8 +166,8 @@ mkws.registerWidgetType('Navi', function() {
mkws.registerWidgetType('Sort', function() {
var that = this;
- $(this.node).change(function() {
- that.team.set_sortOrder($(that.node).val());
+ this.node.change(function() {
+ that.team.set_sortOrder(that.node.val());
if (that.team.submitted()) {
that.team.reShow();
}
@@ -196,8 +179,8 @@ mkws.registerWidgetType('Sort', function() {
mkws.registerWidgetType('Perpage', function() {
var that = this;
- $(this.node).change(function() {
- that.team.set_perpage($(that.node).val());
+ this.node.change(function() {
+ that.team.set_perpage(that.node.val());
if (that.team.submitted()) {
that.team.reShow();
}
@@ -210,18 +193,19 @@ mkws.registerWidgetType('Done', function() {
var that = this;
this.team.queue("complete").subscribe(function(n) {
- $(that.node).html("Search complete: found " + n + " records");
+ that.node.html("Search complete: found " + n + " records");
});
});
mkws.registerWidgetType('Switch', function() {
+ if (!this.config.show_switch) return;
var tname = this.team.name();
- $(this.node).html('\
+ this.node.html('\
Records \
| \
Targets');
- widget.hideWhenNarrow(this);
+ this.hideWhenNarrow();
});
@@ -229,7 +213,7 @@ mkws.registerWidgetType('Search', function() {
var tname = this.team.name();
var M = mkws.M;
- $(this.node).html('\
+ this.node.html('\
';
- $(this.node).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 = '