};
-// The following PubSub code is modified from the jQuery manual:
-// https://api.jquery.com/jQuery.Callbacks/
-//
-// Use as:
-// mkws.queue("eventName").subscribe(function(param1, param2 ...) { ... });
-// mkws.queue("eventName").publish(arg1, arg2, ...);
-
-(function() {
- var queues = {};
- mkws.queue = function(id) {
- if (!queues[id]) {
- var callbacks = $.Callbacks();
- queues[id] = {
- publish: callbacks.fire,
- subscribe: callbacks.add,
- unsubscribe: callbacks.remove
- };
- }
- return queues[id];
- }
-}());
-
-
// Define empty mkws_config for simple applications that don't define it.
if (mkws_config == null || typeof mkws_config != 'object') {
var mkws_config = {};
node: node
};
- // ### More to do here, surely: e.g. wiring into the team
- mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
+ var M = mkws.M;
+
+ if (type === 'Targets') {
+ promoteTargets();
+ } else if (type === 'Stat') {
+ promoteStat();
+ } else {
+ // ### Handle other types here
+ }
+ mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
return that;
+
+
+ // Functions follow for promoting the regular widget object into
+ // widgets of specific types. These could be moved outside of the
+ // widget object, or even into their own source files.
+
+ function promoteTargets() {
+ team.queue("targets").subscribe(function(data) {
+ 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>';
+ var subnode = $(node).children('.mkwsBytarget');
+ subnode.html(table);
+ });
+ }
+
+
+ function promoteStat() {
+ team.queue("stat").subscribe(function(data) {
+ if (node.length === 0) alert("huh?!");
+
+ $(node).html('<span class="head">' + M('Status info') + '</span>' +
+ ' -- ' +
+ '<span class="clients">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
+ ' -- ' +
+ '<span class="records">' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '</span>');
+ });
+ }
}
function team($, teamName) {
var that = {};
var m_teamName = teamName;
+ that.name = function() { return m_teamName; }
var m_submitted = false;
var m_query; // initially undefined
var m_sort; // will be set below
//
// pz2.js event handlers:
//
- function onInit(teamName) {
+ function onInit() {
debug("init");
m_paz.stat();
m_paz.bytarget();
}
- function onBytarget(data, teamName) {
+ function onBytarget(data) {
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);
+ queue("targets").publish(data);
}
- function onStat(data, teamName) {
+ function onStat(data) {
debug("stat");
- var node = findnode('.mkwsStat');
- if (node.length === 0) return;
-
- node.html('<span class="head">' + M('Status info') + '</span>' +
- ' -- ' +
- '<span class="clients">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
- ' -- ' +
- '<span class="records">' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '</span>');
+ queue("stat").publish(data);
}
- function onTerm(data, teamName) {
+ function onTerm(data) {
debug("term");
var node = findnode(".mkwsTermlists");
if (node.length == 0) return;
var detRecordDiv = document.getElementById('mkwsDet_' + teamName + '_' + data.recid);
if (detRecordDiv) return;
m_curDetRecData = data;
+ // Can't use jQuery's $('#x') syntax to find this ID, because it contains spaces.
var recordDiv = document.getElementById('mkwsRecdiv_' + teamName + '_' + m_curDetRecData.recid);
var html = renderDetails(m_curDetRecData);
- recordDiv.innerHTML += html;
+ $(recordDiv).append(html);
}
}
+ // The following PubSub code is modified from the jQuery manual:
+ // https://api.jquery.com/jQuery.Callbacks/
+ //
+ // Use as:
+ // team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
+ // team.queue("eventName").publish(arg1, arg2, ...);
+
+ var queues = {};
+ var queue = function(id) {
+ if (!queues[id]) {
+ var callbacks = $.Callbacks();
+ queues[id] = {
+ publish: callbacks.fire,
+ subscribe: callbacks.add,
+ unsubscribe: callbacks.remove
+ };
+ }
+ return queues[id];
+ }
+
+ that.queue = queue;
+
+
// main
(function() {
try {