if (type === 'Targets') {
promoteTargets();
+ team.debug("made targets widget(node=" + node + ")");
} else if (type === 'Stat') {
promoteStat();
+ team.debug("made stat widget(node=" + node + ")");
} else if (type === 'Termlists') {
promoteTermlists();
+ team.debug("made termlists widget(node=" + node + ")");
} else if (type === 'Pager') {
promotePager();
+ team.debug("made pager widget(node=" + node + ")");
+ } else if (type === 'Records') {
+ promoteRecords();
+ team.debug("made records 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 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);
+ }
+ });
+ }
}
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; }
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);
}
}
- 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: