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 wherein it makes each data object an array but
+ // simply assigns properties to it.
+ // TODO: remove this when PAZ-946 is addressed.
+ 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}));
});
});
mkws.registerWidgetType('Stat', function() {
var that = this;
- var M = mkws.M;
-
this.team.queue("stat").subscribe(function(data) {
- that.node.html(' -- ' +
- '<span class="mkwsClientCount">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
- ' -- ' +
- M('Retrieved records') + ': ' + data.records + '/' + data.hits);
+ var template = that.team.loadTemplate(that.config.template || "Stat");
+ that.node.html(template(data));
});
});
var M = mkws.M;
this.team.queue("pager").subscribe(function(data) {
- that.node.html(drawPager(data))
-
- function drawPager(data) {
- var teamName = that.team.name();
- var s = '<div style="float: right">' + M('Displaying') + ': '
- + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
- ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
- + data.total + ')</div>';
-
- //client indexes pages from 1 but pz2 from 0
- var onsides = 6;
- var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage());
- var currentPage = that.team.currentPage();
-
- var firstClkbl = (currentPage - onsides > 0)
- ? currentPage - onsides
- : 1;
-
- var lastClkbl = firstClkbl + 2*onsides < pages
- ? firstClkbl + 2*onsides
- : pages;
-
- var prev = '<span class="mkwsPrev"><< ' + M('Prev') + '</span> | ';
- if (currentPage > 1)
- prev = '<a href="#" class="mkwsPrev" onclick="mkws.pagerPrev(\'' + teamName + '\');">'
- +'<< ' + M('Prev') + '</a> | ';
-
- var middle = '';
- for(var i = firstClkbl; i <= lastClkbl; i++) {
- var numLabel = i;
- if(i == currentPage)
- numLabel = '<span class="mkwsCurrentPage">' + i + '</span>';
-
- middle += '<a href="#" onclick="mkws.showPage(\'' + teamName + '\', ' + i + ')"> '
- + numLabel + ' </a>';
+ var teamName = that.team.name();
+ var output = {};
+ output.first = data.start + 1;
+ output.last = data.start + data.num;
+ output.count = data.merged;
+ output.found = data.total;
+
+ //client indexes pages from 1 but pz2 from 0
+ var onsides = 6;
+ var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage());
+ var currentPage = that.team.currentPage();
+
+ var firstClkbl = (currentPage - onsides > 0)
+ ? currentPage - onsides
+ : 1;
+ var lastClkbl = firstClkbl + 2*onsides < pages
+ ? firstClkbl + 2*onsides
+ : pages;
+
+ if (firstClkbl > 1) output.morePrev = true;
+ if (lastClkbl < pages) output.moreNext = true;
+
+ if (currentPage > 1) output.prevClick = "mkws.pagerPrev(\'" + teamName + "\');";
+
+ output.pages = [];
+ for(var i = firstClkbl; i <= lastClkbl; i++) {
+ var o = {};
+ o.number = i;
+ if (i !== currentPage) {
+ o.click = "mkws.showPage(\'" + teamName + "\', " + i + ");";
}
+ output.pages.push(o);
+ }
- var next = ' | <span class="mkwsNext">' + M('Next') + ' >></span>';
- if (pages - currentPage > 0)
- next = ' | <a href="#" class="mkwsNext" onclick="mkws.pagerNext(\'' + teamName + '\')">'
- + M('Next') + ' >></a>';
-
- var predots = '';
- if (firstClkbl > 1)
- predots = '...';
-
- var postdots = '';
- if (lastClkbl < pages)
- postdots = '...';
-
- s += '<div style="float: clear">'
- + prev + predots + middle + postdots + next + '</div>';
+ if (pages - currentPage > 0) output.nextClick = "mkws.pagerNext(\'" + teamName + "\')";
- return s;
- }
+ var template = that.team.loadTemplate(that.config.template || "Pager");
+ that.node.html(template(output));
});
});
mkws.registerWidgetType('Done', function() {
var that = this;
-
this.team.queue("complete").subscribe(function(n) {
- that.node.html("Search complete: found " + n + " records");
+ var template = that.team.loadTemplate(that.config.template || "Done");
+ that.node.html(template({count: n}));
});
});
mkws.registerWidgetType('Switch', function() {
if (!this.config.show_switch) return;
var tname = this.team.name();
- this.node.html('\
-<a href="#" onclick="mkws.switchView(\'' + tname + '\', \'records\')">Records</a><span> \
-| \
-</span><a href="#" onclick="mkws.switchView(\'' + tname + '\', \'targets\')">Targets</a>');
+ var output = {};
+ output.recordClick = "mkws.switchView(\'" + tname + "\', \'records\')";
+ output.targetClick = "mkws.switchView(\'" + tname + "\', \'targets\')";
+ var template = this.team.loadTemplate(this.config.template || "Switch");
+ this.node.html(template(output));
this.hideWhenNarrow();
});
mkws.registerWidgetType('Search', function() {
- var tname = this.team.name();
- var M = mkws.M;
-
- 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') + '" />\
-</form>');
+ var output = {};
+ output.team = this.team.name();
+ output.queryWidth = this.config.query_width;
+ var template = this.team.loadTemplate(this.config.template || "Search");
+ this.node.html(template(output));
});
mkws.registerWidgetType('Results', function() {
- var tname = this.team.name();
-
- this.node.html('\
-<table width="100%" border="0" cellpadding="6" cellspacing="0">\
- <tr>\
- <td class="mkwsTermlists-Container-wide mkwsTeam_' + tname + '" width="250" valign="top">\
- <div class="mkwsTermlists mkwsTeam_' + tname + '"></div>\
- </td>\
- <td class="mkwsMOTDContainer mkwsTeam_' + tname + '" valign="top">\
- <div class="mkwsRanking mkwsTeam_' + tname + '"></div>\
- <div class="mkwsPager mkwsTeam_' + tname + '"></div>\
- <div class="mkwsNavi mkwsTeam_' + tname + '"></div>\
- <div class="mkwsRecords mkwsTeam_' + tname + '"></div>\
- </td>\
- </tr>\
- <tr>\
- <td colspan="2">\
- <div class="mkwsTermlists-Container-narrow mkwsTeam_' + tname + '"></div>\
- </td>\
- </tr>\
-</table>');
-
+ var template = this.team.loadTemplate(this.config.template || "Results");
+ this.node.html(template({team: this.team.name()}));
this.autosearch();
});
mkws.registerWidgetType('Ranking', function() {
- var tname = this.team.name();
- var that = this;
- var M = mkws.M;
-
- var s = '<form>';
- if (this.config.show_sort) {
- s += M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
- }
- if (this.config.show_perpage) {
- s += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
+ var output = {};
+ output.perPage = [];
+ output.sort = [];
+ output.team = this.team.name();
+ output.showSort = this.config.show_sort;
+ output.showPerPage = this.config.show_perpage;
+
+ var order = this.team.sortOrder();
+ this.log("making sort, sortOrder = '" + order + "'");
+ for (var i = 0; i < this.config.sort_options.length; i++) {
+ var cur = {};
+ var opt = this.config.sort_options[i];
+ cur.key = opt[0];
+ cur.label = opt.length == 1 ? opt[0] : opt[1];
+ if (order == cur.key || order == cur.label) cur.selected = true;
+ output.sort.push(cur);
}
- s += '</form>';
-
- this.node.html(s);
-
-
- function mkwsHtmlSort() {
- var order = that.team.sortOrder();
-
- 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++) {
- var opt = that.config.sort_options[i];
- var key = opt[0];
- var val = opt.length == 1 ? opt[0] : opt[1];
-
- sort_html += '<option value="' + key + '"';
- if (order == key || order == val) {
- sort_html += ' selected="selected"';
- }
- sort_html += '>' + M(val) + '</option>';
- }
- sort_html += '</select>';
- return sort_html;
+ var perpage = this.team.perpage();
+ this.log("making perpage, perpage = " + perpage);
+ for(var i = 0; i < this.config.perpage_options.length; i++) {
+ var cur = {};
+ cur.perPage = this.config.perpage_options[i];
+ if (cur.perPage == perpage) cur.selected = true;
+ output.perPage.push(cur);
}
- function mkwsHtmlPerpage() {
- var perpage = that.team.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++) {
- var key = that.config.perpage_options[i];
-
- perpage_html += '<option value="' + key + '"';
- if (key == perpage) {
- perpage_html += ' selected="selected"';
- }
- perpage_html += '>' + key + '</option>';
- }
- perpage_html += '</select>';
-
- return perpage_html;
- }
+ var template = this.team.loadTemplate(this.config.template || "Ranking");
+ console.log(output);
+ this.node.html(template(output));
});
var c = this.config;
for (var name in c) {
if (c.hasOwnProperty(name)) {
- this.team.config()[name] = c[name];
+ this.team.config[name] = c[name];
this.log(this + " copied property " + name + "='" + c[name] + "' up to team");
}
}
s += '</span>';
s += '<span class="mkwsWaiting">';
}
- s += '█';
+ s += '█';
}
s += '</span>';
that.node.html(s);
mkws.registerWidgetType('Query', function() {});
mkws.registerWidgetType('MOTDContainer', function() {});
mkws.registerWidgetType('Button', function() {});
-mkws.registerWidgetType('Popup', function() {});