var M = mkws.M;
- if (type === 'Targets') {
- promoteTargets();
- } else if (type === 'Stat') {
- promoteStat();
- } else if (type === 'Termlists') {
- promoteTermlists();
- } else if (type === 'Pager') {
- promotePager();
+ var type2fn = {
+ Targets: promoteTargets,
+ Stat: promoteStat,
+ Termlists: promoteTermlists,
+ Pager: promotePager,
+ Records: promoteRecords,
+ Navi: promoteNavi
+ };
+
+ var promote = type2fn[type];
+ if (promote) {
+ promote();
+ team.debug("made " + type + " widget(node=" + node + ")");
} else {
- // ### Handle other types here
+ team.debug("made UNENCAPSULATED widget(type=" + type + ", node=" + node + ")");
}
- mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
return that;
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>' +
function promotePager() {
team.queue("pager").subscribe(function(data) {
- if (node) {
- $(node).html(drawPager(data))
- }
+ $(node).html(drawPager(data))
function drawPager(data) {
var s = '<div style="float: right">' + M('Displaying') + ': '
}
});
}
+
+
+ function promoteRecords() {
+ team.queue("records").subscribe(function(data) {
+ var html = [];
+ for (var i = 0; i < data.hits.length; i++) {
+ var hit = data.hits[i];
+ html.push('<div class="record" id="mkwsRecdiv_' + team.name() + '_' + hit.recid + '" >',
+ renderSummary(hit),
+ '</div>');
+ // ### 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()));
+ }
+ }
+ $(node).html(html.join(''));
+
+ function renderSummary(hit)
+ {
+ var template = team.loadTemplate("Summary");
+ hit._id = "mkwsRec_" + hit.recid;
+ hit._onclick = "mkws.showDetails('" + team.name() + "', this.id);return false;"
+ return template(hit);
+ }
+ });
+ }
+
+
+ function promoteNavi() {
+ team.queue("navi").subscribe(function() {
+ var filters = team.filters();
+ var text = "";
+
+ for (var i in filters) {
+ if (text) {
+ text += " | ";
+ }
+ var filter = filters[i];
+ if (filter.id) {
+ text += M('source') + ': <a class="crossout" href="#" onclick="mkws.delimitTarget(\'' + team.name() +
+ "', '" + filter.id + "'" + ');return false;">' + filter.name + '</a>';
+ } else {
+ text += M(filter.field) + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(\'' + team.name() +
+ "', '" + filter.field + "', '" + filter.value + "'" +
+ ');return false;">' + filter.value + '</a>';
+ }
+ }
+
+ $(node).html(text);
+ });
+ }
}
that.perpage = function() { return m_perpage; }
that.totalRecordCount = function() { return m_totalRecordCount; }
that.currentPage = function() { return m_currentPage; }
+ that.currentRecordId = function() { return m_currentRecordId; }
+ that.currentRecordData = function() { return m_currentRecordData; }
+ that.filters = function() { return m_filters; }
var debug = function (s) {
var now = $.now();
mkws.debug(m_teamName + ": " + timestamp + s);
}
+ that.debug = debug;
debug("start running MKWS");
function onShow(data, teamName) {
debug("show");
m_totalRecordCount = data.merged;
-
queue("pager").publish(data);
-
- var results = findnode(".mkwsRecords");
- if (!results.length)
- return;
-
- var html = [];
- for (var i = 0; i < data.hits.length; i++) {
- var hit = data.hits[i];
- html.push('<div class="record" id="mkwsRecdiv_' + teamName + '_' + hit.recid + '" >',
- renderSummary(hit),
- '</div>');
- if (hit.recid == m_currentRecordId) {
- if (m_currentRecordData)
- html.push(renderDetails(m_currentRecordData));
- }
- }
- results.html(html.join(''));
+ queue("records").publish(data);
}
}
m_filters = []
- redrawNavi();
- resetPage();
- loadSelect();
triggerSearch(query, sortOrder, targets);
switchView('records'); // In case it's configured to start off as hidden
m_submitted = true;
}
- function onSelectDdChange()
+ function onSortChange()
{
+ m_sortOrder = findnode('.mkwsSort').val();
if (!m_submitted) return false;
resetPage();
- loadSelect();
m_paz.show(0, m_perpage, m_sortOrder);
return false;
}
- function redrawNavi ()
+ function onPerpageChange()
{
- var navi = findnode('.mkwsNavi');
- if (!navi) return;
+ m_perpage = findnode('.mkwsPerpage').val();
+ if (!m_submitted) return false;
+ resetPage();
+ m_paz.show(0, m_perpage, m_sortOrder);
+ return false;
+ }
- var text = "";
- for (var i in m_filters) {
- if (text) {
- text += " | ";
- }
- var filter = m_filters[i];
- if (filter.id) {
- text += M('source') + ': <a class="crossout" href="#" onclick="mkws.delimitTarget(\'' + m_teamName +
- "', '" + filter.id + "'" + ');return false;">' + filter.name + '</a>';
- } else {
- text += M(filter.field) + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(\'' + m_teamName +
- "', '" + filter.field + "', '" + filter.value + "'" +
- ');return false;">' + filter.value + '</a>';
- }
- }
- navi.html(text);
+ function redrawNavi ()
+ {
+ queue("navi").publish();
}
}
- function loadSelect ()
- {
- var node = findnode('.mkwsSort');
- if (node.length && node.val() != m_sortOrder) {
- debug("changing m_sortOrder from " + m_sortOrder + " to " + node.val());
- m_sortOrder = node.val();
- }
- node = findnode('.mkwsPerpage');
- if (node.length && node.val() != m_perpage) {
- debug("changing m_perpage from " + m_perpage + " to " + node.val());
- m_perpage = node.val();
- }
- }
-
-
function triggerSearch (query, sortOrder, targets)
{
+ resetPage();
+ redrawNavi();
+
var pp2filter = "";
var pp2limit = "";
{
debug("limitTarget(id=" + id + ", name=" + name + ")");
m_filters.push({ id: id, name: name });
- redrawNavi();
- resetPage();
- loadSelect();
triggerSearch();
return false;
}
{
debug("limitQuery(field=" + field + ", value=" + value + ")");
m_filters.push({ field: field, value: value });
- redrawNavi();
- resetPage();
- loadSelect();
triggerSearch();
return false;
}
}
m_filters = newFilters;
- redrawNavi();
- resetPage();
- loadSelect();
triggerSearch();
return false;
}
}
m_filters = newFilters;
- redrawNavi();
- resetPage();
- loadSelect();
triggerSearch();
return false;
}
var node = findnode(".mkwsRanking");
if (node.length) {
- var ranking_data = '';
- ranking_data += '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + m_teamName + '" action="" >';
+ var ranking_data = '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + m_teamName + '" action="" >';
if (mkws_config.show_sort) {
ranking_data += M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
}
node.submit(onFormSubmitEventHandler);
node = findnode('.mkwsSort');
if (node.length)
- node.change(onSelectDdChange);
+ node.change(onSortChange);
node = findnode('.mkwsPerpage');
if (node.length)
- node.change(onSelectDdChange);
+ node.change(onPerpageChange);
// on first page, hide the termlist
$(document).ready(function() { findnode(".mkwsTermlists").hide(); });
}
- function renderSummary(hit)
- {
- var template = loadTemplate("Summary");
- hit._id = "mkwsRec_" + hit.recid;
- hit._onclick = "mkws.showDetails('" + m_teamName + "', this.id);return false;"
- return template(hit);
- }
-
-
function renderDetails(data, marker)
{
var template = loadTemplate("Record");
var details = template(data);
return '<div class="details" id="mkwsDet_' + m_teamName + '_' + data.recid + '">' + details + '</div>';
}
+ that.renderDetails = renderDetails;
function loadTemplate(name)
return template;
}
+ that.loadTemplate = loadTemplate;
// The following PubSub code is modified from the jQuery manual:
// Second pass: make the individual widget objects. This has
// to be done separately, and after the team-creation, since
// that sometimes makes new widget nodes (e.g. creating
- // mkwsTermlists instead mkwsResults.
+ // mkwsTermlists inside mkwsResults.
$('[class^="mkws"],[class*=" mkws"]').each(function () {
mkws.handleNodeWithTeam(this, function(tname, type) {
var myTeam = mkws.teams[tname];